Skip to content

Commit a242e91

Browse files
committed
chore: update deploy script
1 parent 30a8f5f commit a242e91

File tree

1 file changed

+85
-47
lines changed

1 file changed

+85
-47
lines changed

.github/workflows/release.yml

Lines changed: 85 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,84 +1,122 @@
11
name: Release NPM Package
22

33
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
722

823
permissions:
924
contents: write
10-
pull-requests: write
1125
id-token: write
1226

1327
jobs:
1428
release:
1529
runs-on: ubuntu-latest
16-
if: startsWith(github.event.head_commit.message, 'chore(release):')
1730
steps:
1831
- uses: actions/checkout@v4
1932
with:
33+
ref: ${{ github.event.inputs.ref || github.ref }}
2034
fetch-depth: 0
2135

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
4237
uses: actions/setup-node@v4
43-
if: steps.version.outputs.version != ''
4438
with:
4539
registry-url: https://registry.npmjs.org/
4640
node-version: 22
4741

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+
4847
- name: Setup Bun
49-
uses: oven-sh/setup-bun@v1
50-
if: steps.version.outputs.version != ''
48+
uses: oven-sh/setup-bun@v2
5149
with:
5250
bun-version: latest
5351

5452
- name: Install dependencies
55-
if: steps.version.outputs.version != ''
5653
run: bun install
5754

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+
5880
- name: Create GitHub Release
59-
if: steps.version.outputs.version != ''
81+
if: ${{ !inputs.skip-github-release }}
6082
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
6490
else
65-
echo "Release v${{ steps.version.outputs.version }} already exists, skipping creation"
91+
echo "Release v${{ steps.bump.outputs.version }} already exists, skipping"
6692
fi
6793
env:
6894
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
6995

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
75101
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"
84119
fi
120+
npm publish "${TARBALL}" --access public --tag "${TAG}"
121+
rm -f *.tgz README.md
122+
echo "--- Published ${PKG_NAME}@${VERSION} ---"

0 commit comments

Comments
 (0)