Skip to content

Commit b6d60ec

Browse files
committed
ci: use github app to commit changes in workflow
1 parent d1cb6dd commit b6d60ec

File tree

1 file changed

+39
-8
lines changed

1 file changed

+39
-8
lines changed

.github/workflows/build-and-push-stage.yml

Lines changed: 39 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@ jobs:
1111
build_and_deploy_stage:
1212
runs-on: ubuntu-latest
1313
permissions:
14-
contents: write
1514
packages: write
1615
actions: write
16+
outputs:
17+
branch: ${{ steps.extract_branch.outputs.branch }}
18+
version: ${{ env.RELEASE_VERSION }}
1719
steps:
1820
- name: Checkout code
1921
uses: actions/checkout@v4
@@ -80,25 +82,54 @@ jobs:
8082
push: true
8183
tags: ghcr.io/${{ env.REPO_LC }}:${{ env.RELEASE_VERSION }},ghcr.io/${{ env.REPO_LC }}:${{ env.COMMIT_SHA }}
8284

85+
update_deployment:
86+
runs-on: ubuntu-latest
87+
needs: build_and_deploy_stage
88+
permissions:
89+
contents: write
90+
env:
91+
branch: ${{ needs.build_and_deploy_stage.outputs.branch }}
92+
version: ${{ needs.build_and_deploy_stage.outputs.version }}
93+
steps:
94+
- uses: actions/create-github-app-token@v2
95+
id: app-token
96+
with:
97+
app-id: ${{ vars.APP_ID }}
98+
private-key: ${{ secrets.APP_PRIVATE_KEY }}
99+
permission-contents: write
100+
101+
- name: Checkout code
102+
uses: actions/checkout@v4
103+
with:
104+
token: ${{ steps.app-token.outputs.token }}
105+
fetch-depth: 0
106+
fetch-tags: true
107+
83108
- name: 'Setup yq'
84109
uses: dcarbone/install-yq-action@v1.3.1
85110
with:
86111
version: 'v4.44.3'
87112
force: true
88113

114+
- name: Bump version in values/stage.yaml
115+
run: yq -i '.deployment.image.tag=strenv(version)' ./k8s/values/stage.yaml
116+
117+
- name: Get GitHub App User ID
118+
id: get-user-id
119+
env:
120+
GH_TOKEN: ${{ steps.app-token.outputs.token }}
121+
run: echo "user-id=$(gh api "/users/${{ steps.app-token.outputs.app-slug }}[bot]" --jq .id)" >> "$GITHUB_OUTPUT"
122+
89123
- name: Initialize mandatory git config
90124
run: |
91-
git config --global user.name 'GitHub Actions'
92-
git config --global user.email 'noreply@github.com'
93-
94-
- name: Bump version in values/stage.yaml
95-
run: yq -i '.deployment.image.tag=strenv(RELEASE_VERSION)' ./k8s/values/stage.yaml
125+
git config --global user.name '${{ steps.app-token.outputs.app-slug }}[bot]'
126+
git config --global user.email '${{ steps.get-user-id.outputs.user-id }}+${{ steps.app-token.outputs.app-slug }}[bot]@users.noreply.github.com'
96127
97128
- name: Commit k8s values and push changes
98129
env:
99-
GITHUB_TOKEN: ${{ secrets.GREEN_ECOLUTION_PAT }}
130+
GITHUB_TOKEN: ${{ steps.app-token.outputs.token }}
100131
run: |
101132
git add ./k8s/values/stage.yaml
102-
git commit --message "chore: update stage image to version ${{ env.RELEASE_VERSION }}" \
133+
git commit --message "chore: update stage image to version ${{ env.RELEASE_VERSION }} [skip ci]" \
103134
&& git push origin ${{ steps.extract_branch.outputs.branch }} \
104135
|| echo "No changes to commit"

0 commit comments

Comments
 (0)