-
Notifications
You must be signed in to change notification settings - Fork 1
203 lines (173 loc) · 5.42 KB
/
Copy pathrelease.yml
File metadata and controls
203 lines (173 loc) · 5.42 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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
name: Build and Release
on:
push:
branches:
- main
permissions:
contents: write
jobs:
test:
name: Run Tests
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v6
- name: Set up Go
uses: actions/setup-go@v6
with:
go-version: '1.25'
- name: Download dependencies
run: go mod download
- name: Run tests
run: go test -v ./tests/...
version:
name: Calculate Version
runs-on: ubuntu-latest
needs: test
outputs:
new_version: ${{ steps.version.outputs.new_version }}
changelog: ${{ steps.version.outputs.changelog }}
steps:
- name: Checkout code
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Get latest tag
id: get_tag
run: |
# Get the latest tag, or use v0.0.0 if no tags exist
LATEST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "v0.0.0")
echo "latest_tag=$LATEST_TAG" >> $GITHUB_OUTPUT
echo "Latest tag: $LATEST_TAG"
- name: Calculate new version
id: version
run: |
LATEST_TAG="${{ steps.get_tag.outputs.latest_tag }}"
# Remove 'v' prefix
VERSION=${LATEST_TAG#v}
# Split version into parts
IFS='.' read -ra VERSION_PARTS <<< "$VERSION"
MAJOR=${VERSION_PARTS[0]}
MINOR=${VERSION_PARTS[1]}
PATCH=${VERSION_PARTS[2]}
# Get commit messages since last tag
if [ "$LATEST_TAG" = "v0.0.0" ]; then
COMMITS=$(git log --pretty=format:"%s")
else
COMMITS=$(git log ${LATEST_TAG}..HEAD --pretty=format:"%s")
fi
echo "Commits since last tag:"
echo "$COMMITS"
# Check for breaking changes (MAJOR)
if echo "$COMMITS" | grep -qiE "BREAKING CHANGE|major:"; then
MAJOR=$((MAJOR + 1))
MINOR=0
PATCH=0
BUMP_TYPE="major"
# Check for features (MINOR)
elif echo "$COMMITS" | grep -qiE "^feat|^feature|minor:"; then
MINOR=$((MINOR + 1))
PATCH=0
BUMP_TYPE="minor"
# Default to PATCH
else
PATCH=$((PATCH + 1))
BUMP_TYPE="patch"
fi
NEW_VERSION="v${MAJOR}.${MINOR}.${PATCH}"
echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT
echo "bump_type=$BUMP_TYPE" >> $GITHUB_OUTPUT
echo "New version: $NEW_VERSION (${BUMP_TYPE} bump)"
# Generate changelog
CHANGELOG="## Changes in $NEW_VERSION\n\n"
if [ "$LATEST_TAG" = "v0.0.0" ]; then
CHANGELOG+="Initial release\n\n"
CHANGELOG+=$(git log --pretty=format:"- %s (%h)" | head -20)
else
CHANGELOG+=$(git log ${LATEST_TAG}..HEAD --pretty=format:"- %s (%h)")
fi
echo "changelog<<EOF" >> $GITHUB_OUTPUT
echo -e "$CHANGELOG" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
build:
name: Build Binaries
runs-on: ubuntu-latest
needs: version
strategy:
matrix:
include:
# Windows
- goos: windows
goarch: amd64
output: dave-windows-amd64.exe
- goos: windows
goarch: arm64
output: dave-windows-arm64.exe
# macOS
- goos: darwin
goarch: amd64
output: dave-macos-amd64
- goos: darwin
goarch: arm64
output: dave-macos-arm64
# Linux
- goos: linux
goarch: amd64
output: dave-linux-amd64
- goos: linux
goarch: arm64
output: dave-linux-arm64
- goos: linux
goarch: 386
output: dave-linux-386
steps:
- name: Checkout code
uses: actions/checkout@v6
- name: Set up Go
uses: actions/setup-go@v6
with:
go-version: '1.25'
- name: Download dependencies
run: go mod download
- name: Build binary
env:
GOOS: ${{ matrix.goos }}
GOARCH: ${{ matrix.goarch }}
CGO_ENABLED: 0
run: |
VERSION="${{ needs.version.outputs.new_version }}"
go build -ldflags "-s -w -X main.Version=${VERSION}" -o ${{ matrix.output }}
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.output }}
path: ${{ matrix.output }}
release:
name: Create Release
runs-on: ubuntu-latest
needs: [version, build]
steps:
- name: Checkout code
uses: actions/checkout@v6
- name: Download all artifacts
uses: actions/download-artifact@v4
with:
path: ./binaries
- name: Display structure of downloaded files
run: ls -R ./binaries
- name: Prepare release assets
run: |
mkdir -p release
find ./binaries -type f -exec cp {} ./release/ \;
ls -lh ./release
- name: Create Release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ needs.version.outputs.new_version }}
name: Release ${{ needs.version.outputs.new_version }}
body: ${{ needs.version.outputs.changelog }}
files: ./release/*
draft: false
prerelease: false
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}