Skip to content

ci: public-npm publish non-blocking (unblock GitHub Packages publish) #108

ci: public-npm publish non-blocking (unblock GitHub Packages publish)

ci: public-npm publish non-blocking (unblock GitHub Packages publish) #108

Workflow file for this run

name: CI/CD Pipeline
on:
push:
branches:
- main
pull_request:
branches:
- main
workflow_dispatch:
inputs:
publish:
description: 'Publish packages (npm + GitHub Packages)'
required: false
type: boolean
default: false
jobs:
build:
name: Build & Test
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup pnpm
uses: pnpm/action-setup@v4
with:
version: 10.17.1
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'pnpm'
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Lint
run: pnpm lint
- name: Type check
run: pnpm type-check
- name: Run tests
run: pnpm test
- name: Build all packages
run: pnpm build
- name: Build Storybook
run: pnpm build-storybook
- name: Upload Storybook artifact
uses: actions/upload-artifact@v4
with:
name: storybook-static
path: apps/storybook/storybook-static
retention-days: 7
chromatic:
name: Chromatic Visual Tests
runs-on: ubuntu-latest
needs: build
if: github.event_name == 'push' || github.event_name == 'pull_request'
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup pnpm
uses: pnpm/action-setup@v4
with:
version: 10.17.1
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'pnpm'
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Run Chromatic
uses: chromaui/action@latest
continue-on-error: true
with:
projectToken: ${{ secrets.CHROMATIC_PROJECT_TOKEN }}
workingDir: apps/storybook
buildScriptName: build-storybook
onlyChanged: true
autoAcceptChanges: main
exitZeroOnChanges: true
changeset:
name: Version and Publish Packages
runs-on: ubuntu-latest
needs: build
if: |
(github.event_name == 'push' && github.ref == 'refs/heads/main') ||
(github.event_name == 'workflow_dispatch' && inputs.publish == true)
permissions:
contents: write
packages: write
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.ADMIN_TOKEN }}
- name: Setup pnpm
uses: pnpm/action-setup@v4
with:
version: 10.17.1
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'pnpm'
registry-url: 'https://registry.npmjs.org'
scope: '@tesserix'
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Build packages
run: pnpm build
- name: Configure Git
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
- name: Check for changesets
id: check-changesets
run: |
if [ -n "$(find .changeset -name '*.md' -not -name 'README.md' -print -quit)" ]; then
echo "has_changesets=true" >> $GITHUB_OUTPUT
else
echo "has_changesets=false" >> $GITHUB_OUTPUT
fi
- name: Version packages
if: steps.check-changesets.outputs.has_changesets == 'true'
run: |
pnpm version-packages
git add .
git commit -m "chore: version packages" || echo "No version changes"
git push
- name: Publish to npm (public registry)
if: steps.check-changesets.outputs.has_changesets == 'true' || (github.event_name == 'workflow_dispatch' && inputs.publish == true)
# Public-npm publish is best-effort — @tesserix is consumed from
# GitHub Packages, so a public-registry auth failure must NOT abort
# the job before the GitHub Packages publish step below runs.
continue-on-error: true
run: |
rm -f packages/web/.npmrc
echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" > "$NPM_CONFIG_USERCONFIG"
cp "$NPM_CONFIG_USERCONFIG" .npmrc
pnpm release
- name: Publish to GitHub Packages
if: steps.check-changesets.outputs.has_changesets == 'true' || (github.event_name == 'workflow_dispatch' && inputs.publish == true)
run: |
echo "@tesserix:registry=https://npm.pkg.github.com" > "$NPM_CONFIG_USERCONFIG"
echo "//npm.pkg.github.com/:_authToken=${{ secrets.ADMIN_TOKEN }}" >> "$NPM_CONFIG_USERCONFIG"
cp "$NPM_CONFIG_USERCONFIG" .npmrc
pnpm changeset publish