ci: add tag-gated npm release workflow
This commit is contained in:
87
.gitea/workflows/npm-release.yml
Normal file
87
.gitea/workflows/npm-release.yml
Normal file
@@ -0,0 +1,87 @@
|
||||
name: npm release
|
||||
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- 'v*'
|
||||
- '[0-9]*'
|
||||
|
||||
jobs:
|
||||
verify:
|
||||
name: verify
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 20
|
||||
|
||||
steps:
|
||||
- name: Check out repository
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Set up Node.js
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: '20'
|
||||
registry-url: 'https://registry.npmjs.org'
|
||||
|
||||
- name: Set up Bun
|
||||
uses: oven-sh/setup-bun@v2
|
||||
with:
|
||||
bun-version: '1.3.13'
|
||||
|
||||
- name: Install dependencies
|
||||
run: bun install --frozen-lockfile
|
||||
|
||||
- name: Verify release tag matches package version
|
||||
shell: bash
|
||||
run: |
|
||||
set -euo pipefail
|
||||
TAG_NAME="${GITHUB_REF##refs/tags/}"
|
||||
PACKAGE_VERSION="$(node -p "require('./package.json').version")"
|
||||
|
||||
if [ "$TAG_NAME" = "v$PACKAGE_VERSION" ] || [ "$TAG_NAME" = "$PACKAGE_VERSION" ]; then
|
||||
echo "Release tag $TAG_NAME matches package version $PACKAGE_VERSION"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
echo "Tag $TAG_NAME does not match package.json version $PACKAGE_VERSION" >&2
|
||||
exit 1
|
||||
|
||||
- name: Run verify pipeline
|
||||
run: |
|
||||
bun run test
|
||||
bun run check
|
||||
bun run build
|
||||
|
||||
release:
|
||||
name: publish to npm
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 20
|
||||
needs:
|
||||
- verify
|
||||
|
||||
steps:
|
||||
- name: Check out repository
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Set up Node.js
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: '20'
|
||||
registry-url: 'https://registry.npmjs.org'
|
||||
|
||||
- name: Set up Bun
|
||||
uses: oven-sh/setup-bun@v2
|
||||
with:
|
||||
bun-version: '1.3.13'
|
||||
|
||||
- name: Install dependencies
|
||||
run: bun install --frozen-lockfile
|
||||
|
||||
- name: Build package
|
||||
run: bun run build
|
||||
|
||||
- name: Publish package to npm
|
||||
env:
|
||||
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
||||
run: npm publish
|
||||
Reference in New Issue
Block a user