|
| 1 | +name: Deploy |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: ['develop', 'main'] |
| 6 | +permissions: |
| 7 | + contents: write |
| 8 | + |
| 9 | +concurrency: |
| 10 | + group: prod-${{ github.ref }} |
| 11 | + cancel-in-progress: true |
| 12 | + |
| 13 | +jobs: |
| 14 | + promote-and-deploy: |
| 15 | + if: ${{ github.ref == 'refs/heads/develop' }} |
| 16 | + runs-on: ubuntu-latest |
| 17 | + outputs: |
| 18 | + changed: ${{ steps.promote.outputs.changed }} |
| 19 | + new_sha: ${{ steps.promote.outputs.new_sha }} |
| 20 | + steps: |
| 21 | + - uses: actions/checkout@v4 |
| 22 | + with: |
| 23 | + fetch-depth: 0 |
| 24 | + - name: Promote develop → main (fast-forward only) |
| 25 | + id: promote |
| 26 | + env: |
| 27 | + GH_USER_NAME: github-actions[bot] |
| 28 | + GH_USER_EMAIL: 41898282+github-actions[bot]@users.noreply.github.com |
| 29 | + run: | |
| 30 | + set -euo pipefail |
| 31 | + git config user.name "$GH_USER_NAME" |
| 32 | + git config user.email "$GH_USER_EMAIL" |
| 33 | +
|
| 34 | + git fetch origin main develop |
| 35 | +
|
| 36 | + BEFORE="$(git rev-parse origin/main)" |
| 37 | + git checkout -B main origin/main |
| 38 | +
|
| 39 | + git merge --ff-only origin/develop |
| 40 | +
|
| 41 | + AFTER="$(git rev-parse HEAD)" |
| 42 | +
|
| 43 | + if [ "$BEFORE" = "$AFTER" ]; then |
| 44 | + echo "No changes to promote. main already up to date." |
| 45 | + echo "changed=false" >> "$GITHUB_OUTPUT" |
| 46 | + echo "new_sha=$AFTER" >> "$GITHUB_OUTPUT" |
| 47 | + exit 0 |
| 48 | + fi |
| 49 | +
|
| 50 | + git push origin main |
| 51 | + echo "changed=true" >> "$GITHUB_OUTPUT" |
| 52 | + echo "new_sha=$AFTER" >> "$GITHUB_OUTPUT" |
| 53 | +
|
| 54 | + - uses: actions/setup-node@v4 |
| 55 | + if: ${{ steps.promote.outputs.changed == 'true' }} |
| 56 | + with: |
| 57 | + node-version: 20 |
| 58 | + registry-url: 'https://registry.npmjs.org' |
| 59 | + |
| 60 | + - name: Force npmjs registry |
| 61 | + if: ${{ steps.promote.outputs.changed == 'true' }} |
| 62 | + run: | |
| 63 | + npm config set registry https://registry.npmjs.org/ |
| 64 | + echo "registry=https://registry.npmjs.org/" > ~/.npmrc |
| 65 | +
|
| 66 | + - uses: pnpm/action-setup@v4 |
| 67 | + if: ${{ steps.promote.outputs.changed == 'true' }} |
| 68 | + with: |
| 69 | + version: 10 |
| 70 | + standalone: true |
| 71 | + |
| 72 | + |
| 73 | + - run: pnpm -v |
| 74 | + if: ${{ steps.promote.outputs.changed == 'true' }} |
| 75 | + |
| 76 | + - uses: actions/setup-node@v4 |
| 77 | + if: ${{ steps.promote.outputs.changed == 'true' }} |
| 78 | + with: |
| 79 | + node-version: 20 |
| 80 | + cache: 'pnpm' |
| 81 | + cache-dependency-path: 'pnpm-lock.yaml' |
| 82 | + |
| 83 | + |
| 84 | + - name: Install Vercel CLI |
| 85 | + if: ${{ steps.promote.outputs.changed == 'true' }} |
| 86 | + run: npm i -g vercel@latest |
| 87 | + |
| 88 | + - name: Pull Vercel Env (production) |
| 89 | + if: ${{ steps.promote.outputs.changed == 'true' }} |
| 90 | + env: |
| 91 | + VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }} |
| 92 | + VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }} |
| 93 | + run: vercel pull --yes --environment=production --token='${{ secrets.VERCEL_TOKEN }}' |
| 94 | + |
| 95 | + - name: Build (prebuilt, prod) |
| 96 | + if: ${{ steps.promote.outputs.changed == 'true' }} |
| 97 | + run: vercel build --prod --token='${{ secrets.VERCEL_TOKEN }}' |
| 98 | + |
| 99 | + - name: Deploy (prod) |
| 100 | + if: ${{ steps.promote.outputs.changed == 'true' }} |
| 101 | + id: deploy |
| 102 | + run: | |
| 103 | + url="$(vercel deploy --prebuilt --prod --token='${{ secrets.VERCEL_TOKEN }}')" |
| 104 | + echo "::notice::Deployed $url" |
| 105 | +
|
| 106 | +
|
| 107 | + deploy-on-main: |
| 108 | + if: ${{ github.ref == 'refs/heads/main' }} |
| 109 | + runs-on: ubuntu-latest |
| 110 | + steps: |
| 111 | + - uses: actions/checkout@v4 |
| 112 | + - uses: actions/setup-node@v4 |
| 113 | + with: |
| 114 | + node-version: 20 |
| 115 | + registry-url: 'https://registry.npmjs.org' |
| 116 | + |
| 117 | + - name: Force npmjs registry |
| 118 | + run: | |
| 119 | + npm config set registry https://registry.npmjs.org/ |
| 120 | + echo "registry=https://registry.npmjs.org/" > ~/.npmrc |
| 121 | +
|
| 122 | +
|
| 123 | + - uses: pnpm/action-setup@v4 |
| 124 | + with: |
| 125 | + version: 10 |
| 126 | + standalone: true |
| 127 | + - run: pnpm -v |
| 128 | + |
| 129 | + - uses: actions/setup-node@v4 |
| 130 | + with: |
| 131 | + node-version: 20 |
| 132 | + cache: 'pnpm' |
| 133 | + cache-dependency-path: 'pnpm-lock.yaml' |
| 134 | + |
| 135 | + - run: npm i -g vercel@latest |
| 136 | + - name: Pull Vercel Env (production) |
| 137 | + env: |
| 138 | + VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }} |
| 139 | + VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }} |
| 140 | + run: vercel pull --yes --environment=production --token='${{ secrets.VERCEL_TOKEN }}' |
| 141 | + - name: Build (prebuilt, prod) |
| 142 | + run: vercel build --prod --token='${{ secrets.VERCEL_TOKEN }}' |
| 143 | + - name: Deploy (prod) |
| 144 | + run: vercel deploy --prebuilt --prod --token='${{ secrets.VERCEL_TOKEN }}' |
0 commit comments