-
Notifications
You must be signed in to change notification settings - Fork 0
96 lines (80 loc) · 3.03 KB
/
version.yml
File metadata and controls
96 lines (80 loc) · 3.03 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
84
85
86
87
88
89
90
91
92
93
94
95
96
name: Version Bump
on:
schedule:
- cron: '0 0 * * *'
workflow_dispatch:
permissions:
contents: write
pull-requests: write
jobs:
version:
# Skip version-bump merges to avoid infinite loops
if: github.actor != 'github-actions[bot]'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
ref: main
fetch-depth: 0
- uses: actions/setup-node@v4
with:
node-version: 22
- run: npm ci
- name: Determine next version
id: next
run: |
CURRENT=$(node -p "require('./package.json').version")
echo "current=$CURRENT"
# Run semantic-release dry-run and capture output
OUTPUT=$(npx semantic-release --dry-run 2>&1) || true
echo "$OUTPUT"
# Extract the next version from dry-run output
# semantic-release prints lines like:
# "The next release version is X.Y.Z"
# "Published release X.Y.Z"
NEXT=$(echo "$OUTPUT" | grep -oP '(?:next release version is |Published release )\K[0-9]+\.[0-9]+\.[0-9]+' | head -1 || true)
if [ -z "$NEXT" ] || [ "$NEXT" = "$CURRENT" ]; then
echo "No version bump needed"
echo "bump=false" >> "$GITHUB_OUTPUT"
else
echo "Version bump: $CURRENT -> $NEXT"
echo "bump=true" >> "$GITHUB_OUTPUT"
echo "next=$NEXT" >> "$GITHUB_OUTPUT"
fi
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Check for existing PR
if: steps.next.outputs.bump == 'true'
id: existing
run: |
BRANCH="release/v${{ steps.next.outputs.next }}"
PR=$(gh pr list --head "$BRANCH" --state open --json number --jq '.[0].number' || true)
if [ -n "$PR" ]; then
echo "PR #$PR already exists for $BRANCH"
echo "exists=true" >> "$GITHUB_OUTPUT"
else
echo "exists=false" >> "$GITHUB_OUTPUT"
fi
env:
GH_TOKEN: ${{ github.token }}
- name: Create version bump PR
if: steps.next.outputs.bump == 'true' && steps.existing.outputs.exists != 'true'
run: |
VERSION="${{ steps.next.outputs.next }}"
BRANCH="release/v${VERSION}"
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git checkout -b "$BRANCH"
npm version "$VERSION" --no-git-tag-version
npm install --package-lock-only
git add package.json package-lock.json
git commit -m "chore(release): bump version to ${VERSION}"
git pull --rebase origin "$BRANCH" || true
git push origin "$BRANCH"
gh pr create \
--title "chore(release): v${VERSION}" \
--body "Automated version bump to \`${VERSION}\` based on conventional commits since the last release." \
--base main \
--head "$BRANCH"
env:
GH_TOKEN: ${{ github.token }}