Files
oc/.github/workflows/publish.yml
T
dependabot[bot]andGitHub 8dc8233824 build(deps): bump actions/setup-node from 4 to 7
Bumps [actions/setup-node](https://github.com/actions/setup-node) from 4 to 7.
- [Release notes](https://github.com/actions/setup-node/releases)
- [Commits](https://github.com/actions/setup-node/compare/v4...v7)

---
updated-dependencies:
- dependency-name: actions/setup-node
  dependency-version: '7'
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-08-18 13:43:14 +00:00

69 lines
2.5 KiB
YAML

# Publishes to npm via OIDC trusted publishing: no token, no OTP prompt.
# One-time setup on npmjs.com after the package exists: package settings,
# Trusted Publisher, GitHub Actions, repository only-cli/oc, workflow
# file publish.yml. From then on, publishing a GitHub release ships to npm.
#
# Release channels map to npm dist-tags:
# latest stable releases, what `npm install @only-cli/oc` gets
# beta release candidates, version like 0.2.0-beta.1
# alpha earlier previews, version like 0.2.0-alpha.1
# dev throwaway builds from main, version stamped per run
#
# A GitHub release picks its channel from the version suffix, so marking a
# release 0.2.0-beta.1 ships to beta automatically. Run the workflow by hand
# (Actions tab, publish, Run workflow) to cut a dev build without a release.
name: publish
on:
release:
types: [published]
workflow_dispatch:
inputs:
channel:
description: npm dist-tag to publish under
type: choice
options: [dev, alpha, beta, latest]
default: dev
permissions:
contents: read
id-token: write
jobs:
publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v7
with:
node-version: 24
registry-url: https://registry.npmjs.org
# Trusted publishing needs npm 11.5.1 or newer.
- run: npm install -g npm@latest
- run: npm ci
- run: npm test
- name: pick channel and version
run: |
V=$(node -p "require('./package.json').version")
CHANNEL="${{ github.event_name == 'workflow_dispatch' && inputs.channel || '' }}"
if [ -z "$CHANNEL" ]; then
case "$V" in
*-alpha*) CHANNEL=alpha ;;
*-beta*) CHANNEL=beta ;;
*-dev*) CHANNEL=dev ;;
*) CHANNEL=latest ;;
esac
fi
# Fail loud instead of shipping a prerelease as stable.
if [ "$CHANNEL" = latest ] && [ "${V#*-}" != "$V" ]; then
echo "refusing to publish prerelease version $V to latest" >&2
exit 1
fi
# Dev builds get a unique version per run so repeat publishes never
# collide; the version in git stays untouched.
if [ "$CHANNEL" = dev ] && [ "${V%-dev*}" = "$V" ]; then
npm version --no-git-tag-version "${V%%-*}-dev.${{ github.run_number }}"
fi
echo "CHANNEL=$CHANNEL" >> "$GITHUB_ENV"
- run: npm publish --access public --tag "$CHANNEL"