Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
110 changes: 110 additions & 0 deletions .github/workflows/publish-github-packages.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
name: Publish to GitHub Packages

on:
workflow_dispatch:
inputs:
dry_run:
description: "Run npm publish as a dry run"
required: false
default: "false"
type: choice
options:
- "false"
- "true"

permissions:
contents: read
packages: write

concurrency:
group: publish-github-packages-${{ github.ref }}
cancel-in-progress: false

jobs:
publish:
runs-on: ubuntu-latest
steps:
- name: Checkout sumit-react
uses: actions/checkout@v4
with:
path: sumit-react

- name: Checkout sumit-api peer package
uses: actions/checkout@v4
with:
repository: Digitizers/sumit-api
path: sumit-api

- uses: pnpm/action-setup@v4
with:
version: 10.26.0

- uses: actions/setup-node@v4
with:
node-version: 22
cache: pnpm
cache-dependency-path: |
sumit-react/pnpm-lock.yaml
sumit-api/pnpm-lock.yaml
registry-url: https://npm.pkg.github.com
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Keep install registry on npmjs before build steps

Setting registry-url to https://npm.pkg.github.com at setup time makes all subsequent pnpm install steps resolve packages from GitHub Packages instead of npmjs, so standard dependencies like react are looked up at npm.pkg.github.com and fail (403/404). In this workflow, installs happen immediately after setup (Build sumit-api peer package and Install sumit-react), so the publish job will fail before packaging unless the registry is switched back or scoped only to the publish step.

Useful? React with 👍 / 👎.


- name: Build sumit-api peer package
working-directory: sumit-api
run: |
pnpm install --frozen-lockfile
pnpm build

- name: Install sumit-react
working-directory: sumit-react
run: pnpm install --frozen-lockfile

- name: Typecheck
working-directory: sumit-react
run: pnpm typecheck

- name: Test
working-directory: sumit-react
run: pnpm test

- name: Build
working-directory: sumit-react
run: pnpm build

- name: Pack check
working-directory: sumit-react
run: npm pack --dry-run

- name: Build GitHub Packages tarball directory
working-directory: sumit-react
run: |
set -euo pipefail
PACK_JSON=$(npm pack --json --ignore-scripts)
PACK_FILE=$(printf '%s' "$PACK_JSON" | node -e "let s=''; process.stdin.on('data', d => s += d); process.stdin.on('end', () => { const start = s.indexOf('['); const p = JSON.parse(s.slice(start)); console.log(p[0].filename); });")
rm -rf .publish-ghpkg
mkdir .publish-ghpkg
tar -xzf "$PACK_FILE" -C .publish-ghpkg --strip-components=1
node - <<'NODE'
const fs = require('node:fs');
const path = '.publish-ghpkg/package.json';
const pkg = JSON.parse(fs.readFileSync(path, 'utf8'));
pkg.name = '@digitizers/sumit-react';
pkg.publishConfig = {
registry: 'https://npm.pkg.github.com',
access: 'public'
};
fs.writeFileSync(path, `${JSON.stringify(pkg, null, 2)}\n`);
NODE

- name: Publish scoped package to GitHub Packages
working-directory: sumit-react/.publish-ghpkg
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
set -euo pipefail
npm config set @digitizers:registry https://npm.pkg.github.com
npm config set //npm.pkg.github.com/:_authToken "${NODE_AUTH_TOKEN}"
if [ "${{ inputs.dry_run }}" = "true" ]; then
npm publish --registry=https://npm.pkg.github.com --access public --ignore-scripts --dry-run
else
npm publish --registry=https://npm.pkg.github.com --access public --ignore-scripts
fi
Loading