Skip to content

Commit 06107c7

Browse files
committed
Add version.yml workflow for on-click release
Added a new workflow file: version.yml. This workflow simply runs npm version with the desired values and pushes the commit and tag back to the repository. Along with release.yml, this functionally creates on-demand npm and github releases from the click of a button. This workflow requires a PAT in-place of the GITHUB_TOKEN, as the workflow default GITHUB_TOKEN will **not** trigger GitHub Actions.
1 parent a0ea293 commit 06107c7

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed

.github/workflows/version.yml

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
name: Push version
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
version:
7+
description: 'npm version semver level'
8+
required: true
9+
default: 'patch'
10+
type: choice
11+
options:
12+
- patch
13+
- minor
14+
- major
15+
- prerelease
16+
- prepatch
17+
- preminor
18+
- premajor
19+
preId:
20+
description: 'Prerelease identifier (required with pre-*)'
21+
required: false
22+
type: string
23+
24+
jobs:
25+
validate:
26+
name: Validate workflow inputs
27+
runs-on: ubuntu-latest
28+
29+
steps:
30+
- name: Invalid prerelease identifier
31+
if: ${{ startsWith(github.event.inputs.version, 'pre') && !github.event.inputs.preId }}
32+
run: |
33+
echo "Error: 'preId' input is required with 'pre-*' version."
34+
exit 1
35+
36+
version:
37+
name: Push ${{ inputs.version }} tag
38+
runs-on: ubuntu-latest
39+
40+
needs: [validate]
41+
42+
steps:
43+
- name: Checkout branch
44+
uses: actions/checkout@v4
45+
with:
46+
# see https://github.com/orgs/community/discussions/25617#discussioncomment-3248494
47+
token: ${{ secrets.RELEASE_TOKEN }}
48+
# requires contents: write permission for this repo
49+
# used by `git push` at the end
50+
- uses: actions/setup-node@v4
51+
with:
52+
node-version: 22.x
53+
- name: Configure git user
54+
# this step is necessary for `npm version` to succeed
55+
run: |
56+
git config --global user.name "${{ github.actor }}"
57+
git config --global user.email "${{ github.actor }}@users.noreply.github.com"
58+
- name: NPM version
59+
run: echo "version=$(npm version ${{ inputs.version }}${{ inputs.preId && format(' --preid {0}', inputs.preId) || '' }})" >> $GITHUB_ENV
60+
- name: Git push
61+
run: git push && git push origin ${{ env.version }}

0 commit comments

Comments
 (0)