-
Notifications
You must be signed in to change notification settings - Fork 1
150 lines (129 loc) · 4.22 KB
/
release.yml
File metadata and controls
150 lines (129 loc) · 4.22 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
name: Build Release
on:
push:
tags:
- 'v*'
workflow_dispatch:
jobs:
build:
name: Build Cross-Platform Binaries
runs-on: ubuntu-latest
strategy:
matrix:
include:
- goos: linux
goarch: amd64
name: linux-amd64
- goos: linux
goarch: arm64
name: linux-arm64
- goos: darwin
goarch: amd64
name: darwin-amd64
- goos: darwin
goarch: arm64
name: darwin-arm64
- goos: windows
goarch: amd64
name: windows-amd64
ext: .exe
- goos: windows
goarch: arm64
name: windows-arm64
ext: .exe
steps:
- uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.25'
- name: Cache Go modules
uses: actions/cache@v4
with:
path: |
~/.cache/go-build
~/go/pkg/mod
key: ${{ runner.os }}-go-1.25-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-1.25-
- name: Download dependencies
run: go mod download
- name: Extract version information
id: version
run: |
# Extract version from tag (remove 'v' prefix if present)
if [[ "${{ github.ref }}" == refs/tags/* ]]; then
VERSION="${GITHUB_REF#refs/tags/}"
else
VERSION=$(git describe --tags --always --dirty 2>/dev/null || echo "dev")
fi
echo "version=$VERSION" >> $GITHUB_OUTPUT
# Get build date in UTC
BUILD_DATE=$(date -u +"%Y-%m-%d")
echo "build_date=$BUILD_DATE" >> $GITHUB_OUTPUT
# Get short commit hash
GIT_COMMIT=$(git rev-parse --short HEAD)
echo "git_commit=$GIT_COMMIT" >> $GITHUB_OUTPUT
echo "Building version: $VERSION (commit: $GIT_COMMIT, date: $BUILD_DATE)"
- name: Build binary
env:
GOOS: ${{ matrix.goos }}
GOARCH: ${{ matrix.goarch }}
CGO_ENABLED: 0
run: |
go build -a -installsuffix cgo \
-ldflags="-w -s -X cloudamqp-cli/cmd.Version=${{ steps.version.outputs.version }} -X cloudamqp-cli/cmd.BuildDate=${{ steps.version.outputs.build_date }} -X cloudamqp-cli/cmd.GitCommit=${{ steps.version.outputs.git_commit }}" \
-o cloudamqp-${{ matrix.name }}${{ matrix.ext }} .
- name: Verify version (Linux/macOS only)
if: matrix.goos != 'windows'
run: |
chmod +x cloudamqp-${{ matrix.name }}${{ matrix.ext }}
./cloudamqp-${{ matrix.name }}${{ matrix.ext }} version || echo "Version verification skipped for cross-compiled binary"
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: cloudamqp-${{ matrix.name }}
path: cloudamqp-${{ matrix.name }}${{ matrix.ext }}
retention-days: 30
package:
name: Create Release Archive
runs-on: ubuntu-latest
needs: build
if: startsWith(github.ref, 'refs/tags/')
steps:
- uses: actions/checkout@v4
- name: Download all artifacts
uses: actions/download-artifact@v4
with:
path: artifacts
- name: Create release archives
run: |
mkdir -p release
for dir in artifacts/*/; do
artifact_name=$(basename "$dir")
binary_name=$(ls "$dir")
# Create archive based on platform
if [[ $artifact_name == *"windows"* ]]; then
cd "$dir" && zip "../../release/${artifact_name}.zip" "$binary_name" && cd - > /dev/null
else
cd "$dir" && tar -czf "../../release/${artifact_name}.tar.gz" "$binary_name" && cd - > /dev/null
fi
done
# List created archives
ls -la release/
- name: Upload release archives
uses: actions/upload-artifact@v4
with:
name: release-archives
path: release/
retention-days: 90
- name: Create GitHub Release
uses: softprops/action-gh-release@v1
if: startsWith(github.ref, 'refs/tags/')
with:
files: release/*
draft: false
prerelease: false
generate_release_notes: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}