Skip to content

Commit

Permalink
Optimize conditional execution in workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
mnixry committed Feb 6, 2024
1 parent 400610d commit 53ed490
Showing 1 changed file with 26 additions and 60 deletions.
86 changes: 26 additions & 60 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ jobs:
build:
runs-on: ubuntu-latest

permissions:
id-token: write

steps:
- uses: actions/checkout@v4

Expand All @@ -30,7 +33,15 @@ jobs:
- name: Build
run: pnpm build

- name: Dry run publish
- name: Publish
if: github.ref_type == 'tag' && startsWith(github.ref_name, 'v')
id: publish
run: |
pnpm config set '//registry.npmjs.org/:_authToken' '${{ secrets.NPM_TOKEN }}'
pnpm -r publish --provenance --access public --no-git-checks
- name: Publish (dry-run)
if: steps.publish.outcome != 'success'
run: pnpm -r publish --dry-run --no-git-checks

- name: Fild dist directories
Expand Down Expand Up @@ -74,68 +85,23 @@ jobs:
cache: pnpm

- name: Install Vercel CLI
run: npm install --global vercel@latest
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
run: |
if [ "${{ env.DEPLOY_ENV }}" == "production" ]; then
vercel build \
--prod \
--token=${{ env.VERCEL_TOKEN }}
else
vercel build \
--token=${{ env.VERCEL_TOKEN }}
fi
- name: Deploy Project Artifacts to Vercel
run: |
if [ "${{ env.DEPLOY_ENV }}" == "production" ]; then
vercel deploy \
--prebuilt \
--prod \
--token=${{ env.VERCEL_TOKEN }}
else
vercel deploy \
--prebuilt \
--token=${{ env.VERCEL_TOKEN }}
fi
release:
runs-on: ubuntu-latest
needs: build

if: github.ref_type == 'tag' && startsWith(github.ref_name, 'v')

permissions:
id-token: write

steps:
- uses: actions/checkout@v4
run: vercel pull --yes --environment=${{ env.DEPLOY_ENV }} --token=${{ env.VERCEL_TOKEN }}

- uses: actions/download-artifact@v4
with:
name: dists

- uses: pnpm/action-setup@v2
with:
version: 8
- name: Build Project Artifacts (Production)
if: env.DEPLOY_ENV == 'production'
run: vercel build --prod --token=${{ env.VERCEL_TOKEN }}

- uses: actions/setup-node@v4
with:
node-version: 20
cache: pnpm
- name: Build Project Artifacts (Preview)
if: env.DEPLOY_ENV == 'preview'
run: vercel build --token=${{ env.VERCEL_TOKEN }}

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

- name: Release
run: |
pnpm config set '//registry.npmjs.org/:_authToken' '${{ secrets.NPM_TOKEN }}'
pnpm -r publish --provenance --access public --no-git-checks
- name: Deploy Project Artifacts to Vercel (Preview)
if: env.DEPLOY_ENV == 'preview'
run: vercel deploy --prebuilt --token=${{ env.VERCEL_TOKEN }}

0 comments on commit 53ed490

Please sign in to comment.