-
Notifications
You must be signed in to change notification settings - Fork 1
123 lines (104 loc) · 4.89 KB
/
netlicensing-js-release.yml
File metadata and controls
123 lines (104 loc) · 4.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
name: JavaScript Client - Release
on:
workflow_dispatch:
inputs:
version:
description: 'Release version (e.g. 3.2.1) or bump type (patch, minor, major)'
required: true
default: 'patch'
release_notes:
description: 'Release notes — leave blank to auto-generate from commits/PRs'
required: false
type: string
permissions:
contents: write
packages: write
id-token: write
jobs:
release:
runs-on: ubuntu-latest
environment: npm-publish
steps:
- name: Checkout repository
uses: actions/checkout@v5
with:
token: ${{ secrets.GITHUB_TOKEN }}
fetch-depth: 0
- name: Setup Node.js
uses: actions/setup-node@v5
with:
node-version: 20
cache: npm
registry-url: https://registry.npmjs.org/
# ── Guards ──────────────────────────────────────────────────────────────
- name: Validate version input
run: |
INPUT="${{ inputs.version }}"
# Allow bump aliases OR strict semver (with optional pre-release label)
if echo "$INPUT" | grep -Pq '^(patch|minor|major)$'; then
echo "✅ Bump type: $INPUT"
elif echo "$INPUT" | grep -Pq '^\d+\.\d+\.\d+(-[\w.]+)?(\+[\w.]+)?$'; then
echo "✅ Explicit version: $INPUT"
else
echo "❌ '$INPUT' is neither a bump type (patch/minor/major) nor valid semver"
exit 1
fi
- name: Check version not already tagged
run: |
INPUT="${{ inputs.version }}"
# Only relevant for explicit versions — bump types resolve at npm version time
if echo "$INPUT" | grep -Pq '^\d+'; then
if git ls-remote --tags origin | grep -q "refs/tags/${INPUT}$"; then
echo "❌ Tag ${INPUT} already exists — bump the version or delete the tag first"
exit 1
fi
fi
# ── Install & Verify ────────────────────────────────────────────────────
- name: Install dependencies
run: npm ci
- name: Check outdated dependencies
run: npm outdated || true # Report only — never fail the release on this
- name: Run tests
run: npm run test
- name: Lint typecheck
run: npm run lint:typecheck
# ── Build ───────────────────────────────────────────────────────────────
- name: Build distribution
run: npm run build
# ── Git: commit dist before versioning ──────────────────────────────────
# Committing dist/ separately keeps git history readable:
# "chore: update build artifacts" ← dist changes
# "Release 3.2.1" ← version bump, this is what gets tagged
- name: Configure Git
run: |
git config user.name "${{ github.actor }}"
git config user.email "${{ github.actor }}@users.noreply.github.com"
- name: Commit build artifacts
run: |
git add .
git diff --quiet && git diff --staged --quiet \
|| git commit -m "Update build artifacts for ${{ inputs.version }}"
# ── Version bump, tag & push ────────────────────────────────────────────
- name: Bump version and tag
id: bump
run: |
# 1. Pass the empty prefix directly via CLI flag (bypasses the npm bug)
npm version ${{ inputs.version }} --tag-version-prefix="" -m "Release %s"
# 2. Extract the clean version directly from package.json
NEW_VERSION=$(node -p "require('./package.json').version")
# 3. Save it to outputs and push
echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT
git push --follow-tags
# ── Publish ─────────────────────────────────────────────────────────────
- name: Update npm
run: npm install -g npm@latest
- name: Publish to npm
run: npm publish --provenance --access public
- name: Create GitHub Release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ steps.bump.outputs.new_version }}
name: ${{ steps.bump.outputs.new_version }}
body: ${{ inputs.release_notes }}
generate_release_notes: ${{ inputs.release_notes == '' }}
files: dist/**