-
Notifications
You must be signed in to change notification settings - Fork 1
249 lines (224 loc) · 8.8 KB
/
Copy pathrelease.yml
File metadata and controls
249 lines (224 loc) · 8.8 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
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
name: Build and Release Go Binary
on:
push:
branches: ["main"]
tags:
- "v*"
workflow_dispatch:
env:
GO_VERSION: "1.24"
permissions:
contents: write
packages: write
jobs:
build:
name: Build (${{ matrix.os }}-${{ matrix.arch }})
runs-on: ${{ matrix.os }}
permissions:
contents: write
packages: write
strategy:
matrix:
include:
- os: ubuntu-latest
goos: linux
arch: amd64
artifact_name: vers-linux-amd64
asset_name: vers-linux-amd64
- os: ubuntu-latest
goos: linux
arch: arm64
artifact_name: vers-linux-arm64
asset_name: vers-linux-arm64
- os: ubuntu-latest
goos: darwin
arch: amd64
artifact_name: vers-darwin-amd64
asset_name: vers-darwin-amd64
- os: ubuntu-latest
goos: darwin
arch: arm64
artifact_name: vers-darwin-arm64
asset_name: vers-darwin-arm64
- os: ubuntu-latest
goos: windows
arch: amd64
artifact_name: vers-windows-amd64.exe
asset_name: vers-windows-amd64
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: ${{ env.GO_VERSION }}
- name: Cache Go modules
uses: actions/cache@v3
with:
path: |
~/.cache/go-build
~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}-v1
restore-keys: |
${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}-
${{ runner.os }}-go-
- name: Download dependencies
run: go mod download
- name: Get build info
id: build_info
run: |
if [[ "${{ github.ref }}" == refs/tags/* ]]; then
VERSION="${{ github.ref_name }}"
elif [[ "${{ github.ref }}" == "refs/heads/main" ]]; then
VERSION="nightly-$(git rev-parse --short HEAD)"
else
VERSION=$(git describe --tags --always --dirty 2>/dev/null || echo "dev-$(git rev-parse --short HEAD)")
fi
GIT_COMMIT=$(git rev-parse HEAD)
BUILD_DATE=$(date -u +'%Y-%m-%dT%H:%M:%SZ')
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "git_commit=$GIT_COMMIT" >> $GITHUB_OUTPUT
echo "build_date=$BUILD_DATE" >> $GITHUB_OUTPUT
echo "Building version: $VERSION"
echo "Git commit: $GIT_COMMIT"
echo "Build date: $BUILD_DATE"
- name: Build Release Binary
run: |
LDFLAGS="-s -w \
-X 'github.com/hdresearch/vers-cli/cmd.Version=${{ steps.build_info.outputs.version }}' \
-X 'github.com/hdresearch/vers-cli/cmd.GitCommit=${{ steps.build_info.outputs.git_commit }}' \
-X 'github.com/hdresearch/vers-cli/cmd.BuildDate=${{ steps.build_info.outputs.build_date }}' \
-X 'github.com/hdresearch/vers-cli/cmd.Name=vers-cli' \
-X 'github.com/hdresearch/vers-cli/cmd.Description=A CLI tool for version management' \
-X 'github.com/hdresearch/vers-cli/cmd.Author=the VERS team' \
-X 'github.com/hdresearch/vers-cli/cmd.Repository=https://github.com/hdresearch/vers-cli' \
-X 'github.com/hdresearch/vers-cli/cmd.License=MIT' \
-extldflags '-static'"
CGO_ENABLED=0 GOOS=${{ matrix.goos }} GOARCH=${{ matrix.arch }} \
go build -ldflags "$LDFLAGS" -o ${{ matrix.artifact_name }} ./cmd/vers
- name: Generate checksums
shell: bash
run: |
# Generate SHA256 checksum
sha256sum ${{ matrix.artifact_name }} > ${{ matrix.artifact_name }}.sha256
# Also create a JSON metadata file with size and checksum info
SIZE=$(stat -c%s ${{ matrix.artifact_name }} 2>/dev/null || stat -f%z ${{ matrix.artifact_name }})
SHA256=$(cut -d' ' -f1 ${{ matrix.artifact_name }}.sha256)
echo "{\"filename\":\"${{ matrix.artifact_name }}\",\"size\":$SIZE,\"sha256\":\"$SHA256\",\"version\":\"${{ steps.build_info.outputs.version }}\",\"goos\":\"${{ matrix.goos }}\",\"goarch\":\"${{ matrix.arch }}\"}" > ${{ matrix.artifact_name }}.json
cat ${{ matrix.artifact_name }}.sha256
cat ${{ matrix.artifact_name }}.json
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.asset_name }}
path: |
${{ matrix.artifact_name }}
${{ matrix.artifact_name }}.sha256
${{ matrix.artifact_name }}.json
if-no-files-found: error
release:
name: Create Release
needs: build
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/')
permissions:
contents: write
steps:
- name: Generate release info
id: release_info
run: |
if [ "${{ github.ref }}" = "refs/heads/main" ]; then
echo "name=nightly" >> $GITHUB_OUTPUT
echo "tag=nightly" >> $GITHUB_OUTPUT
echo "is_prerelease=true" >> $GITHUB_OUTPUT
else
echo "name=${{ github.ref_name }}" >> $GITHUB_OUTPUT
echo "tag=${{ github.ref_name }}" >> $GITHUB_OUTPUT
echo "is_prerelease=false" >> $GITHUB_OUTPUT
fi
- name: Download release artifacts
uses: actions/download-artifact@v4
- name: Delete existing nightly release and tag
if: github.ref == 'refs/heads/main'
run: |
gh release delete nightly --yes || true
git push origin :refs/tags/nightly || true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Create Release
uses: softprops/action-gh-release@v1
with:
name: ${{ steps.release_info.outputs.name }}
tag_name: ${{ steps.release_info.outputs.tag }}
files: |
vers-linux-amd64/vers-linux-amd64
vers-linux-amd64/vers-linux-amd64.sha256
vers-linux-amd64/vers-linux-amd64.json
vers-linux-arm64/vers-linux-arm64
vers-linux-arm64/vers-linux-arm64.sha256
vers-linux-arm64/vers-linux-arm64.json
vers-darwin-amd64/vers-darwin-amd64
vers-darwin-amd64/vers-darwin-amd64.sha256
vers-darwin-amd64/vers-darwin-amd64.json
vers-darwin-arm64/vers-darwin-arm64
vers-darwin-arm64/vers-darwin-arm64.sha256
vers-darwin-arm64/vers-darwin-arm64.json
vers-windows-amd64/vers-windows-amd64.exe
vers-windows-amd64/vers-windows-amd64.exe.sha256
vers-windows-amd64/vers-windows-amd64.exe.json
draft: false
prerelease: ${{ steps.release_info.outputs.is_prerelease }}
body: |
${{ github.ref == 'refs/heads/main' && format('Nightly build from commit {0}', github.sha) || '' }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
test:
name: Test Binary
needs: build
runs-on: ubuntu-latest
steps:
- name: Download Linux binary
uses: actions/download-artifact@v4
with:
name: vers-linux-amd64
path: ./
- name: Test binary
run: |
chmod +x ./vers-linux-amd64
echo "Testing version command:"
./vers-linux-amd64 --version
echo -e "\nTesting metadata command:"
./vers-linux-amd64 --VVersion || echo "Metadata command test completed"
- name: Verify static linking
run: |
echo "Checking binary is statically linked:"
if ldd ./vers-linux-amd64 2>&1 | grep -q "not a dynamic executable"; then
echo "✅ Binary is statically linked"
elif file ./vers-linux-amd64 | grep -q "statically linked"; then
echo "✅ Binary is statically linked"
else
echo "❌ Binary appears to be dynamically linked:"
ldd ./vers-linux-amd64 || true
file ./vers-linux-amd64
exit 1
fi
# homebrew:
# name: Update Homebrew Tap
# needs: release
# runs-on: ubuntu-latest
# if: startsWith(github.ref, 'refs/tags/')
# steps:
# - name: Update Homebrew tap
# uses: mislav/bump-homebrew-formula-action@v3
# with:
# formula-name: vers-cli
# formula-path: Formula/vers-cli.rb
# homebrew-tap: hdresearch/homebrew-vers-cli
# base-branch: main
# download-url: https://github.com/hdresearch/vers-cli/releases/download/${{ github.ref_name }}/vers-darwin-amd64
# commit-message: |
# vers-cli ${{ github.ref_name }}
# Created by bump-homebrew-formula-action
# env:
# COMMITTER_TOKEN: ${{ secrets.HOMEBREW_TAP_TOKEN }}