|
1 | 1 | name: JavaScript Client - Release |
2 | 2 |
|
3 | 3 | 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 |
6 | 18 |
|
7 | 19 | jobs: |
8 | | - build: |
| 20 | + release: |
9 | 21 | runs-on: ubuntu-latest |
| 22 | + environment: npm-publish |
10 | 23 | steps: |
11 | | - - uses: actions/checkout@v3 |
12 | | - - uses: actions/setup-node@v3 |
| 24 | + - name: Checkout repository |
| 25 | + uses: actions/checkout@v4 |
13 | 26 | with: |
14 | | - node-version: 18 |
15 | | - - run: npm ci |
16 | | - - run: npm test |
| 27 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 28 | + fetch-depth: 0 |
17 | 29 |
|
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 |
24 | 32 | with: |
25 | | - node-version: 18 |
| 33 | + node-version: 20 |
| 34 | + cache: npm |
26 | 35 | 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 |
29 | 111 | 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/** |
0 commit comments