Skip to content

Commit

Permalink
Update build workflow to use amondnet/vercel-action
Browse files Browse the repository at this point in the history
  • Loading branch information
mnixry committed Feb 27, 2024
1 parent 12b19e0 commit ac727a8
Showing 1 changed file with 15 additions and 31 deletions.
46 changes: 15 additions & 31 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@ name: CI
on:
push:
pull_request_target:
types: [opened, synchronize]
workflow_dispatch:

env:
CHECKOUT_REF: ${{ github.event.pull_request.head.sha || github.sha }}
NODE_ENV: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' && 'production' || 'development'}}

jobs:
build:
runs-on: ubuntu-latest
Expand All @@ -15,6 +18,8 @@ jobs:

steps:
- uses: actions/checkout@v4
with:
ref: ${{ env.CHECKOUT_REF }}

- uses: docker/setup-buildx-action@v3

Expand Down Expand Up @@ -64,19 +69,12 @@ jobs:
runs-on: ubuntu-latest
needs: build

# If push event triggered, it must not be a pull request
if: github.event_name != 'push' || !startsWith(github.ref, 'refs/pull/')

env:
VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }}
VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }}
DEPLOY_ENV: ${{ github.ref == 'refs/heads/main' && 'production' || 'preview' }}
if: github.event_name != 'push' || !startsWith(github.event.pull_request.head.ref, 'ref/pull/')

steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha || github.sha }}
ref: ${{ env.CHECKOUT_REF }}

- uses: actions/download-artifact@v4
with:
Expand All @@ -91,24 +89,10 @@ jobs:
node-version: 20
cache: pnpm

- name: Install Vercel CLI
run: pnpm install --global vercel@latest

- name: Pull Vercel Environment Information
run: vercel pull --yes --environment=${{ env.DEPLOY_ENV }} --token=${{ env.VERCEL_TOKEN }}

- name: Build Project Artifacts (Production)
if: env.DEPLOY_ENV == 'production'
run: vercel build --prod --token=${{ env.VERCEL_TOKEN }}

- name: Build Project Artifacts (Preview)
if: env.DEPLOY_ENV == 'preview'
run: vercel build --token=${{ env.VERCEL_TOKEN }}

- name: Deploy Project Artifacts to Vercel (Production)
if: env.DEPLOY_ENV == 'production'
run: vercel deploy --prebuilt --prod --token=${{ env.VERCEL_TOKEN }}

- name: Deploy Project Artifacts to Vercel (Preview)
if: env.DEPLOY_ENV == 'preview'
run: vercel deploy --prebuilt --token=${{ env.VERCEL_TOKEN }}
- uses: amondnet/vercel-action@v20 #deploy
with:
vercel-token: ${{ secrets.VERCEL_TOKEN }}
github-token: ${{ secrets.GITHUB_TOKEN }}
vercel-args: ${{ env.NODE_ENV == 'production' && '--prod' || ''}}
vercel-org-id: ${{ secrets.VERCEL_ORG_ID }}
vercel-project-id: ${{ secrets.VERCEL_PROJECT_ID }}

0 comments on commit ac727a8

Please sign in to comment.