Skip to content

Commit a96984f

Browse files
feat: enhance pipeline token preparation for improved error handling and fallback mechanism
1 parent 1b67a15 commit a96984f

File tree

1 file changed

+24
-4
lines changed

1 file changed

+24
-4
lines changed

.github/workflows/container-build.yaml

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,34 @@ jobs:
2929
username: ${{ github.actor }}
3030
password: ${{ secrets.GITHUB_TOKEN }}
3131

32-
- name: Ensure pipeline token is configured
32+
- name: Prepare pipeline token
33+
env:
34+
PIPELINE_GITHUB_TOKEN: ${{ secrets.PIPELINE_GITHUB_TOKEN }}
35+
DEFAULT_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3336
run: |
3437
set -euo pipefail
35-
if [ -z "${{ secrets.PIPELINE_GITHUB_TOKEN }}" ]; then
36-
echo "Set the PIPELINE_GITHUB_TOKEN secret with a classic PAT that has at least public_repo scope." >&2
38+
token="$PIPELINE_GITHUB_TOKEN"
39+
source="PIPELINE_GITHUB_TOKEN"
40+
41+
if [ -z "$token" ]; then
42+
token="$DEFAULT_GITHUB_TOKEN"
43+
source="GITHUB_TOKEN"
44+
echo "PIPELINE_GITHUB_TOKEN not set; falling back to workflow GITHUB_TOKEN (may hit rate limits)." >&2
45+
fi
46+
47+
if [ -z "$token" ]; then
48+
echo "No GitHub token available. Configure PIPELINE_GITHUB_TOKEN or rely on the default GITHUB_TOKEN." >&2
3749
exit 1
3850
fi
3951
52+
echo "::add-mask::$token"
53+
{
54+
echo "PIPELINE_BUILD_TOKEN=$token"
55+
echo "PIPELINE_BUILD_TOKEN_SOURCE=$source"
56+
} >> "$GITHUB_ENV"
57+
58+
echo "Using token source: $source"
59+
4060
- name: Build and push image
4161
uses: docker/build-push-action@v6
4262
with:
@@ -45,5 +65,5 @@ jobs:
4565
push: true
4666
platforms: linux/amd64
4767
secrets: |
48-
github_token=${{ secrets.PIPELINE_GITHUB_TOKEN }}
68+
github_token=${{ env.PIPELINE_BUILD_TOKEN }}
4969
tags: ${{ env.IMAGE_TAG }}

0 commit comments

Comments
 (0)