Skip to content

ci: beta pr releases #348

ci: beta pr releases

ci: beta pr releases #348

Workflow file for this run

name: release
# All npm-publishing flows live in this single file so npm's trusted-publisher
# config only needs one workflow filename per package.
#
# release — push to main / workflow_dispatch.
# changesets/action opens/updates the "chore: version
# packages" PR. When that PR is merged, the same action
# publishes the bumped packages to npm under `latest`.
# `commitMode: github-api` gives commits a Verified badge
# without us shipping signing keys to CI.
#
# beta — push to main.
# Snapshot-publishes every push to `@beta`, with versions
# of the form `<next-release>-beta.<N>` (counter scoped to
# the base version, queried from npm).
#
# publish-pr — pull_request.
# Same as `beta` but `@pr` dist-tag and versions of the form
# `<next-release>-pr.<PR#>.<N>`. Sticky-header'd into the PR
# description so reviewers can install the canary build.
#
# Forks never reach the publish step (`is-not-fork` gate from pre-run).
on:
push:
branches:
- main
tags-ignore:
- '**'
paths-ignore:
- '**.md'
pull_request:
paths-ignore:
- '**.md'
workflow_dispatch:
permissions:
contents: write
pull-requests: write
id-token: write # npm OIDC trusted publishing
concurrency: ${{ github.workflow }}-${{ github.ref }}
jobs:
pre-run:
uses: ./.github/workflows/pre-run.yml
secrets: inherit
release:
runs-on: ubuntu-latest
needs: pre-run
if: needs.pre-run.outputs.is-not-fork == 'true' && github.event_name != 'pull_request'
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
fetch-depth: 0
- uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
with:
node-version: 24
cache: npm
- run: npm ci
- name: Create release PR or publish
uses: changesets/action@63a615b9cd06ba9a3e6d13796c7fbcb080a60a0b # v1.8.0
with:
version: npm run version
publish: npm run release
title: 'chore: version packages'
commit: 'chore: version packages'
commitMode: github-api
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
beta:
runs-on: ubuntu-latest
needs: pre-run
if: needs.pre-run.outputs.is-not-fork == 'true' && github.event_name == 'push'
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
fetch-depth: 0
- uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
with:
node-version: 24
cache: npm
- run: npm ci
- name: Seed dummy changeset if none present
run: |
if ! ls .changeset/*.md 2>/dev/null | grep -vqi readme; then
cat > .changeset/__snapshot.md <<'EOF'
---
"@stacks/common": patch
---
snapshot
EOF
fi
- run: npx changeset version
- run: node .github/scripts/snapshot-version.mjs beta
# CJS+ESM only — UMD has a known module-resolution bug after the
# snapshot rewrite. Per-package failures are non-fatal here; whatever
# builds gets published.
- name: Build CJS+ESM per workspace (skip UMD)
run: |
for pkg in packages/*/; do
[ -f "$pkg/package.json" ] || continue
( cd "$pkg" && npm run build:cjs --if-present && npm run build:esm --if-present ) || echo "build failed for $pkg (continuing)"
done
# NPM_CONFIG_IGNORE_SCRIPTS skips each package's prepublishOnly hook
# (which would re-run the UMD build and fail).
- run: npx changeset publish --tag beta --no-git-tag
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_CONFIG_IGNORE_SCRIPTS: 'true'
publish-pr:
runs-on: ubuntu-latest
needs: pre-run
if: needs.pre-run.outputs.is-not-fork == 'true' && github.event_name == 'pull_request'
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
fetch-depth: 0
- uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
with:
node-version: 24
cache: npm
- run: npm ci
- name: Seed dummy changeset if none present
run: |
if ! ls .changeset/*.md 2>/dev/null | grep -vqi readme; then
cat > .changeset/__snapshot.md <<'EOF'
---
"@stacks/common": patch
---
snapshot
EOF
fi
- run: npx changeset version
- id: snapshot
run: node .github/scripts/snapshot-version.mjs pr --pr ${{ github.event.pull_request.number }}
- name: Build CJS+ESM per workspace (skip UMD)
run: |
for pkg in packages/*/; do
[ -f "$pkg/package.json" ] || continue
( cd "$pkg" && npm run build:cjs --if-present && npm run build:esm --if-present ) || echo "build failed for $pkg (continuing)"
done
- run: npx changeset publish --tag pr --no-git-tag
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_CONFIG_IGNORE_SCRIPTS: 'true'
- name: Update PR sticky header
uses: janniks/pull-request-fixed-header@5d331404c3ece209cb49d932fcf0f85c995ce5b5 # v1.1.0
with:
header: |
> This PR was published to npm with the version `${{ steps.snapshot.outputs.version }}` (dist-tag `pr`).
> e.g. `npm install @stacks/common@${{ steps.snapshot.outputs.version }} --save-exact`
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}