Skip to content

Publish

Publish #10

Workflow file for this run

name: Publish
on:
workflow_dispatch:
inputs:
npm_tag:
description: 'npm dist-tag (e.g., latest, next, beta, rc)'
required: false
default: 'latest'
prerelease:
description: 'Mark the GitHub release as a pre-release'
required: false
type: boolean
default: false
release_body:
description: 'Optional release notes (leave empty for auto-generated notes)'
required: false
default: ''
permissions:
id-token: write # needed to push tags & create releases
contents: write
jobs:
release-and-publish:
runs-on: ubuntu-latest
env:
NPM_TAG: ${{ github.event.inputs.npm_tag || 'latest' }}
steps:
- name: Checkout main
uses: actions/checkout@v4
with:
ref: main
fetch-depth: 0
submodules: recursive
- name: Setup Node.js
uses: actions/setup-node@v4
with:
registry-url: 'https://registry.npmjs.org'
scope: '@cycleplatform'
always-auth: true
- run: npm install -g npm@latest
- name: Install jq
run: sudo apt-get update && sudo apt-get install -y jq
- name: Read package version
id: pkg
run: |
VERSION=$(jq -r '.version' package.json)
if [ -z "$VERSION" ] || [ "$VERSION" = "null" ]; then
echo "package.json version is missing"; exit 1
fi
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
echo "tag=v$VERSION" >> "$GITHUB_OUTPUT"
- name: Configure git
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
- name: Create git tag if missing
run: |
TAG="${{ steps.pkg.outputs.tag }}"
# Get latest refs safely
git fetch --tags origin
git fetch origin main
# Work on the remote tip to avoid local-branch/upstream issues
git checkout --detach origin/main
# Create annotated tag if it doesn't already exist
if git rev-parse -q --verify "refs/tags/$TAG" >/dev/null; then
echo "Tag $TAG already exists, continuing."
else
git tag -a "$TAG" -m "Release $TAG"
git push origin "$TAG"
fi
- name: Create or Update GitHub Release
id: release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ steps.pkg.outputs.tag }}
name: ${{ steps.pkg.outputs.tag }}
body: ${{ github.event.inputs.release_body }}
prerelease: ${{ github.event.inputs.prerelease }}
generate_release_notes: ${{ github.event.inputs.release_body == '' }}
draft: false
make_latest: true
allow_updates: true
- name: Install dependencies
run: npm ci
- name: Publish to npm
run: |
echo "Publishing version ${{ steps.pkg.outputs.version }} with dist-tag '${NPM_TAG}'"
npm publish --tag "${NPM_TAG}" --provenance --access public