Skip to content

Commit b835e48

Browse files
DhruvBhatia0claude
andcommitted
ci: use OIDC trusted publishing with auto version bump
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 8c92f8e commit b835e48

1 file changed

Lines changed: 38 additions & 21 deletions

File tree

.github/workflows/release.yml

Lines changed: 38 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,17 @@ name: Release
33
on:
44
push:
55
branches: [main]
6+
workflow_dispatch:
7+
inputs:
8+
version_bump:
9+
description: 'Version bump type'
10+
required: true
11+
default: 'patch'
12+
type: choice
13+
options:
14+
- patch
15+
- minor
16+
- major
617

718
jobs:
819
publish:
@@ -14,6 +25,9 @@ jobs:
1425

1526
steps:
1627
- uses: actions/checkout@v4
28+
with:
29+
fetch-depth: 0
30+
token: ${{ secrets.GITHUB_TOKEN }}
1731

1832
- uses: oven-sh/setup-bun@v2
1933
with:
@@ -24,6 +38,10 @@ jobs:
2438
node-version: '20'
2539
registry-url: 'https://registry.npmjs.org'
2640

41+
# npm 11.5.1+ required for Trusted Publishing
42+
- name: Update npm to latest
43+
run: npm install -g npm@latest
44+
2745
- name: Install dependencies
2846
run: bun install
2947

@@ -36,37 +54,36 @@ jobs:
3654
- name: Build
3755
run: bun run build
3856

39-
- name: Check if version changed
57+
- name: Bump version
4058
id: version
4159
run: |
42-
LOCAL=$(node -p "require('./package.json').version")
43-
REMOTE=$(npm view @morphllm/opencode-morph-plugin version 2>/dev/null || echo "0.0.0")
44-
echo "local=$LOCAL" >> "$GITHUB_OUTPUT"
45-
echo "remote=$REMOTE" >> "$GITHUB_OUTPUT"
46-
if [ "$LOCAL" != "$REMOTE" ]; then
47-
echo "changed=true" >> "$GITHUB_OUTPUT"
48-
else
49-
echo "changed=false" >> "$GITHUB_OUTPUT"
50-
fi
60+
git config --global user.name "github-actions[bot]"
61+
git config --global user.email "github-actions[bot]@users.noreply.github.com"
62+
63+
git pull --rebase origin main
5164
65+
BUMP_TYPE="${{ github.event.inputs.version_bump || 'patch' }}"
66+
npm version $BUMP_TYPE --no-git-tag-version
67+
NEW_VERSION=$(node -p "require('./package.json').version")
68+
echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT
69+
70+
git add package.json
71+
git commit -m "chore: bump to $NEW_VERSION [skip ci]"
72+
git tag -f "v$NEW_VERSION"
73+
git push origin main --tags --force
74+
75+
# Trusted Publishing: No NODE_AUTH_TOKEN needed!
76+
# npm CLI auto-detects OIDC and handles auth via id-token permission
5277
- name: Publish to npm
53-
if: steps.version.outputs.changed == 'true'
5478
run: npm publish --access public
55-
env:
56-
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
5779

5880
- name: Create GitHub Release
59-
if: steps.version.outputs.changed == 'true'
6081
run: |
61-
VERSION="v${{ steps.version.outputs.local }}"
62-
NOTES=$(awk "/^## \[${VERSION#v}\]/{flag=1; next} /^## \[/{flag=0} flag" CHANGELOG.md)
63-
NOTES_FILE="${RUNNER_TEMP}/release-notes.md"
64-
echo "$NOTES" > "$NOTES_FILE"
65-
82+
VERSION="v${{ steps.version.outputs.new_version }}"
6683
if gh release view "$VERSION" >/dev/null 2>&1; then
67-
gh release edit "$VERSION" --title "$VERSION" --notes-file "$NOTES_FILE"
84+
gh release edit "$VERSION" --title "$VERSION" --notes "Published @morphllm/opencode-morph-plugin@${{ steps.version.outputs.new_version }}"
6885
else
69-
gh release create "$VERSION" --title "$VERSION" --notes-file "$NOTES_FILE"
86+
gh release create "$VERSION" --title "$VERSION" --notes "Published @morphllm/opencode-morph-plugin@${{ steps.version.outputs.new_version }}"
7087
fi
7188
env:
7289
GH_TOKEN: ${{ github.token }}

0 commit comments

Comments
 (0)