-
Notifications
You must be signed in to change notification settings - Fork 11
198 lines (165 loc) · 5.99 KB
/
release.yml
File metadata and controls
198 lines (165 loc) · 5.99 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
name: Create Release
on:
push:
tags:
- 'v*'
permissions:
contents: write
concurrency:
group: release-${{ github.ref_name }}
cancel-in-progress: true
jobs:
update-flake-version:
name: Update Flake Version
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
fetch-depth: 0
- name: Update flake.nix version
run: |
set -euo pipefail
version="${GITHUB_REF#refs/tags/}"
version="${version#v}"
echo "Updating flake.nix to version: $version"
# Update version in flake.nix
sed -i "s/dsearchVersion = \"[^\"]*\"/dsearchVersion = \"$version\"/" flake.nix
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
if ! git diff --quiet flake.nix; then
git add flake.nix
git commit -m "flake: bump version to $version"
# Push to master (or main, depending on your default branch)
git push origin HEAD:master || git push origin HEAD:main
echo "Pushed flake.nix version update to master"
else
echo "No version changes needed"
fi
test:
name: Test
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v4
- name: Setup Go with cache
uses: actions/setup-go@v5
with:
go-version-file: ./go.mod
- name: Run tests
run: go test -v ./...
- name: Run go vet
run: go vet ./...
build:
name: Build Binaries
needs: [test]
strategy:
matrix:
include:
- goos: linux
goarch: amd64
runs-on: ubuntu-24.04
- goos: linux
goarch: arm64
runs-on: ubuntu-24.04
runs-on: ${{ matrix.runs-on }}
steps:
- uses: actions/checkout@v4
- name: Setup Go with cache
uses: actions/setup-go@v5
with:
go-version-file: ./go.mod
- name: Build CLI Binary
env:
GOOS: ${{ matrix.goos }}
GOARCH: ${{ matrix.goarch }}
CGO_ENABLED: 0
run: |
VERSION=${{ github.ref_name }}
BUILD_TIME=$(date -u '+%Y-%m-%d_%H:%M:%S')
COMMIT=$(git rev-parse --short HEAD)
BINARY_NAME="dsearch-${{ matrix.goos }}-${{ matrix.goarch }}"
go build -ldflags "-s -w -X main.Version=${VERSION} -X main.buildTime=${BUILD_TIME} -X main.commit=${COMMIT}" \
-o "${BINARY_NAME}" ./cmd/dsearch
gzip -c "${BINARY_NAME}" > "${BINARY_NAME}.gz"
tar -czf "${BINARY_NAME}.tar.gz" "${BINARY_NAME}"
- name: Generate checksums
run: |
BINARY_NAME="dsearch-${{ matrix.goos }}-${{ matrix.goarch }}"
sha256sum "${BINARY_NAME}.gz" > "${BINARY_NAME}.gz.sha256"
sha256sum "${BINARY_NAME}.tar.gz" > "${BINARY_NAME}.tar.gz.sha256"
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: dsearch-${{ matrix.goos }}-${{ matrix.goarch }}
path: |
dsearch-${{ matrix.goos }}-${{ matrix.goarch }}.gz
dsearch-${{ matrix.goos }}-${{ matrix.goarch }}.gz.sha256
dsearch-${{ matrix.goos }}-${{ matrix.goarch }}.tar.gz
dsearch-${{ matrix.goos }}-${{ matrix.goarch }}.tar.gz.sha256
create_release:
name: Create GitHub Release
runs-on: ubuntu-24.04
needs: [build]
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Download all artifacts
uses: actions/download-artifact@v4
with:
path: ./artifacts
- name: Generate Changelog
id: changelog
run: |
PREVIOUS_TAG=$(git describe --tags --abbrev=0 HEAD^ 2>/dev/null || echo "")
if [ -z "$PREVIOUS_TAG" ]; then
echo "No previous tag found, using all commits"
CHANGELOG=$(git log --oneline --pretty=format:"- %s (%h)" | head -50)
else
echo "Generating changelog from $PREVIOUS_TAG to HEAD"
CHANGELOG=$(git log --oneline --pretty=format:"- %s (%h)" $PREVIOUS_TAG..HEAD)
fi
cat > CHANGELOG.md << EOF
## What's Changed
$CHANGELOG
**Full Changelog**: https://github.com/${{ github.repository }}/compare/${PREVIOUS_TAG}...${{ github.ref_name }}
EOF
echo "changelog<<EOF" >> $GITHUB_OUTPUT
cat CHANGELOG.md >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
- name: Create Release
uses: comnoco/create-release-action@v2.0.5
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.ref_name }}
release_name: Release ${{ github.ref_name }}
body: ${{ steps.changelog.outputs.changelog }}
draft: false
prerelease: ${{ contains(github.ref_name, '-') }}
# Generate source tarball with vendored modules
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version-file: ./go.mod
- name: Generate vendored source tarball
run: |
VERSION=${{ github.ref_name }}
VERSION_NUM=${VERSION#v}
go mod vendor
tar czf "dsearch-${VERSION_NUM}.tar.gz" --transform "s,^,dsearch-${VERSION_NUM}/," --exclude=./artifacts --exclude=.git *
- name: Upload assets
run: |
VERSION=${{ github.ref_name }}
VERSION_NUM=${VERSION#v}
# Upload all binaries and checksums
find ./artifacts -name "dsearch-*" -type f | while read file; do
echo "Uploading: $file"
gh release upload "$VERSION" "$file" --clobber
done
# Upload vendored source tarball
echo "Uploading: dsearch-${VERSION_NUM}.tar.gz"
gh release upload "$VERSION" "dsearch-${VERSION_NUM}.tar.gz" --clobber
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}