Skip to content

Commit ab0c518

Browse files
committed
Enhance release workflow with manual trigger and inputs
1 parent d768cc6 commit ab0c518

File tree

11 files changed

+111
-3600
lines changed

11 files changed

+111
-3600
lines changed
Lines changed: 109 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,120 @@
11
name: JavaScript Client - Release
22

33
on:
4-
release:
5-
types: [created]
4+
workflow_dispatch:
5+
inputs:
6+
version:
7+
description: 'Release version (e.g. 3.2.1) or bump type (patch, minor, major)'
8+
required: true
9+
default: 'patch'
10+
release_notes:
11+
description: 'Release notes — leave blank to auto-generate from commits/PRs'
12+
required: false
13+
type: string
14+
15+
permissions:
16+
contents: write
17+
packages: write
18+
id-token: write
619

720
jobs:
8-
build:
21+
release:
922
runs-on: ubuntu-latest
23+
environment: npm-publish
1024
steps:
11-
- uses: actions/checkout@v3
12-
- uses: actions/setup-node@v3
25+
- name: Checkout repository
26+
uses: actions/checkout@v4
1327
with:
14-
node-version: 18
15-
- run: npm ci
16-
- run: npm test
28+
token: ${{ secrets.GITHUB_TOKEN }}
29+
fetch-depth: 0
1730

18-
publish-npm:
19-
needs: build
20-
runs-on: ubuntu-latest
21-
steps:
22-
- uses: actions/checkout@v3
23-
- uses: actions/setup-node@v3
31+
- name: Setup Node.js
32+
uses: actions/setup-node@v4
2433
with:
25-
node-version: 18
34+
node-version: 20
35+
cache: npm
2636
registry-url: https://registry.npmjs.org/
27-
- run: npm ci
28-
- run: npm publish
29-
env:
30-
NODE_AUTH_TOKEN: ${{secrets.npm_token}}
37+
38+
# ── Guards ──────────────────────────────────────────────────────────────
39+
- name: Validate version input
40+
run: |
41+
INPUT="${{ inputs.version }}"
42+
# Allow bump aliases OR strict semver (with optional pre-release label)
43+
if echo "$INPUT" | grep -Pq '^(patch|minor|major)$'; then
44+
echo "✅ Bump type: $INPUT"
45+
elif echo "$INPUT" | grep -Pq '^\d+\.\d+\.\d+(-[\w.]+)?(\+[\w.]+)?$'; then
46+
echo "✅ Explicit version: $INPUT"
47+
else
48+
echo "❌ '$INPUT' is neither a bump type (patch/minor/major) nor valid semver"
49+
exit 1
50+
fi
51+
52+
- name: Check version not already tagged
53+
run: |
54+
INPUT="${{ inputs.version }}"
55+
# Only relevant for explicit versions — bump types resolve at npm version time
56+
if echo "$INPUT" | grep -Pq '^\d+'; then
57+
if git ls-remote --tags origin | grep -q "refs/tags/${INPUT}$"; then
58+
echo "❌ Tag ${INPUT} already exists — bump the version or delete the tag first"
59+
exit 1
60+
fi
61+
fi
62+
63+
# ── Install & Verify ────────────────────────────────────────────────────
64+
- name: Install dependencies
65+
run: npm ci
66+
67+
- name: Check outdated dependencies
68+
run: npm outdated || true # Report only — never fail the release on this
69+
70+
- name: Run tests
71+
run: npm run test
72+
73+
- name: Lint typecheck
74+
run: npm run lint:typecheck
75+
76+
# ── Build ───────────────────────────────────────────────────────────────
77+
- name: Build distribution
78+
run: npm run build
79+
80+
# ── Git: commit dist before versioning ──────────────────────────────────
81+
# Committing dist/ separately keeps git history readable:
82+
# "chore: update build artifacts" ← dist changes
83+
# "Release 3.2.1" ← version bump, this is what gets tagged
84+
- name: Configure Git
85+
run: |
86+
git config user.name "${{ github.actor }}"
87+
git config user.email "${{ github.actor }}@users.noreply.github.com"
88+
89+
- name: Commit build artifacts
90+
run: |
91+
git add .
92+
git diff --quiet && git diff --staged --quiet \
93+
|| git commit -m "Update build artifacts for ${{ inputs.version }}"
94+
95+
# ── Version bump, tag & push ────────────────────────────────────────────
96+
- name: Bump version and tag
97+
id: bump
98+
run: |
99+
# 1. Pass the empty prefix directly via CLI flag (bypasses the npm bug)
100+
npm version ${{ inputs.version }} --tag-version-prefix="" -m "Release %s"
101+
102+
# 2. Extract the clean version directly from package.json
103+
NEW_VERSION=$(node -p "require('./package.json').version")
104+
105+
# 3. Save it to outputs and push
106+
echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT
107+
git push --follow-tags
108+
109+
# ── Publish ─────────────────────────────────────────────────────────────
110+
- name: Publish to npm
111+
run: npm publish --provenance --access public
112+
113+
- name: Create GitHub Release
114+
uses: softprops/action-gh-release@v2
115+
with:
116+
tag_name: ${{ steps.bump.outputs.new_version }}
117+
name: Release ${{ steps.bump.outputs.new_version }}
118+
body: ${{ inputs.release_notes }}
119+
generate_release_notes: ${{ inputs.release_notes == '' }}
120+
files: dist/**

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ npm-debug.log
44
.build*
55
.idea
66
index.html
7+
dist/

0 commit comments

Comments
 (0)