Skip to content

Commit c9a7a83

Browse files
authored
Enhance release workflow with manual trigger and inputs
Added workflow_dispatch event to allow manual triggering of the release process with version and release notes inputs. Updated various steps for improved version management and artifact handling.
1 parent 8d4f487 commit c9a7a83

File tree

1 file changed

+104
-18
lines changed

1 file changed

+104
-18
lines changed
Lines changed: 104 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,116 @@
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+
npm config set tag-version-prefix ''
99+
NEW_VERSION=$(npm version ${{ inputs.version }} -m "Release %s")
100+
echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT
101+
git push --follow-tags
102+
103+
# ── Publish ─────────────────────────────────────────────────────────────
104+
- name: Publish to npm
105+
run: npm publish
29106
env:
30-
NODE_AUTH_TOKEN: ${{secrets.npm_token}}
107+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
108+
109+
- name: Create GitHub Release
110+
uses: softprops/action-gh-release@v2
111+
with:
112+
tag_name: ${{ steps.bump.outputs.new_version }}
113+
name: Release ${{ steps.bump.outputs.new_version }}
114+
body: ${{ inputs.release_notes }}
115+
generate_release_notes: ${{ inputs.release_notes == '' }}
116+
files: dist/**

0 commit comments

Comments
 (0)