Merge pull request #5 from Snowgent/feature/#3-onboarding #8
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Deploy | |
| on: | |
| push: | |
| branches: ['develop', 'main'] | |
| permissions: | |
| contents: write | |
| concurrency: | |
| group: prod-${{ github.ref }} | |
| cancel-in-progress: true | |
| jobs: | |
| promote-and-deploy: | |
| if: ${{ github.ref == 'refs/heads/develop' }} | |
| runs-on: ubuntu-latest | |
| outputs: | |
| changed: ${{ steps.promote.outputs.changed }} | |
| new_sha: ${{ steps.promote.outputs.new_sha }} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Promote develop → main (fast-forward only) | |
| id: promote | |
| run: | | |
| set -euo pipefail | |
| git config user.name "github-actions[bot]" | |
| git config user.email "41898282+github-actions[bot]@users.noreply.github.com" | |
| git fetch origin main develop | |
| BEFORE="$(git rev-parse origin/main)" | |
| git checkout -B main origin/main | |
| git merge --ff-only origin/develop | |
| AFTER="$(git rev-parse HEAD)" | |
| if [ "$BEFORE" = "$AFTER" ]; then | |
| echo "changed=false" >> "$GITHUB_OUTPUT" | |
| echo "new_sha=$AFTER" >> "$GITHUB_OUTPUT" | |
| exit 0 | |
| fi | |
| git push origin main | |
| echo "changed=true" >> "$GITHUB_OUTPUT" | |
| echo "new_sha=$AFTER" >> "$GITHUB_OUTPUT" | |
| - uses: actions/setup-node@v4 | |
| if: ${{ steps.promote.outputs.changed == 'true' }} | |
| with: | |
| node-version: 20 | |
| registry-url: 'https://registry.npmjs.org' | |
| cache: 'npm' | |
| cache-dependency-path: 'package-lock.json' | |
| - name: Force npmjs registry | |
| if: ${{ steps.promote.outputs.changed == 'true' }} | |
| run: | | |
| npm config set registry https://registry.npmjs.org/ | |
| echo "registry=https://registry.npmjs.org/" > ~/.npmrc | |
| - name: Install dependencies | |
| if: ${{ steps.promote.outputs.changed == 'true' }} | |
| run: npm ci | |
| - name: Install Vercel CLI | |
| if: ${{ steps.promote.outputs.changed == 'true' }} | |
| run: npm i -g vercel@latest | |
| - name: Pull Vercel Env (production) | |
| if: ${{ steps.promote.outputs.changed == 'true' }} | |
| env: | |
| VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }} | |
| VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }} | |
| run: vercel pull --yes --environment=production --token='${{ secrets.VERCEL_TOKEN }}' | |
| - name: Build (prebuilt, prod) | |
| if: ${{ steps.promote.outputs.changed == 'true' }} | |
| run: vercel build --prod --token='${{ secrets.VERCEL_TOKEN }}' | |
| - name: Deploy (prod) | |
| if: ${{ steps.promote.outputs.changed == 'true' }} | |
| id: deploy | |
| run: | | |
| url="$(vercel deploy --prebuilt --prod --token='${{ secrets.VERCEL_TOKEN }}')" | |
| echo "::notice::Deployed $url" | |
| deploy-on-main: | |
| if: ${{ github.ref == 'refs/heads/main' }} | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: actions/setup-node@v4 | |
| with: | |
| node-version: 20 | |
| registry-url: 'https://registry.npmjs.org' | |
| cache: 'npm' | |
| cache-dependency-path: 'package-lock.json' | |
| - name: Force npmjs registry | |
| run: | | |
| npm config set registry https://registry.npmjs.org/ | |
| echo "registry=https://registry.npmjs.org/" > ~/.npmrc | |
| - name: Install dependencies | |
| run: npm ci | |
| - run: npm i -g vercel@latest | |
| - name: Pull Vercel Env (production) | |
| env: | |
| VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }} | |
| VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }} | |
| run: vercel pull --yes --environment=production --token='${{ secrets.VERCEL_TOKEN }}' | |
| - name: Build (prebuilt, prod) | |
| run: vercel build --prod --token='${{ secrets.VERCEL_TOKEN }}' | |
| - name: Deploy (prod) | |
| run: vercel deploy --prebuilt --prod --token='${{ secrets.VERCEL_TOKEN }}' |