Skip to content

Add release workflow for publishing npm packages #41

Add release workflow for publishing npm packages

Add release workflow for publishing npm packages #41

Workflow file for this run

name: CI
on:
push:
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: docker/setup-buildx-action@v3
- uses: crazy-max/ghaction-github-runtime@v3
- uses: pnpm/action-setup@v2
with:
version: 8
- uses: actions/setup-node@v4
with:
node-version: 20
cache: pnpm
- name: Install dependencies
run: pnpm install
- name: Build
run: pnpm build
- name: Dry run publish
run: pnpm -r publish --dry-run
- name: Fild dist directories
id: find-dists
run: |
echo 'dirs<<EOF' >> $GITHUB_OUTPUT
for dir in $(find . -type d -name "*dist" -not -path "*/node_modules/*"); do
echo $dir >> $GITHUB_OUTPUT
done
echo 'EOF' >> $GITHUB_OUTPUT
- uses: actions/upload-artifact@v4
with:
name: dists
path: ${{ steps.find-dists.outputs.dirs }}
deploy:
runs-on: ubuntu-latest
needs: build
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' }}
steps:
- uses: actions/checkout@v4
- uses: actions/download-artifact@v4
with:
name: dists
- uses: pnpm/action-setup@v2
with:
version: 8
- uses: actions/setup-node@v4
with:
node-version: 20
cache: pnpm
- name: Install Vercel CLI
run: npm 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
- uses: actions/download-artifact@v4
with:
name: dists
- uses: pnpm/action-setup@v2
with:
version: 8
- uses: actions/setup-node@v4
with:
node-version: 20
cache: pnpm
- name: Install dependencies
run: pnpm install
- name: Release
run: |
pnpm config set '//registry.npmjs.org/:_authToken' '${{ secrets.NPM_TOKEN }}'
pnpm -r publish --provenance --access public