@@ -31,6 +31,10 @@ inputs:
3131 description : " Push digests to registry"
3232 default : " true"
3333 required : false
34+ gha-cache :
35+ description : " GitHub Actions cache mode: all|none|from"
36+ default : " all"
37+ required : false
3438
3539outputs :
3640 platform :
@@ -60,25 +64,11 @@ runs:
6064 shell : bash
6165 run : |
6266 set -euo pipefail
63- ghcr_login_user="${{ inputs.ghcr-username }}"
64- if [[ -z "$ghcr_login_user" ]]; then
65- ghcr_login_user="${{ github.actor }}"
66- fi
6767
68- ghcr_owner="${{ inputs.ghcr-username }}"
69- # Dependabot usernames include brackets (e.g. dependabot[bot]) which are
70- # invalid in image/cache references; fall back to repo owner namespace.
71- if [[ -z "$ghcr_owner" || "$ghcr_owner" == *"["* || "$ghcr_owner" == *"]"* ]]; then
72- ghcr_owner="${{ github.repository_owner }}"
73- fi
74- ghcr_owner="$(printf '%s' "$ghcr_owner" | tr '[:upper:]' '[:lower:]' | sed -E 's/[^a-z0-9._-]+/-/g; s/^-+//; s/-+$//')"
75- if [[ -z "$ghcr_owner" ]]; then
76- ghcr_owner="$(printf '%s' "${{ github.repository_owner }}" | tr '[:upper:]' '[:lower:]' | sed -E 's/[^a-z0-9._-]+/-/g; s/^-+//; s/-+$//')"
77- fi
68+ ghcr_owner="${{ github.repository_owner }}"
7869
7970 family="${{ inputs.family }}"
8071 distro="${{ inputs.distro }}"
81- echo "ghcr_login_user=$ghcr_login_user" >> "$GITHUB_OUTPUT"
8272 echo "ghcr_owner=$ghcr_owner" >> "$GITHUB_OUTPUT"
8373 echo "family=${family,,}" >> "$GITHUB_OUTPUT"
8474 echo "distro=${distro,,}" >> "$GITHUB_OUTPUT"
@@ -91,11 +81,11 @@ runs:
9181 password : ${{ inputs.docker-password }}
9282
9383 - name : Log in to GHCR
94- if : ${{ inputs.ghcr-password && steps.refs.outputs.ghcr_login_user }}
84+ if : ${{ inputs.ghcr-username && inputs.ghcr-password }}
9585 uses : docker/login-action@v3
9686 with :
9787 registry : ghcr.io
98- username : ${{ steps.refs.outputs.ghcr_login_user }}
88+ username : ${{ inputs.ghcr-username }}
9989 password : ${{ inputs.ghcr-password }}
10090
10191 - name : Set up Python
@@ -131,7 +121,7 @@ runs:
131121 --family "${{ inputs.family }}"
132122 --distro "${{ inputs.distro }}"
133123 --platform "${{ steps.detect.outputs.platform }}"
134- ${{ inputs.ghcr-password && format('--ghcr-username "{0}"', steps.refs.outputs.ghcr_owner) || '' }}
124+ ${{ inputs.ghcr-password && format('--ghcr-owner "{0}"', steps.refs.outputs.ghcr_owner) || '' }}
135125 ${{ inputs.docker-password && format('--docker-username "{0}"', inputs.docker-username) || '' }}
136126 ${{ inputs.push == 'true' && '--digest' || '' }}
137127 )
@@ -147,8 +137,8 @@ runs:
147137 push : ${{ inputs.push }}
148138 set : |
149139 ${{ steps.gen.outputs.release }}-*.platform=${{ steps.detect.outputs.platform }}
150- *.cache-to=type=gha,mode=max,scope=${{ steps.gen.outputs.group }}
151- *.cache-from=type=gha,scope=${{ steps.gen.outputs.group }}
140+ ${{ inputs.gha-cache == 'all' && (inputs.push == 'true' && format(' *.cache-to=type=gha,mode=max,scope={0},ignore-error=true', steps.gen.outputs.group) || format('*.cache-to=type=gha,mode=min,scope={0},ignore-error=true', steps.gen.outputs.group)) || '' }}
141+ ${{ (inputs.gha-cache == 'all' || inputs.gha-cache == 'from') && format(' *.cache-from=type=gha,scope={0}', steps.gen.outputs.group) || '' }}
152142 ${{ (inputs.push == 'true' && inputs.ghcr-password && steps.refs.outputs.ghcr_owner) && format('*.cache-to=type=registry,ref=ghcr.io/{0}/{1}:{2}-{3}-buildcache,mode=max', steps.refs.outputs.ghcr_owner, steps.refs.outputs.family, steps.refs.outputs.distro, steps.detect.outputs.platform_key) || '' }}
153143 ${{ (inputs.ghcr-password && steps.refs.outputs.ghcr_owner) && format('*.cache-from=type=registry,ref=ghcr.io/{0}/{1}:{2}-{3}-buildcache', steps.refs.outputs.ghcr_owner, steps.refs.outputs.family, steps.refs.outputs.distro, steps.detect.outputs.platform_key) || '' }}
154144 ${{ steps.gen.outputs.set_lines }}
@@ -161,8 +151,9 @@ runs:
161151 meta_dir="${{ github.workspace }}/.tmp"
162152 mkdir -p "$meta_dir"
163153 meta_file="bake-metadata-${{ inputs.family }}-${{ inputs.distro }}-${{ steps.detect.outputs.platform_key }}.json"
164- metadata='${{ steps.bake.outputs.metadata }}'
165- printf '%s' "$metadata" > "$meta_dir/$meta_file"
154+ cat > "$meta_dir/$meta_file" <<'__DOCKER_BAKE_METADATA__'
155+ ${{ steps.bake.outputs.metadata }}
156+ __DOCKER_BAKE_METADATA__
166157 echo "metadata_path=$meta_dir/$meta_file" >> "$GITHUB_OUTPUT"
167158 echo "Saved $meta_file ($(wc -c < "$meta_dir/$meta_file") bytes)"
168159
0 commit comments