|
| 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 | + target: caddy |
| 63 | + push: true |
| 64 | + tags: | |
| 65 | + ${{ env.IMAGE_NAME }}:test |
| 66 | + ${{ env.IMAGE_NAME }}:${{ github.sha }} |
| 67 | + secrets: | |
| 68 | + "PIWIK_PRO_ACCOUNT_ADDRESS=${{ secrets.PIWIK_PRO_ACCOUNT_ADDRESS }}" |
| 69 | + "PIWIK_PRO_SITE_ID=${{ secrets.PIWIK_PRO_SITE_ID }}" |
| 70 | +
|
| 71 | + update-infra-test: |
| 72 | + needs: build-and-push |
| 73 | + runs-on: ubuntu-latest |
| 74 | + steps: |
| 75 | + - name: Parse infra repository |
| 76 | + id: infra-repo |
| 77 | + run: | |
| 78 | + INFRA_REPO="${{ env.INFRA_REPO }}" |
| 79 | +
|
| 80 | + if [[ -z "$INFRA_REPO" || "$INFRA_REPO" != */* ]]; then |
| 81 | + echo "INFRA_REPO moet de vorm owner/repo hebben, huidige waarde: '$INFRA_REPO'" >&2 |
| 82 | + exit 1 |
| 83 | + fi |
| 84 | +
|
| 85 | + echo "owner=${INFRA_REPO%%/*}" >> "$GITHUB_OUTPUT" |
| 86 | + echo "repo=${INFRA_REPO#*/}" >> "$GITHUB_OUTPUT" |
| 87 | +
|
| 88 | + - name: Genereer app token (Release proces app) |
| 89 | + id: app-token |
| 90 | + uses: actions/create-github-app-token@f8d387b68d61c58ab83c6c016672934102569859 |
| 91 | + with: |
| 92 | + app-id: ${{ secrets.RELEASE_PROCES_APP_ID }} |
| 93 | + private-key: ${{ secrets.RELEASE_PROCES_APP_PRIVATE_KEY }} |
| 94 | + owner: ${{ steps.infra-repo.outputs.owner }} |
| 95 | + repositories: ${{ steps.infra-repo.outputs.repo }} |
| 96 | + |
| 97 | + - name: Checkout don-infra |
| 98 | + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd |
| 99 | + with: |
| 100 | + repository: ${{ env.INFRA_REPO }} |
| 101 | + token: ${{ steps.app-token.outputs.token }} |
| 102 | + |
| 103 | + - name: Update image tag in test overlay |
| 104 | + run: | |
| 105 | + KUSTOMIZATION_FILE="${{ env.KUSTOMIZE_PATH }}${{ env.DEPLOY_ENV }}/kustomization.yaml" |
| 106 | +
|
| 107 | + yq e '(.images[] | select(.name == "static")).newTag = "${{ github.sha }}"' \ |
| 108 | + -i "$KUSTOMIZATION_FILE" |
| 109 | +
|
| 110 | + - name: Commit en push naar don-infra |
| 111 | + run: | |
| 112 | + KUSTOMIZATION_FILE="${{ env.KUSTOMIZE_PATH }}${{ env.DEPLOY_ENV }}/kustomization.yaml" |
| 113 | +
|
| 114 | + git config user.name "${{ github.actor }}" |
| 115 | + git config user.email "${{ github.actor_id }}+${{ github.actor }}@users.noreply.github.com" |
| 116 | + git add "$KUSTOMIZATION_FILE" |
| 117 | + git commit -m "test: don-site → ${{ github.sha }} |
| 118 | +
|
| 119 | + Branch: ${{ github.ref_name }} |
| 120 | + Commit: ${{ github.server_url }}/${{ github.repository }}/commit/${{ github.sha }}" |
| 121 | + git push |
0 commit comments