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