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