Skip to content

Commit cd2f50a

Browse files
authored
ci: set release version at publish time + allow manual publish (#318)
1 parent 3d4ea7a commit cd2f50a

3 files changed

Lines changed: 23 additions & 11 deletions

File tree

.github/workflows/release.yml

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@ name: 'Release'
33
on:
44
release:
55
types: [published]
6+
workflow_dispatch:
7+
inputs:
8+
version:
9+
description: 'Version to publish (e.g. 1.2.0 or v1.2.0)'
10+
required: true
11+
type: string
612

713
# Least-privilege by default; the publish job opts into id-token below.
814
permissions:
@@ -48,16 +54,22 @@ jobs:
4854
- name: Ensure npm supports trusted publishing
4955
# Trusted publishing requires npm >= 11.5.1.
5056
run: npm install -g npm@latest
51-
- name: Verify release tag matches package.json version
52-
run: |
53-
PKG_VERSION="v$(node -p "require('./package.json').version")"
54-
TAG="${{ github.event.release.tag_name }}"
55-
if [ "$PKG_VERSION" != "$TAG" ]; then
56-
echo "::error::Release tag '$TAG' does not match package.json version '$PKG_VERSION'"
57-
exit 1
58-
fi
5957
- name: Install dependencies
6058
run: npm ci
59+
- name: Set version to publish
60+
# package.json ships a 0.0.0-development placeholder; the real version
61+
# comes from the manual input (workflow_dispatch) or the release tag,
62+
# with any leading "v" stripped (e.g. v1.2.0 -> 1.2.0).
63+
run: |
64+
VERSION="${INPUT_VERSION:-$TAG}"
65+
if [ -z "$VERSION" ]; then
66+
echo "::error::No version provided" && exit 1
67+
fi
68+
npm pkg set version="${VERSION#v}"
69+
echo "Publishing version ${VERSION#v}"
70+
env:
71+
INPUT_VERSION: ${{ github.event.inputs.version }}
72+
TAG: ${{ github.event.release.tag_name }}
6173
- name: Publish to npm
6274
# No NODE_AUTH_TOKEN: auth happens via OIDC, provenance is automatic.
6375
run: npm publish

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "lambda-api",
3-
"version": "1.2.0",
3+
"version": "0.0.0-development",
44
"description": "Lightweight web framework for your serverless applications",
55
"main": "index.js",
66
"types": "index.d.ts",

0 commit comments

Comments
 (0)