Skip to content

ci: release

ci: release #13

Workflow file for this run

name: Release (Changesets)
on:
push:
branches: [main]
permissions:
contents: write
packages: write
id-token: write
issues: write
pull-requests: write
jobs:
release:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Bun
uses: oven-sh/setup-bun@v2
with:
bun-version: latest
- name: Install dependencies
run: bun install --frozen-lockfile
- name: Build
run: bun run build
- name: Test
run: bun run test
- name: Version and Publish via Changesets
uses: changesets/action@v1
with:
version: bun run version
publish: bun run release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
LEFTHOOK: "0"
NPM_CONFIG_PROVENANCE: "true"
- name: Configure npm for GitHub Packages
run: |
echo "//npm.pkg.github.com/:_authToken=${GITHUB_TOKEN}" > ~/.npmrc
echo "@${{ github.repository_owner }}:registry=https://npm.pkg.github.com/" >> ~/.npmrc
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Publish to GitHub Packages (GPR)
shell: bash
run: |
set -euo pipefail
shopt -s nullglob
for pkg in packages/*; do
if [ -f "$pkg/package.json" ] && grep -Eq '"gpr"[[:space:]]*:[[:space:]]*true' "$pkg/package.json"; then
echo "Preparing GPR for $pkg"
# Ensure the package has been built before attempting GPR staging
if [ ! -d "$pkg/dist" ]; then
echo "Skipping $pkg: dist/ not found (build step did not produce output)"
continue
fi
# Prepare the .gpr staged package; CLI exits non-zero on fatal errors
node packages/cli/dist/index.mjs gpr --root "$pkg"
# Only publish if the .gpr directory was created successfully
if [ -d "$pkg/.gpr" ]; then
echo "Publishing $pkg to GitHub Packages"
pushd "$pkg/.gpr" >/dev/null
# Skip publish if this exact version already exists in GPR
eval $(node -p "const p=require('./package.json'); 'NAME='+p.name+' VERSION='+p.version")
PUBLISHED_VER=$(npm view "$NAME@$VERSION" version 2>/dev/null || true)
if [ -n "$PUBLISHED_VER" ]; then
echo "Skip $NAME@$VERSION: already exists in GPR"
else
npm publish --access public || npm publish
fi
popd >/dev/null
else
echo "Skipping $pkg: .gpr not created"
continue
fi
fi
done