-
Notifications
You must be signed in to change notification settings - Fork 2
118 lines (97 loc) · 3.71 KB
/
auto-release.yml
File metadata and controls
118 lines (97 loc) · 3.71 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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
name: Auto Release
on:
push:
branches:
- main
concurrency:
group: release
jobs:
publish:
if: github.actor != 'weka-version-bumper[bot]'
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/create-github-app-token@v1
id: app-token
with:
app-id: 919414
private-key: ${{ secrets.WEKA_VERSION_BUMPER_PRIVATE_KEY }}
- uses: actions/checkout@v4
with:
token: ${{ steps.app-token.outputs.token }}
ref: main
fetch-depth: 0
- uses: actions/setup-node@v4
with:
node-version: '20'
- run: |
git config --global user.name 'github-actions'
git config --global user.email 'github-actions@users.noreply.github.com'
- run: git checkout main
- name: Find latest stable v-prefixed tag
id: latest_tag
run: |
LATEST_TAG=$(git tag -l 'v[0-9]*.[0-9]*.[0-9]*' --sort=-v:refname | grep -v -e '-beta' -e '-alpha' -e '-rc' | head -1)
if [ -z "$LATEST_TAG" ]; then
echo "No stable v-prefixed tag found. Exiting gracefully."
echo "found=false" >> $GITHUB_OUTPUT
exit 0
fi
echo "Latest stable tag: $LATEST_TAG"
echo "found=true" >> $GITHUB_OUTPUT
echo "tag=$LATEST_TAG" >> $GITHUB_OUTPUT
- name: Determine bump type from PR labels
if: steps.latest_tag.outputs.found == 'true'
id: bump
env:
GH_TOKEN: ${{ steps.app-token.outputs.token }}
run: |
# Find the merged PR for this commit
COMMIT_SHA="${{ github.sha }}"
PR_NUMBER=$(gh pr list --search "$COMMIT_SHA" --state merged --json number --jq '.[0].number')
if [ -z "$PR_NUMBER" ]; then
echo "No merged PR found for commit $COMMIT_SHA. Defaulting to minor bump."
echo "type=minor" >> $GITHUB_OUTPUT
exit 0
fi
echo "Found merged PR #$PR_NUMBER"
# Check for patch label
HAS_PATCH=$(gh pr view "$PR_NUMBER" --json labels --jq '.labels[].name' | grep -c '^patch$' || true)
if [ "$HAS_PATCH" -gt 0 ]; then
echo "PR has 'patch' label → patch bump"
echo "type=patch" >> $GITHUB_OUTPUT
else
echo "No 'patch' label → minor bump"
echo "type=minor" >> $GITHUB_OUTPUT
fi
- name: Compute next version
if: steps.latest_tag.outputs.found == 'true'
id: next_version
run: |
LATEST_TAG="${{ steps.latest_tag.outputs.tag }}"
BUMP_TYPE="${{ steps.bump.outputs.type }}"
# Strip v prefix
VERSION="${LATEST_TAG#v}"
IFS='.' read -r MAJOR MINOR PATCH <<< "$VERSION"
if [ "$BUMP_TYPE" = "patch" ]; then
NEW_VERSION="$MAJOR.$MINOR.$((PATCH + 1))"
else
NEW_VERSION="$MAJOR.$((MINOR + 1)).0"
fi
echo "Bumping $BUMP_TYPE: $VERSION → $NEW_VERSION"
echo "version=$NEW_VERSION" >> $GITHUB_OUTPUT
- name: Update package.json version
if: steps.latest_tag.outputs.found == 'true'
run: npm version ${{ steps.next_version.outputs.version }} --no-git-tag-version --allow-same-version
- name: Commit and tag
if: steps.latest_tag.outputs.found == 'true'
run: |
git add package.json
git commit -m 'publish v${{ steps.next_version.outputs.version }}'
git tag 'v${{ steps.next_version.outputs.version }}'
- name: Push commit and tag
if: steps.latest_tag.outputs.found == 'true'
run: |
git push origin main
git push origin tag 'v${{ steps.next_version.outputs.version }}'