Skip to content

Commit 40f5a93

Browse files
committed
ci: make release workflow more flexible
1 parent 2f3ebb2 commit 40f5a93

File tree

1 file changed

+26
-37
lines changed

1 file changed

+26
-37
lines changed

.github/workflows/release.yaml

Lines changed: 26 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -3,38 +3,42 @@ name: Release
33
on:
44
workflow_dispatch:
55
inputs:
6-
bump:
6+
version:
7+
description: 'Bump version (e.g., 4.0.0, 4.1.0-alpha.1, 5.0.0-beta.2)'
78
required: true
8-
type: choice
9-
options:
10-
- next
11-
- patch
12-
- minor
13-
- major
14-
- prepatch
15-
- preminor
16-
- premajor
17-
18-
preid:
19-
type: choice
20-
required: true
21-
default: beta
22-
options:
23-
- alpha
24-
- beta
25-
- canary
9+
type: string
2610

2711
concurrency:
2812
group: ${{ github.workflow }}-${{ github.ref }}
2913
cancel-in-progress: false
3014

3115
jobs:
32-
publish:
16+
release:
3317
runs-on: ubuntu-latest
3418
permissions:
3519
contents: write
3620
id-token: write
3721
steps:
22+
- id: version
23+
run: |
24+
VERSION="${{ github.event.inputs.version }}"
25+
26+
if [[ $VERSION =~ ^(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)(-([a-z]+)\.([1-9][0-9]*))?$ ]]; then
27+
if [[ "${BASH_REMATCH[5]}" == "latest" ]]; then
28+
echo "INVALID VERSION FORMAT ('latest' is not allowed): $VERSION" >&2
29+
exit 1
30+
fi
31+
32+
echo "major=${BASH_REMATCH[1]}" >> $GITHUB_OUTPUT
33+
echo "minor=${BASH_REMATCH[2]}" >> $GITHUB_OUTPUT
34+
echo "patch=${BASH_REMATCH[3]}" >> $GITHUB_OUTPUT
35+
echo "preid=${BASH_REMATCH[5]}" >> $GITHUB_OUTPUT
36+
echo "number=${BASH_REMATCH[6]}" >> $GITHUB_OUTPUT
37+
else
38+
echo "INVALID VERSION FORMAT: $VERSION" >&2
39+
exit 1
40+
fi
41+
3842
- uses: actions/checkout@v4
3943
with:
4044
fetch-depth: 0
@@ -47,28 +51,13 @@ jobs:
4751
git config --global user.name "github-actions[bot]"
4852
git config --global user.email "github-actions[bot]@users.noreply.github.com"
4953
50-
- run: pnpm run packages:bump ${{ github.event.inputs.bump }} --yes --preid ${{ github.event.inputs.preid }}
51-
52-
- id: package-version
53-
uses: martinbeentjes/npm-get-version-action@v1.3.1
54-
with:
55-
path: packages/server
56-
57-
- id: prerelease-tag
58-
run: |
59-
VERSION=${{ steps.package-version.outputs.current-version }}
60-
61-
if [[ $VERSION =~ ^[0-9\.]+(-([0-9A-Za-z-]+).*)?$ ]]; then
62-
echo "tag=${BASH_REMATCH[2]}"
63-
else
64-
echo "tag=unknown"
65-
fi
54+
- run: pnpm run packages:bump ${{ github.event.inputs.version }} --yes --preid=${{ steps.version.outputs.preid }}
6655

6756
- run: pnpm config set '//registry.npmjs.org/:_authToken' "${NPM_TOKEN}"
6857
env:
6958
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
7059

71-
- run: pnpm run packages:publish --tag="${{ steps.prerelease-tag.outputs.tag || 'latest' }}"
60+
- run: pnpm run packages:publish --tag="${{ steps.version.outputs.preid || 'latest' }}"
7261
env:
7362
NPM_CONFIG_PROVENANCE: true
7463

0 commit comments

Comments
 (0)