Skip to content

Commit c8499df

Browse files
committed
chore: ci upgrades
1 parent b303a62 commit c8499df

2 files changed

Lines changed: 87 additions & 32 deletions

File tree

.github/workflows/publish.yaml

Lines changed: 7 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,26 @@
1-
name: Publish to NPM
1+
name: Publish NPM and Release
22

33
on:
4-
workflow_dispatch:
5-
inputs:
6-
semver:
7-
description: "The semantic version to bump"
8-
required: true
9-
type: choice
10-
options:
11-
- patch
12-
- minor
13-
- major
14-
default: "patch"
15-
nodeVersion:
16-
description: "The Node.js version to use"
17-
required: true
18-
type: choice
19-
options:
20-
- "18.x"
21-
- "20.x"
22-
- "22.x"
23-
default: "18.x"
4+
push:
5+
tags:
6+
- 'v*.*.*'
247

258
jobs:
269
release:
2710
permissions:
28-
contents: write
2911
id-token: write
12+
contents: write
3013

31-
# Use the semver as the job name
32-
name: "Release ${{ github.event.inputs.semver }}"
14+
name: Publish release ${{ github.ref_name }}
3315
runs-on: ubuntu-latest
3416
steps:
3517
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
3618

3719
- uses: actions/setup-node@3235b876344d2a9aa001b8d1453c930bba69e610
3820
with:
39-
node-version: ${{ github.event.inputs.nodeVersion }}
21+
node-version: 22
4022
registry-url: "https://registry.npmjs.org"
4123

42-
- name: Bump and commit version
43-
run: |
44-
git config --global user.email "github-actions[bot]@github.com"
45-
git config --global user.name "github-actions[bot]"
46-
npm version ${{ github.event.inputs.semver }} --message "chore(release): bump version to %s"
47-
git push --follow-tags
48-
4924
- name: Publish
5025
run: npm publish
5126

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
name: Update Version
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
semver:
7+
description: "The semantic version to bump"
8+
required: true
9+
type: choice
10+
options:
11+
- patch
12+
- minor
13+
- major
14+
default: "patch"
15+
nodeVersion:
16+
description: "The Node.js version to use"
17+
required: true
18+
type: choice
19+
options:
20+
- "18.x"
21+
- "20.x"
22+
- "22.x"
23+
default: "18.x"
24+
25+
jobs:
26+
release:
27+
permissions:
28+
contents: write
29+
30+
name: Update and publish version ${{ github.event.inputs.semver }}
31+
runs-on: ubuntu-latest
32+
steps:
33+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
34+
with:
35+
fetch-depth: 0
36+
persist-credentials: true
37+
38+
- uses: actions/setup-node@3235b876344d2a9aa001b8d1453c930bba69e610
39+
with:
40+
node-version: ${{ github.event.inputs.nodeVersion }}
41+
registry-url: "https://registry.npmjs.org"
42+
43+
- name: Create release branch, bump version and push
44+
env:
45+
SEMVER: ${{ github.event.inputs.semver }}
46+
run: |
47+
set -euo pipefail
48+
git config --global user.email "github-actions[bot]@github.com"
49+
git config --global user.name "github-actions[bot]"
50+
51+
# Create a unique release branch so the bump commit and tag are isolated
52+
BRANCH="release-${SEMVER}-$(date +%s)"
53+
git checkout -b "$BRANCH"
54+
55+
# Bump version (creates commit and tag)
56+
npm version "$SEMVER" --message "chore(release): bump version to %s"
57+
58+
# Push the new branch (do not push tags here; tags are created but will be managed on merge/release)
59+
git push --set-upstream origin "$BRANCH"
60+
61+
# Read the new version for PR title/body and persist values for next step
62+
VERSION=$(node -p "require('./package.json').version")
63+
echo "BRANCH=$BRANCH" >> $GITHUB_ENV
64+
echo "VERSION=$VERSION" >> $GITHUB_ENV
65+
66+
- name: Create PR with gh
67+
env:
68+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
69+
GITHUB_REPOSITORY: ${{ github.repository }}
70+
SEMVER: ${{ github.event.inputs.semver }}
71+
run: |
72+
set -euo pipefail
73+
PR_TITLE="chore(release): bump version to ${VERSION}"
74+
PR_BODY="Automated version bump to ${VERSION} (triggered by workflow_dispatch)."
75+
76+
# Write body to a temp file to preserve newlines
77+
printf "%s\n\nSemantic bump: %s\n" "$PR_BODY" "$SEMVER" > /tmp/pr_body.md
78+
79+
echo "Creating PR: ${PR_TITLE} from ${BRANCH} into master"
80+
gh pr create --title "$PR_TITLE" --body-file /tmp/pr_body.md --base master --head "$BRANCH" --repo "$GITHUB_REPOSITORY"

0 commit comments

Comments
 (0)