|
1 | 1 | name: Release NPM Package |
2 | 2 |
|
3 | 3 | on: |
4 | | - push: |
5 | | - branches: |
6 | | - - main |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + bump: |
| 7 | + description: "Bump type" |
| 8 | + required: true |
| 9 | + type: choice |
| 10 | + options: |
| 11 | + - patch |
| 12 | + - minor |
| 13 | + version-override: |
| 14 | + description: "Exact version override (e.g. 0.89.0). Leave empty to use bump type." |
| 15 | + required: false |
| 16 | + type: string |
| 17 | + skip-github-release: |
| 18 | + description: "Skip creating git tag and GitHub release" |
| 19 | + required: false |
| 20 | + type: boolean |
| 21 | + default: false |
7 | 22 |
|
8 | 23 | permissions: |
9 | 24 | contents: write |
10 | | - pull-requests: write |
11 | 25 | id-token: write |
12 | 26 |
|
13 | 27 | jobs: |
14 | 28 | release: |
15 | 29 | runs-on: ubuntu-latest |
16 | | - if: startsWith(github.event.head_commit.message, 'chore(release):') |
17 | 30 | steps: |
18 | 31 | - uses: actions/checkout@v4 |
19 | 32 | with: |
| 33 | + ref: ${{ github.event.inputs.ref || github.ref }} |
20 | 34 | fetch-depth: 0 |
21 | 35 |
|
22 | | - - name: Extract version from commit message |
23 | | - id: version |
24 | | - run: | |
25 | | - VERSION=$(echo "${{ github.event.head_commit.message }}" | sed -E 's/^chore\(release\): //') |
26 | | - echo "version=$VERSION" >> $GITHUB_OUTPUT |
27 | | -
|
28 | | - - name: Create and push tag |
29 | | - if: steps.version.outputs.version != '' |
30 | | - run: | |
31 | | - git config --local user.email "github-actions[bot]@users.noreply.github.com" |
32 | | - git config --local user.name "github-actions[bot]" |
33 | | - # Check if tag exists before creating |
34 | | - if ! git rev-parse "v${{ steps.version.outputs.version }}" >/dev/null 2>&1; then |
35 | | - git tag -a "v${{ steps.version.outputs.version }}" -m "Release v${{ steps.version.outputs.version }}" |
36 | | - git push --tags |
37 | | - else |
38 | | - echo "Tag v${{ steps.version.outputs.version }} already exists, skipping creation" |
39 | | - fi |
40 | | -
|
41 | | - - name: Set node |
| 36 | + - name: Setup Node |
42 | 37 | uses: actions/setup-node@v4 |
43 | | - if: steps.version.outputs.version != '' |
44 | 38 | with: |
45 | 39 | registry-url: https://registry.npmjs.org/ |
46 | 40 | node-version: 22 |
47 | 41 |
|
| 42 | + - name: Upgrade npm for OIDC trusted publishing |
| 43 | + run: | |
| 44 | + npm install -g npm@latest && npm --version |
| 45 | + sed -i '/always-auth/d' ~/.npmrc 2>/dev/null || true |
| 46 | +
|
48 | 47 | - name: Setup Bun |
49 | | - uses: oven-sh/setup-bun@v1 |
50 | | - if: steps.version.outputs.version != '' |
| 48 | + uses: oven-sh/setup-bun@v2 |
51 | 49 | with: |
52 | 50 | bun-version: latest |
53 | 51 |
|
54 | 52 | - name: Install dependencies |
55 | | - if: steps.version.outputs.version != '' |
56 | 53 | run: bun install |
57 | 54 |
|
| 55 | + - name: Bump version |
| 56 | + id: bump |
| 57 | + run: | |
| 58 | + if [ -n "${{ inputs.version-override }}" ]; then |
| 59 | + bun ./scripts/bump.ts "${{ inputs.version-override }}" |
| 60 | + VERSION="${{ inputs.version-override }}" |
| 61 | + else |
| 62 | + bun ./scripts/bump.ts "${{ inputs.bump }}" |
| 63 | + VERSION=$(node -p "require('./alchemy/package.json').version") |
| 64 | + fi |
| 65 | + echo "version=$VERSION" >> $GITHUB_OUTPUT |
| 66 | +
|
| 67 | + - name: Push version commit |
| 68 | + run: git push |
| 69 | + |
| 70 | + - name: Capture commit SHA |
| 71 | + id: sha |
| 72 | + run: echo "sha=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT |
| 73 | + |
| 74 | + - name: Create and push tag |
| 75 | + if: ${{ !inputs.skip-github-release }} |
| 76 | + run: | |
| 77 | + git tag -a "v${{ steps.bump.outputs.version }}" -m "Release v${{ steps.bump.outputs.version }}" |
| 78 | + git push --tags |
| 79 | +
|
58 | 80 | - name: Create GitHub Release |
59 | | - if: steps.version.outputs.version != '' |
| 81 | + if: ${{ !inputs.skip-github-release }} |
60 | 82 | run: | |
61 | | - # Check if release exists before creating |
62 | | - if ! gh release view "v${{ steps.version.outputs.version }}" >/dev/null 2>&1; then |
63 | | - bunx changelogithub |
| 83 | + if ! gh release view "v${{ steps.bump.outputs.version }}" >/dev/null 2>&1; then |
| 84 | + PREV_TAG=$(git describe --tags --abbrev=0 HEAD~1 2>/dev/null || echo "") |
| 85 | + if [ -n "$PREV_TAG" ]; then |
| 86 | + bunx changelogithub --from "$PREV_TAG" |
| 87 | + else |
| 88 | + bunx changelogithub --from "v${{ steps.bump.outputs.version }}" |
| 89 | + fi |
64 | 90 | else |
65 | | - echo "Release v${{ steps.version.outputs.version }} already exists, skipping creation" |
| 91 | + echo "Release v${{ steps.bump.outputs.version }} already exists, skipping" |
66 | 92 | fi |
67 | 93 | env: |
68 | 94 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
69 | 95 |
|
70 | | - - name: Create NPM Release |
71 | | - if: steps.version.outputs.version != '' |
72 | | - env: |
73 | | - NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |
74 | | - NPM_CONFIG_PROVENANCE: true |
| 96 | + - name: Build |
| 97 | + run: bun run build |
| 98 | + working-directory: alchemy |
| 99 | + |
| 100 | + - name: Publish to NPM |
75 | 101 | run: | |
76 | | - # Configure npm token for both npm and bun |
77 | | - npm config set '//registry.npmjs.org/:_authToken' "${NODE_AUTH_TOKEN}" |
78 | | - if ! npm view "alchemy@${{ steps.version.outputs.version }}" version >/dev/null 2>&1; then |
79 | | - # Bun respects NPM_CONFIG_TOKEN for auth; also pass provenance |
80 | | - export NPM_CONFIG_TOKEN="${NODE_AUTH_TOKEN}" |
81 | | - bun run publish:npm |
82 | | - else |
83 | | - echo "Version ${{ steps.version.outputs.version }} already published to npm, skipping publish" |
| 102 | + VERSION="${{ steps.bump.outputs.version }}" |
| 103 | + PKG_NAME=$(node -p "require('./alchemy/package.json').name") |
| 104 | + echo "--- Publishing ${PKG_NAME}@${VERSION} ---" |
| 105 | +
|
| 106 | + if npm view "${PKG_NAME}@${VERSION}" version >/dev/null 2>&1; then |
| 107 | + echo "${PKG_NAME}@${VERSION} already published, skipping" |
| 108 | + exit 0 |
| 109 | + fi |
| 110 | +
|
| 111 | + cd alchemy |
| 112 | + cp ../README.md . |
| 113 | + bun pm pack --destination . |
| 114 | + TARBALL=$(ls *.tgz 2>/dev/null | head -1) |
| 115 | + echo "Publishing tarball: ${TARBALL}" |
| 116 | + TAG="latest" |
| 117 | + if echo "${VERSION}" | grep -q '-'; then |
| 118 | + TAG="next" |
84 | 119 | fi |
| 120 | + npm publish "${TARBALL}" --access public --tag "${TAG}" |
| 121 | + rm -f *.tgz README.md |
| 122 | + echo "--- Published ${PKG_NAME}@${VERSION} ---" |
0 commit comments