1
+ name : Auto Release
2
+
3
+ on :
4
+ workflow_dispatch :
5
+ inputs :
6
+ release_type :
7
+ description : ' Release type'
8
+ required : true
9
+ default : ' patch'
10
+ type : choice
11
+ options :
12
+ - patch
13
+ - minor
14
+ - major
15
+
16
+ permissions :
17
+ contents : write
18
+ pull-requests : write
19
+
20
+ jobs :
21
+ auto-release :
22
+ runs-on : ubuntu-latest
23
+
24
+ steps :
25
+ - name : Checkout
26
+ uses : actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
27
+ with :
28
+ fetch-depth : 0
29
+ token : ${{ secrets.GITHUB_TOKEN }}
30
+
31
+ - name : Setup Node.js
32
+ uses : actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4.0.2
33
+ with :
34
+ node-version : ' 20'
35
+
36
+ - name : Install semver CLI
37
+ run : npm install -g semver
38
+
39
+ - name : Get current version
40
+ id : current_version
41
+ run : |
42
+ CURRENT_VERSION=$(grep '^version = ' Cargo.toml | sed 's/version = "\(.*\)"/\1/')
43
+ echo "current=$CURRENT_VERSION" >> $GITHUB_OUTPUT
44
+ echo "Current version: $CURRENT_VERSION"
45
+
46
+ - name : Set release type
47
+ id : release_type
48
+ run : |
49
+ RELEASE_TYPE="${{ github.event.inputs.release_type }}"
50
+ echo "type=$RELEASE_TYPE" >> $GITHUB_OUTPUT
51
+ echo "Release type: $RELEASE_TYPE"
52
+
53
+ - name : Calculate new version
54
+ id : new_version
55
+ run : |
56
+ CURRENT_VERSION="${{ steps.current_version.outputs.current }}"
57
+ RELEASE_TYPE="${{ steps.release_type.outputs.type }}"
58
+ NEW_VERSION=$(semver -i $RELEASE_TYPE $CURRENT_VERSION)
59
+
60
+ echo "new=$NEW_VERSION" >> $GITHUB_OUTPUT
61
+ echo "New version: $NEW_VERSION"
62
+
63
+ - name : Update Cargo.toml
64
+ run : |
65
+ NEW_VERSION="${{ steps.new_version.outputs.new }}"
66
+ sed -i "s/^version = \".*\"/version = \"$NEW_VERSION\"/" Cargo.toml
67
+ echo "Updated Cargo.toml to version $NEW_VERSION"
68
+
69
+ - name : Update CHANGELOG.md
70
+ run : |
71
+ NEW_VERSION="${{ steps.new_version.outputs.new }}"
72
+ TODAY=$(date +%Y-%m-%d)
73
+
74
+ # Get commits since last tag for changelog
75
+ LAST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "")
76
+ if [ -n "$LAST_TAG" ]; then
77
+ COMMITS=$(git log ${LAST_TAG}..HEAD --oneline --pretty=format:"- %s")
78
+ else
79
+ COMMITS=$(git log --oneline --pretty=format:"- %s" -10)
80
+ fi
81
+
82
+ # Insert new version section after "## [Unreleased]"
83
+ sed -i "/## \[Unreleased\]/a\\
84
+ \\
85
+ # # [$NEW_VERSION] - $TODAY\\
86
+ \\
87
+ # ## Changes\\
88
+ $COMMITS" CHANGELOG.md
89
+
90
+ echo "Updated CHANGELOG.md"
91
+
92
+ - name : Commit version bump
93
+ run : |
94
+ NEW_VERSION="${{ steps.new_version.outputs.new }}"
95
+ git config --local user.email "action@github.com"
96
+ git config --local user.name "GitHub Action"
97
+ git add Cargo.toml CHANGELOG.md
98
+ git commit -m "chore: release v$NEW_VERSION
99
+
100
+ 🤖 Generated with [Claude Code](https://claude.ai/code)
101
+
102
+ Co-Authored-By : Claude <noreply@anthropic.com>"
103
+
104
+ - name : Create and push tag
105
+ run : |
106
+ NEW_VERSION="${{ steps.new_version.outputs.new }}"
107
+ git tag -a "v$NEW_VERSION" -m "Release v$NEW_VERSION"
108
+ git push origin main
109
+ git push origin "v$NEW_VERSION"
110
+
111
+ - name : Trigger Homebrew update
112
+ run : |
113
+ NEW_VERSION="${{ steps.new_version.outputs.new }}"
114
+ # Wait a moment for the release workflow to complete
115
+ sleep 60
116
+ gh workflow run "Update Homebrew Formula" --field tag="v$NEW_VERSION"
117
+ env :
118
+ GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
0 commit comments