Skip to content

chore(release): 0.2.13 馃殌 #29

chore(release): 0.2.13 馃殌

chore(release): 0.2.13 馃殌 #29

Workflow file for this run

name: Publish package
on:
workflow_dispatch:
release:
types: [published]
push:
tags:
- 'v*'
permissions:
id-token: write # needed for npm provenance (npmjs.com)
contents: read
packages: write # needed for GitHub Packages
deployments: write # needed to create deployment records
jobs:
publish:
name: Build, test, and publish to npm & GitHub Packages
runs-on: ubuntu-latest
steps:
- name: Check out repository
uses: actions/checkout@v4
- name: Set up Node.js (npmjs.com)
uses: actions/setup-node@v4
with:
node-version: 20
registry-url: https://registry.npmjs.org
scope: '@programinglive'
cache: npm
- name: Install dependencies
run: npm ci
- name: Build
run: npm run build --if-present
- name: Test
run: npm test --if-present
# Pack once so we publish the same bits to both registries
- name: Create tarball
run: |
rm -f *.tgz
npm pack --silent
# This outputs something like: programinglive-zettly-editor-0.1.16.tgz
# We'll capture the filename for reuse.
- id: tarball
run: echo "TARBALL=$(ls *.tgz)" >> $GITHUB_ENV
- name: Determine package version
id: pkg
run: |
VERSION=$(node -p "require('./package.json').version")
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
echo "VERSION=$VERSION" >> "$GITHUB_ENV"
# ---- Publish to npmjs.com ----
- name: Publish to npm (npmjs.com) with provenance
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} # npm Automation token
VERSION: ${{ steps.pkg.outputs.version }}
run: |
echo "Registry: $(npm config get registry)"
npm whoami || true
if npm view "@programinglive/zettly-editor@${VERSION}" version >/dev/null 2>&1; then
echo "Version ${VERSION} already published on npm, skipping..."
else
npm publish "${TARBALL}" --provenance --access public
fi
# ---- Publish to GitHub Packages ----
# Switch registry for GitHub Packages
- name: Set up Node.js (GitHub Packages)
uses: actions/setup-node@v4
with:
node-version: 20
registry-url: https://npm.pkg.github.com
scope: '@programinglive'
- name: Publish to GitHub Packages
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }} # built-in token
VERSION: ${{ steps.pkg.outputs.version }}
run: |
echo "Registry: $(npm config get registry)"
if npm view "@programinglive/zettly-editor@${VERSION}" version >/dev/null 2>&1; then
echo "Version ${VERSION} already published on GitHub Packages, skipping..."
else
npm publish "${TARBALL}"
fi
- name: Record deployment
if: ${{ success() }}
uses: actions/github-script@v7
env:
VERSION: ${{ steps.pkg.outputs.version }}
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const version = process.env.VERSION;
const description = `Published @programinglive/zettly-editor@${version}`;
const deployment = await github.rest.repos.createDeployment({
owner: context.repo.owner,
repo: context.repo.repo,
ref: context.sha,
environment: 'npm-publish',
auto_merge: false,
required_contexts: [],
description,
});
await github.rest.repos.createDeploymentStatus({
owner: context.repo.owner,
repo: context.repo.repo,
deployment_id: deployment.data.id,
state: 'success',
environment: 'npm-publish',
environment_url: `https://www.npmjs.com/package/@programinglive/zettly-editor/v/${version}`,
log_url: `${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`,
});