Skip to content

Commit bb0a705

Browse files
authored
Merge pull request #3 from llbbl/ci/auto-release
ci: add auto-release workflow on PR merge
2 parents fd68501 + b6cb724 commit bb0a705

2 files changed

Lines changed: 88 additions & 0 deletions

File tree

.github/workflows/auto-release.yml

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
name: Auto Release
2+
3+
on:
4+
pull_request:
5+
types: [closed]
6+
branches: [main]
7+
8+
permissions:
9+
contents: write
10+
11+
jobs:
12+
auto-release:
13+
name: Determine Version and Tag
14+
runs-on: ubuntu-latest
15+
if: github.event.pull_request.merged == true
16+
17+
steps:
18+
- uses: actions/checkout@v4
19+
with:
20+
fetch-depth: 0
21+
22+
- name: Setup Bun
23+
uses: oven-sh/setup-bun@v2
24+
with:
25+
bun-version: latest
26+
27+
- name: Install Just
28+
uses: extractions/setup-just@v2
29+
30+
- name: Determine next version
31+
id: version
32+
run: |
33+
latest_tag=$(git describe --tags --abbrev=0 2>/dev/null || echo "v0.0.0")
34+
echo "latest=$latest_tag" >> "$GITHUB_OUTPUT"
35+
36+
# Parse current version
37+
version="${latest_tag#v}"
38+
IFS='.' read -r major minor patch <<< "$version"
39+
40+
# Check commit messages since last tag for bump type
41+
commits=$(git log "$latest_tag"..HEAD --pretty=format:"%s" 2>/dev/null || git log --pretty=format:"%s")
42+
43+
if echo "$commits" | grep -qE "^feat(\(.+\))?!:|^fix(\(.+\))?!:|^refactor(\(.+\))?!:|BREAKING CHANGE"; then
44+
major=$((major + 1))
45+
minor=0
46+
patch=0
47+
elif echo "$commits" | grep -qE "^feat(\(.+\))?:"; then
48+
minor=$((minor + 1))
49+
patch=0
50+
else
51+
patch=$((patch + 1))
52+
fi
53+
54+
next="v${major}.${minor}.${patch}"
55+
echo "next=$next" >> "$GITHUB_OUTPUT"
56+
echo "version=${major}.${minor}.${patch}" >> "$GITHUB_OUTPUT"
57+
echo "Next version: $next"
58+
59+
- name: Update versions
60+
run: |
61+
bun install --frozen-lockfile
62+
just set-version ${{ steps.version.outputs.version }}
63+
64+
- name: Verify
65+
run: |
66+
just typecheck
67+
just test
68+
69+
- name: Commit and tag
70+
env:
71+
TAG: ${{ steps.version.outputs.next }}
72+
VERSION: ${{ steps.version.outputs.version }}
73+
run: |
74+
git config user.name "github-actions[bot]"
75+
git config user.email "github-actions[bot]@users.noreply.github.com"
76+
git add package.json src/cli/index.ts skills/*/SKILL.md
77+
git commit -m "chore(release): bump version to v$VERSION"
78+
git tag -a "$TAG" -m "Release $TAG"
79+
git push origin main --follow-tags

justfile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,15 @@ commit-version:
8282
echo "Created tag v$VERSION"; \
8383
echo "Push with: git push origin main --tags"
8484

85+
set-version version:
86+
jq --arg v "{{version}}" '.version = $v' package.json > package.json.tmp && mv package.json.tmp package.json
87+
@VERSION="{{version}}"; \
88+
sed -i 's/const VERSION = "[^"]*";/const VERSION = "'"$VERSION"'";/' src/cli/index.ts; \
89+
sed -i 's/^version: .*/version: '"$VERSION"'/' skills/upkeep-deps/SKILL.md; \
90+
sed -i 's/^version: .*/version: '"$VERSION"'/' skills/upkeep-audit/SKILL.md; \
91+
sed -i 's/^version: .*/version: '"$VERSION"'/' skills/upkeep-quality/SKILL.md; \
92+
echo "Set all versions to $VERSION"
93+
8594
version-sync:
8695
just update-all-versions
8796

0 commit comments

Comments
 (0)