Skip to content

docs(readme): document Vite build and dev channel publishing #2

docs(readme): document Vite build and dev channel publishing

docs(readme): document Vite build and dev channel publishing #2

Workflow file for this run

name: Publish npm
on:
push:
branches:
- main
tags:
- 'v*'
permissions:
contents: read
id-token: write
concurrency:
group: npm-publish-${{ github.ref_name }}
cancel-in-progress: false
jobs:
publish:
runs-on: ubuntu-latest
steps:
- name: Classify publish target
id: target
env:
REF_NAME: ${{ github.ref_name }}
REF_TYPE: ${{ github.ref_type }}
run: |
if [[ "$REF_TYPE" == "tag" && "$REF_NAME" =~ ^v([0-9]+)\.([0-9]+)\.([0-9]+)$ ]]; then
echo "publish=true" >> "$GITHUB_OUTPUT"
echo "mode=stable" >> "$GITHUB_OUTPUT"
echo "dist_tag=latest" >> "$GITHUB_OUTPUT"
echo "version=${BASH_REMATCH[1]}.${BASH_REMATCH[2]}.${BASH_REMATCH[3]}" >> "$GITHUB_OUTPUT"
elif [[ "$REF_TYPE" == "branch" && "$REF_NAME" == "main" ]]; then
echo "publish=true" >> "$GITHUB_OUTPUT"
echo "mode=development" >> "$GITHUB_OUTPUT"
echo "dist_tag=dev" >> "$GITHUB_OUTPUT"
else
echo "publish=false" >> "$GITHUB_OUTPUT"
echo "mode=skip" >> "$GITHUB_OUTPUT"
echo "dist_tag=n/a" >> "$GITHUB_OUTPUT"
fi
- name: Checkout source
if: steps.target.outputs.publish == 'true'
uses: actions/checkout@v4
- name: Setup Node.js
if: steps.target.outputs.publish == 'true'
uses: actions/setup-node@v4
with:
node-version: 20
cache: npm
cache-dependency-path: package-lock.json
registry-url: https://registry.npmjs.org
- name: Verify release tag matches package version
if: steps.target.outputs.mode == 'stable'
id: version
run: |
version="$(npm run --silent publish:verify-release -- "${{ github.ref_name }}")"
echo "version=$version" >> "$GITHUB_OUTPUT"
- name: Resolve development version
if: steps.target.outputs.mode == 'development'
id: dev_version
run: |
version="$(npm run --silent publish:resolve-dev-version)"
echo "version=$version" >> "$GITHUB_OUTPUT"
- name: Install dependencies
if: steps.target.outputs.publish == 'true'
run: npm ci
- name: Stamp development package version
if: steps.target.outputs.mode == 'development'
env:
DEV_VERSION: ${{ steps.dev_version.outputs.version }}
run: npm version --no-git-tag-version "$DEV_VERSION"
- name: Build package
if: steps.target.outputs.publish == 'true'
run: npm run build
- name: Typecheck package
if: steps.target.outputs.publish == 'true'
run: npm run typecheck
- name: Run tests
if: steps.target.outputs.publish == 'true'
run: npm test
- name: Verify packed files
if: steps.target.outputs.publish == 'true'
run: npm run pack:check
- name: Publish to npm latest dist-tag
if: steps.target.outputs.mode == 'stable'
run: npm publish --tag latest --provenance --access public
- name: Publish to npm dev dist-tag
if: steps.target.outputs.mode == 'development'
run: npm publish --tag dev --provenance --access public
- name: Summarize publish result
if: always()
env:
SHOULD_PUBLISH: ${{ steps.target.outputs.publish || 'false' }}
PUBLISH_MODE: ${{ steps.target.outputs.mode || 'skip' }}
RESOLVED_VERSION: ${{ steps.version.outputs.version || steps.dev_version.outputs.version || steps.target.outputs.version || 'n/a' }}
JOB_STATUS: ${{ job.status }}
REF_NAME: ${{ github.ref_name }}
DIST_TAG: ${{ steps.target.outputs.dist_tag || 'n/a' }}
run: |
{
echo "## npm publish"
echo
echo "- Ref: $REF_NAME"
echo "- Mode: $PUBLISH_MODE"
echo "- Publish enabled: $SHOULD_PUBLISH"
echo "- Resolved version: $RESOLVED_VERSION"
echo "- Dist-tag: $DIST_TAG"
echo "- Registry: npmjs.org"
if [ "$SHOULD_PUBLISH" != "true" ]; then
echo "- Result: skipped because the ref is neither main nor a strict vX.Y.Z tag."
elif [ "$JOB_STATUS" = "success" ]; then
echo "- Result: published with provenance enabled."
else
echo "- Result: failed before publish completed. Check the failed gate above."
fi
} >> "$GITHUB_STEP_SUMMARY"