|
| 1 | +name: release |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [ main ] |
| 6 | + workflow_dispatch: |
| 7 | + inputs: |
| 8 | + tag: |
| 9 | + description: Override image tag (defaults to short SHA) |
| 10 | + required: false |
| 11 | + default: "" |
| 12 | + api_url: |
| 13 | + description: Browser-facing API URL baked into the build (REACT_ZFGBB_API_URL) |
| 14 | + required: false |
| 15 | + default: "https://api.bluedreamers.com/zfgbb" |
| 16 | + |
| 17 | +permissions: |
| 18 | + contents: read |
| 19 | + packages: write |
| 20 | + |
| 21 | +env: |
| 22 | + IMAGE_NAME: zfgbb-react |
| 23 | + |
| 24 | +jobs: |
| 25 | + build-and-push: |
| 26 | + runs-on: ubuntu-latest |
| 27 | + timeout-minutes: 30 |
| 28 | + outputs: |
| 29 | + tag: ${{ steps.meta.outputs.tag }} |
| 30 | + steps: |
| 31 | + - uses: actions/checkout@v6 |
| 32 | + |
| 33 | + - name: Compute lowercase image ref + tag |
| 34 | + id: meta |
| 35 | + run: | |
| 36 | + set -euo pipefail |
| 37 | + echo "IMAGE=ghcr.io/${GITHUB_REPOSITORY_OWNER,,}/${IMAGE_NAME}" >> "$GITHUB_ENV" |
| 38 | + if [[ -n "${{ inputs.tag }}" ]]; then |
| 39 | + tag="${{ inputs.tag }}" |
| 40 | + else |
| 41 | + tag="${GITHUB_SHA::12}" |
| 42 | + fi |
| 43 | + echo "tag=$tag" >> "$GITHUB_OUTPUT" |
| 44 | +
|
| 45 | + - uses: docker/setup-buildx-action@v4 |
| 46 | + |
| 47 | + - uses: docker/login-action@v4 |
| 48 | + with: |
| 49 | + registry: ghcr.io |
| 50 | + username: ${{ github.actor }} |
| 51 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 52 | + |
| 53 | + - name: Build and push |
| 54 | + uses: docker/build-push-action@v7 |
| 55 | + with: |
| 56 | + context: . |
| 57 | + target: app |
| 58 | + push: true |
| 59 | + provenance: false |
| 60 | + build-args: | |
| 61 | + REACT_ZFGBB_API_URL=${{ inputs.api_url || 'https://api.bluedreamers.com/zfgbb' }} |
| 62 | + tags: | |
| 63 | + ${{ env.IMAGE }}:${{ steps.meta.outputs.tag }} |
| 64 | + ${{ env.IMAGE }}:latest |
| 65 | + cache-from: type=registry,ref=${{ env.IMAGE }}:cache |
| 66 | + cache-to: type=registry,ref=${{ env.IMAGE }}:cache,mode=max |
| 67 | + |
| 68 | + bump-argo: |
| 69 | + needs: build-and-push |
| 70 | + if: github.event_name == 'push' && github.ref == 'refs/heads/main' |
| 71 | + runs-on: ubuntu-latest |
| 72 | + steps: |
| 73 | + - name: Checkout argocd repo |
| 74 | + uses: actions/checkout@v6 |
| 75 | + with: |
| 76 | + repository: ZeldaFanGameCentral/argocd.zfgc.com |
| 77 | + token: ${{ secrets.PR_BUMP_TOKEN }} |
| 78 | + path: argocd |
| 79 | + |
| 80 | + - name: Bump image.tag in charts/zfgbb-react/values.yaml |
| 81 | + id: bump |
| 82 | + env: |
| 83 | + NEW_TAG: ${{ needs.build-and-push.outputs.tag }} |
| 84 | + run: | |
| 85 | + set -euo pipefail |
| 86 | + cd argocd |
| 87 | + file=charts/zfgbb-react/values.yaml |
| 88 | + old_tag=$(awk '/^ tag:/{print $2; exit}' "$file" | tr -d '"') |
| 89 | + if [[ "$old_tag" == "$NEW_TAG" ]]; then |
| 90 | + echo "tag already $NEW_TAG; nothing to bump" |
| 91 | + echo "changed=false" >> "$GITHUB_OUTPUT" |
| 92 | + exit 0 |
| 93 | + fi |
| 94 | + sed -i "0,/^ tag: .*/s|| tag: $NEW_TAG|" "$file" |
| 95 | + echo "old_tag=$old_tag" >> "$GITHUB_OUTPUT" |
| 96 | + echo "changed=true" >> "$GITHUB_OUTPUT" |
| 97 | +
|
| 98 | + - name: Open PR |
| 99 | + if: steps.bump.outputs.changed == 'true' |
| 100 | + env: |
| 101 | + GH_TOKEN: ${{ secrets.PR_BUMP_TOKEN }} |
| 102 | + NEW_TAG: ${{ needs.build-and-push.outputs.tag }} |
| 103 | + OLD_TAG: ${{ steps.bump.outputs.old_tag }} |
| 104 | + run: | |
| 105 | + set -euo pipefail |
| 106 | + cd argocd |
| 107 | + branch="bump/zfgbb-react-$NEW_TAG" |
| 108 | + git config user.name 'zfgbb-react-release-bot' |
| 109 | + git config user.email 'zfgbb-react-release-bot@users.noreply.github.com' |
| 110 | + git checkout -b "$branch" |
| 111 | + git add charts/zfgbb-react/values.yaml |
| 112 | + msg=$(printf 'Bump zfgbb-react image to %s\n\nFrom: %s\nTo: %s\n' "$NEW_TAG" "$OLD_TAG" "$NEW_TAG") |
| 113 | + git commit -m "$msg" |
| 114 | + git push -u origin "$branch" |
| 115 | + gh pr create \ |
| 116 | + --base main \ |
| 117 | + --head "$branch" \ |
| 118 | + --title "Bump zfgbb-react image to $NEW_TAG" \ |
| 119 | + --body "Automated bump from \`$OLD_TAG\` to \`$NEW_TAG\` in \`charts/zfgbb-react/values.yaml\`. Built from $GITHUB_REPOSITORY@$GITHUB_SHA." |
0 commit comments