Skip to content

Commit 314a4c5

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

File tree

12 files changed

+113
-3601
lines changed

12 files changed

+113
-3601
lines changed
Lines changed: 109 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,121 @@
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
618

719
jobs:
8-
build:
20+
release:
921
runs-on: ubuntu-latest
22+
environment: npm-publish
1023
steps:
11-
- uses: actions/checkout@v3
12-
- uses: actions/setup-node@v3
24+
- name: Checkout repository
25+
uses: actions/checkout@v4
1326
with:
14-
node-version: 18
15-
- run: npm ci
16-
- run: npm test
27+
token: ${{ secrets.GITHUB_TOKEN }}
28+
fetch-depth: 0
1729

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