@@ -13,22 +13,22 @@ inputs:
1313 required : false
1414 default : " "
1515 docker-username :
16- description : " dockerhub username"
16+ description : " Docker Hub username"
1717 default : " "
1818 required : false
1919 docker-password :
20- description : " dockerhub password"
20+ description : " Docker Hub password"
2121 required : false
2222 ghcr-username :
23- description : " ghcr username"
23+ description : " GHCR username"
2424 default : " "
2525 required : false
2626 ghcr-password :
27- description : " ghcr password"
27+ description : " GHCR password"
2828 default : " "
2929 required : false
3030 push :
31- description : " Push digests to repo "
31+ description : " Push digests to registry "
3232 default : " true"
3333 required : false
3434
@@ -55,19 +55,47 @@ runs:
5555 - name : Set up Docker Buildx
5656 uses : docker/setup-buildx-action@v3
5757
58+ - name : Normalize registry ref parts
59+ id : refs
60+ shell : bash
61+ run : |
62+ 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
67+
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
78+
79+ family="${{ inputs.family }}"
80+ distro="${{ inputs.distro }}"
81+ echo "ghcr_login_user=$ghcr_login_user" >> "$GITHUB_OUTPUT"
82+ echo "ghcr_owner=$ghcr_owner" >> "$GITHUB_OUTPUT"
83+ echo "family=${family,,}" >> "$GITHUB_OUTPUT"
84+ echo "distro=${distro,,}" >> "$GITHUB_OUTPUT"
85+
5886 - name : Login to Docker Hub
59- if : ${{ inputs.docker-password }}
87+ if : ${{ inputs.docker-username && inputs.docker- password }}
6088 uses : docker/login-action@v3
6189 with :
6290 username : ${{ inputs.docker-username }}
6391 password : ${{ inputs.docker-password }}
6492
6593 - name : Log in to GHCR
66- if : ${{ inputs.ghcr-password }}
94+ if : ${{ inputs.ghcr-password && steps.refs.outputs.ghcr_login_user }}
6795 uses : docker/login-action@v3
6896 with :
6997 registry : ghcr.io
70- username : ${{ inputs.ghcr-username }}
98+ username : ${{ steps.refs.outputs.ghcr_login_user }}
7199 password : ${{ inputs.ghcr-password }}
72100
73101 - name : Set up Python
@@ -94,18 +122,6 @@ runs:
94122 key="${plat//\//-}"
95123 echo "platform_key=$key" >> "$GITHUB_OUTPUT"
96124
97- - name : Normalize registry ref parts
98- id : refs
99- shell : bash
100- run : |
101- set -euo pipefail
102- ghcr_owner="${{ inputs.ghcr-username }}"
103- family="${{ inputs.family }}"
104- distro="${{ inputs.distro }}"
105- echo "ghcr_owner=${ghcr_owner,,}" >> "$GITHUB_OUTPUT"
106- echo "family=${family,,}" >> "$GITHUB_OUTPUT"
107- echo "distro=${distro,,}" >> "$GITHUB_OUTPUT"
108-
109125 - name : Compute bake variables
110126 id : gen
111127 shell : bash
@@ -115,9 +131,9 @@ runs:
115131 --family "${{ inputs.family }}"
116132 --distro "${{ inputs.distro }}"
117133 --platform "${{ steps.detect.outputs.platform }}"
118- ${{ inputs.ghcr-password && format('--ghcr-username "{0}"', inputs.ghcr-username ) || '' }}
134+ ${{ inputs.ghcr-password && format('--ghcr-username "{0}"', steps.refs.outputs.ghcr_owner ) || '' }}
119135 ${{ inputs.docker-password && format('--docker-username "{0}"', inputs.docker-username) || '' }}
120- --digest
136+ ${{ inputs.push == 'true' && ' --digest' || '' }}
121137 )
122138 output=$("${cmd[@]}")
123139 echo "$output"
@@ -133,7 +149,7 @@ runs:
133149 ${{ steps.gen.outputs.release }}-*.platform=${{ steps.detect.outputs.platform }}
134150 *.cache-to=type=gha,mode=max,scope=${{ steps.gen.outputs.group }}
135151 *.cache-from=type=gha,scope=${{ steps.gen.outputs.group }}
136- ${{ (inputs.push && 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) || '' }}
152+ ${{ (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) || '' }}
137153 ${{ (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) || '' }}
138154 ${{ steps.gen.outputs.set_lines }}
139155
0 commit comments