-
Notifications
You must be signed in to change notification settings - Fork 162
83 lines (72 loc) · 2.69 KB
/
update-version.yaml
File metadata and controls
83 lines (72 loc) · 2.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
name: Update Version
on:
workflow_dispatch:
inputs:
semver:
description: "The semantic version to bump"
required: true
type: choice
options:
- patch
- minor
- major
default: "patch"
nodeVersion:
description: "The Node.js version to use"
required: true
type: choice
options:
- "18.x"
- "20.x"
- "22.x"
default: "18.x"
jobs:
release:
permissions:
contents: write
pull-requests: read
name: Update and publish version ${{ github.event.inputs.semver }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
with:
fetch-depth: 0
persist-credentials: true
- uses: actions/setup-node@3235b876344d2a9aa001b8d1453c930bba69e610
with:
node-version: ${{ github.event.inputs.nodeVersion }}
registry-url: "https://registry.npmjs.org"
- name: Create release branch, bump version and push
env:
SEMVER: ${{ github.event.inputs.semver }}
run: |
set -euo pipefail
git config --global user.email "github-actions[bot]@github.com"
git config --global user.name "github-actions[bot]"
# Create a unique release branch so the bump commit and tag are isolated
BRANCH="release-${SEMVER}-$(date +%s)"
git checkout -b "$BRANCH"
# Bump version but do NOT create a git tag on the branch
npm version "$SEMVER" --no-git-tag-version --allow-same-version --message "chore(release): bump version to %s"
# Commit package.json and package-lock.json (if present) and push branch
git add package.json package-lock.json || true
git commit -m "chore(release): bump version" || true
git push --set-upstream origin "$BRANCH"
# Read the new version for PR title/body and persist values for next step
VERSION=$(node -p "require('./package.json').version")
echo "BRANCH=$BRANCH" >> $GITHUB_ENV
echo "VERSION=$VERSION" >> $GITHUB_ENV
- name: Provide PR creation link
env:
GITHUB_REPOSITORY: ${{ github.repository }}
run: |
set -euo pipefail
PR_LINK="https://github.com/${GITHUB_REPOSITORY}/compare/master...${BRANCH}?expand=1"
echo "Open this URL to create the PR: ${PR_LINK}"
{
echo "## Version bump branch created";
echo "Branch: ${BRANCH}";
echo "Version: ${VERSION}";
echo "";
echo "[Create the pull request now](${PR_LINK})";
} >> "$GITHUB_STEP_SUMMARY"