11name : Release / Publish to GHCR and Update Action
2+
23on :
34 push :
45 tags :
@@ -14,60 +15,49 @@ jobs:
1415 build-and-push :
1516 runs-on : ubuntu-latest
1617 steps :
18+
1719 - name : Checkout
1820 uses : actions/checkout@v4
1921
20- - name : Set up QEMU
21- uses : docker/setup-qemu-action@v2
22+ - name : Lowercase owner
23+ run : echo "OWNER_LC=${GITHUB_REPOSITORY_OWNER,,}" >> $GITHUB_ENV
2224
2325 - name : Set up Docker Buildx
2426 uses : docker/setup-buildx-action@v3
2527
2628 - name : Log in to GHCR
27- uses : docker/login-action@v2
29+ uses : docker/login-action@v3
2830 with :
2931 registry : ghcr.io
3032 username : ${{ github.actor }}
31- password : ${{ secrets.GHCR_PAT }}
33+ password : ${{ secrets.GITHUB_TOKEN }}
3234
33- - name : Build and push image
34- uses : docker/build-push-action@v4
35+ - name : Build and push versioned + latest images
36+ uses : docker/build-push-action@v5
3537 with :
3638 context : .
3739 file : ./Dockerfile
3840 push : true
3941 tags : |
40- ghcr.io/${{ github.repository_owner }}/sbom-tm:${{ github.ref_name }}
41- ghcr.io/${{ github.repository_owner }}/sbom-tm:latest
42+ ghcr.io/${{ env.OWNER_LC }}/sbom-tm:${{ github.ref_name }}
43+ ghcr.io/${{ env.OWNER_LC }}/sbom-tm:latest
4244
43- - name : Update ` action.yml` to reference GHCR image
45+ - name : Update action.yml to reference version
4446 env :
45- GIT_AUTHOR_NAME : github-actions[bot]
46- GIT_AUTHOR_EMAIL : github-actions[bot]@users.noreply.github.com
47- BRANCH_NAME : release/${{ github.ref_name }}
48- IMAGE_TAG : ghcr.io/${{ github.repository_owner }}/sbom-tm:${{ github.ref_name }}
49- PUSH_TOKEN : ${{ secrets.PERSONAL_TOKEN }}
47+ NEW_IMAGE : ghcr.io/${{ env.OWNER_LC }}/sbom-tm:${{ github.ref_name }}
5048 run : |
51- git config --global user.name "$GIT_AUTHOR_NAME"
52- git config --global user.email "$GIT_AUTHOR_EMAIL"
53- git checkout -b "$BRANCH_NAME"
54- if [ -f action.yml ]; then
55- sed -E "s|image: .*|image: '$IMAGE_TAG'|" action.yml > action.yml.tmp || true
56- mv action.yml.tmp action.yml
57- else
58- echo "warning: action.yml not found"
59- fi
60- git add action.yml || true
61- git commit -m "chore(action): point to GHCR image $IMAGE_TAG" || true
62- git push https://${PUSH_TOKEN}@github.com/${{ github.repository }} HEAD:$BRANCH_NAME
49+ git switch -C release/${{ github.ref_name }}
50+ yq -i ".runs.image = env(NEW_IMAGE)" action.yml
51+ git add action.yml
52+ git commit -m "chore: update action to $NEW_IMAGE" || echo "No changes"
53+ git push -f
6354
6455 - name : Create Pull Request
6556 uses : peter-evans/create-pull-request@v5
6657 with :
67- token : ${{ secrets.PERSONAL_TOKEN }}
68- commit-message : " chore(action): point to GHCR image ${{ github.ref_name }}"
69- title : " Release: point action to GHCR image ${{ github.ref_name }}"
70- body : |
71- This PR updates `action.yml` to use the published GHCR image for the action runtime.
58+ token : ${{ secrets.GITHUB_TOKEN }}
59+ commit-message : " chore: update action to ${{ github.ref_name }}"
60+ title : " Release: update action to ${{ github.ref_name }}"
61+ body : " Automated update for new GHCR release."
7262 base : main
7363 head : release/${{ github.ref_name }}
0 commit comments