Skip to content

Commit 79b15d9

Browse files
authored
fix(ci): Move updating docker tag into own job to avoid setting it twice per run: when the builder image is built and when the app image is built (#269)
* fix(ci): Move updating docker tag into own job to avoid setting it twice per run: when the builder image is built and when the app image is built * Use create-github-app-token and action-github-commit to commit action on master * Rename docker tag step * Shuffle around steps * Only get a token for master runs
1 parent 21eaf20 commit 79b15d9

File tree

2 files changed

+45
-33
lines changed

2 files changed

+45
-33
lines changed

.github/workflows/build.yml

Lines changed: 44 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -21,58 +21,70 @@ env:
2121
SENTRY_PROJECT: ${{ vars.SENTRY_PROJECT }}
2222

2323
jobs:
24-
docker-build:
25-
name: Build & publish Docker images
24+
prepare-docker:
25+
name: Prepare docker tag
2626
runs-on: ubuntu-latest
2727
permissions:
2828
contents: write
29-
packages: write
30-
strategy:
31-
matrix:
32-
target:
33-
- name: builder
34-
image: action-release-builder-image
35-
- name: app
36-
image: action-release-image
29+
outputs:
30+
docker_tag: ${{ steps.docker_tag.outputs.docker_tag }}
3731
steps:
3832
- name: Checkout repo
3933
uses: actions/checkout@v4
40-
with:
41-
fetch-depth: 0
4234

43-
- name: Set git user to getsentry-bot
44-
if: github.ref == 'refs/heads/master'
45-
run: |
46-
echo "GIT_COMMITTER_NAME=getsentry-bot" >> $GITHUB_ENV;
47-
echo "GIT_AUTHOR_NAME=getsentry-bot" >> $GITHUB_ENV;
48-
echo "[email protected]" >> $GITHUB_ENV;
49-
50-
- name: Evaluate docker tag
51-
env:
52-
GITHUB_TOKEN: ${{ secrets.GH_SENTRY_BOT_PAT }}
35+
- name: Get docker tag
36+
id: docker_tag
5337
run: |
5438
if [[ "${{ github.ref }}" == "refs/heads/master" ]]; then
55-
echo "DOCKER_TAG=master" >> $GITHUB_ENV
39+
echo "docker_tag=master" >> $GITHUB_OUTPUT
5640
yarn set-docker-tag master
57-
58-
if ! git diff --quiet action.yml; then
59-
git add action.yml
60-
SKIP=lint,format,set-docker-tag-from-branch git commit -m "chore: Set docker tag for master [skip-ci]"
61-
git push
62-
fi
6341
else
6442
TAG=$(yq '... | select(has("uses") and .uses | test("docker://ghcr.io/getsentry/action-release-image:.*")) | .uses' action.yml | awk -F':' '{print $3}')
65-
echo "DOCKER_TAG=$TAG" >> $GITHUB_ENV
43+
echo "docker_tag=$TAG" >> $GITHUB_OUTPUT
6644
6745
if [[ "${{ github.event_name }}" == "pull_request" ]]; then
6846
if [[ "$TAG" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
69-
echo "Error: DOCKER_TAG $TAG matching format MAJOR.MINOR.PATCH is not allowed inside pull requests."
47+
echo "Error: docker_tag $TAG matching format MAJOR.MINOR.PATCH is not allowed inside pull requests."
7048
echo "Please rename the docker tag in action.yml and try again."
7149
exit 1
7250
fi
7351
fi
7452
fi
7553
54+
- name: Get auth token
55+
id: token
56+
uses: actions/create-github-app-token@5d869da34e18e7287c1daad50e0b8ea0f506ce69 # v1.11.0
57+
if: github.ref == 'refs/heads/master'
58+
with:
59+
app_id: ${{ vars.SENTRY_INTERNAL_APP_ID }}
60+
private_key: ${{ secrets.SENTRY_INTERNAL_APP_PRIVATE_KEY }}
61+
62+
- name: Commit changes
63+
uses: getsentry/[email protected]
64+
if: github.ref == 'refs/heads/master'
65+
with:
66+
github-token: ${{ steps.token.outputs.token }}
67+
message: "chore: Set docker tag for master [skip-ci]"
68+
69+
docker-build:
70+
name: Build & publish Docker images
71+
needs: prepare-docker
72+
runs-on: ubuntu-latest
73+
permissions:
74+
packages: write
75+
strategy:
76+
matrix:
77+
target:
78+
- name: builder
79+
image: action-release-builder-image
80+
- name: app
81+
image: action-release-image
82+
steps:
83+
- name: Checkout repo
84+
uses: actions/checkout@v4
85+
with:
86+
fetch-depth: 0
87+
7688
- name: Set up QEMU
7789
uses: docker/setup-qemu-action@v3
7890

@@ -98,7 +110,7 @@ jobs:
98110
with:
99111
platforms: linux/amd64,linux/arm64
100112
push: true
101-
tags: ghcr.io/${{ github.repository_owner }}/${{ matrix.target.image }}:${{ env.DOCKER_TAG }}
113+
tags: ghcr.io/${{ github.repository_owner }}/${{ matrix.target.image }}:${{ needs.prepare-docker.outputs.docker_tag }}
102114
cache-from: ghcr.io/${{ github.repository_owner }}/${{ matrix.target.image }}:master
103115
target: ${{ matrix.target.name }}
104116
build-args: BUILDKIT_INLINE_CACHE=1

action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ runs:
8484
INPUT_WORKING_DIRECTORY: ${{ inputs.working_directory }}
8585
INPUT_DISABLE_TELEMETRY: ${{ inputs.disable_telemetry }}
8686
INPUT_DISABLE_SAFE_DIRECTORY: ${{ inputs.disable_safe_directory }}
87-
uses: docker://ghcr.io/getsentry/action-release-image:master
87+
uses: docker://ghcr.io/getsentry/action-release-image:ab-set-docker-tag-once
8888

8989
# For actions running on macos or windows runners, we use a composite
9090
# action approach which allows us to install the arch specific sentry-cli

0 commit comments

Comments
 (0)