1+ name : Deploy to Test
2+
3+ on :
4+ workflow_dispatch :
5+ push :
6+ branches-ignore :
7+ - main
8+
9+ env :
10+ IMAGE_NAME : ghcr.io/${{ github.repository }}
11+ INFRA_REPO : ${{ vars.INFRA_REPO }}
12+ KUSTOMIZE_PATH : ${{ vars.KUSTOMIZE_PATH }}
13+ DEPLOY_ENV : test
14+
15+ jobs :
16+ check-keyword :
17+ runs-on : ubuntu-latest
18+ outputs :
19+ deploy : ${{ steps.check.outputs.deploy }}
20+ steps :
21+ - name : Check commit message for deploy keyword
22+ id : check
23+ env :
24+ COMMIT_MESSAGE : ${{ github.event.head_commit.message }}
25+ run : |
26+ # Keyword: [deploy-test] anywhere in de commit message
27+ # Voorbeeld: "feat: nieuwe feature [deploy-test]"
28+ if echo "$COMMIT_MESSAGE" | grep -qi "\[deploy-test\]"; then
29+ echo "deploy=true" >> $GITHUB_OUTPUT
30+ echo "Deploy keyword gevonden in commit message."
31+ else
32+ echo "deploy=false" >> $GITHUB_OUTPUT
33+ echo "Geen deploy keyword gevonden, sla deploy over."
34+ fi
35+
36+ build-and-push :
37+ needs : check-keyword
38+ if : |
39+ needs.check-keyword.outputs.deploy == 'true'
40+ runs-on : ubuntu-latest
41+ permissions :
42+ contents : read
43+ packages : write
44+ steps :
45+ - name : Checkout
46+ uses : actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd
47+
48+ - name : Set up Docker Buildx
49+ uses : docker/setup-buildx-action@4d04d5d9486b7bd6fa91e7baf45bbb4f8b9deedd
50+
51+ - name : Login to container registry
52+ uses : docker/login-action@b45d80f862d83dbcd57f89517bcf500b2ab88fb2
53+ with :
54+ registry : ghcr.io
55+ username : ${{ github.actor }}
56+ password : ${{ secrets.GITHUB_TOKEN }}
57+
58+ - name : Build and push image
59+ uses : docker/build-push-action@d08e5c354a6adb9ed34480a06d141179aa583294
60+ with :
61+ context : .
62+ push : true
63+ tags : |
64+ ${{ env.IMAGE_NAME }}:test
65+ ${{ env.IMAGE_NAME }}:${{ github.sha }}
66+
67+ update-infra-test :
68+ needs : build-and-push
69+ runs-on : ubuntu-latest
70+ steps :
71+ - name : Parse infra repository
72+ id : infra-repo
73+ run : |
74+ INFRA_REPO="${{ env.INFRA_REPO }}"
75+
76+ if [[ -z "$INFRA_REPO" || "$INFRA_REPO" != */* ]]; then
77+ echo "INFRA_REPO moet de vorm owner/repo hebben, huidige waarde: '$INFRA_REPO'" >&2
78+ exit 1
79+ fi
80+
81+ echo "owner=${INFRA_REPO%%/*}" >> "$GITHUB_OUTPUT"
82+ echo "repo=${INFRA_REPO#*/}" >> "$GITHUB_OUTPUT"
83+
84+ - name : Genereer app token (Release proces app)
85+ id : app-token
86+ uses : actions/create-github-app-token@f8d387b68d61c58ab83c6c016672934102569859
87+ with :
88+ app-id : ${{ secrets.RELEASE_PROCES_APP_ID }}
89+ private-key : ${{ secrets.RELEASE_PROCES_APP_PRIVATE_KEY }}
90+ owner : ${{ steps.infra-repo.outputs.owner }}
91+ repositories : ${{ steps.infra-repo.outputs.repo }}
92+
93+ - name : Checkout don-infra
94+ uses : actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd
95+ with :
96+ repository : ${{ env.INFRA_REPO }}
97+ token : ${{ steps.app-token.outputs.token }}
98+
99+ - name : Update image tag in test overlay
100+ run : |
101+ KUSTOMIZATION_FILE="${{ env.KUSTOMIZE_PATH }}${{ env.DEPLOY_ENV }}/kustomization.yaml"
102+
103+ yq e '(.images[] | select(.newName == "${{ env.IMAGE_NAME }}")).newTag = "${{ github.sha }}"' -i "$KUSTOMIZATION_FILE"
104+
105+ - name : Commit en push naar don-infra
106+ run : |
107+ KUSTOMIZATION_FILE="${{ env.KUSTOMIZE_PATH }}${{ env.DEPLOY_ENV }}/kustomization.yaml"
108+
109+ git config user.name "${{ github.actor }}"
110+ git config user.email "${{ github.actor_id }}+${{ github.actor }}@users.noreply.github.com"
111+ git add "$KUSTOMIZATION_FILE"
112+ git commit -m "test: don-tools-api → ${{ github.sha }}
113+
114+ Branch: ${{ github.ref_name }}
115+ Commit: ${{ github.server_url }}/${{ github.repository }}/commit/${{ github.sha }}"
116+ git push
0 commit comments