-
Notifications
You must be signed in to change notification settings - Fork 2
189 lines (163 loc) · 6.1 KB
/
release.yml
File metadata and controls
189 lines (163 loc) · 6.1 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
name: Release
on:
push:
tags:
- 'v*'
permissions:
contents: write
id-token: write
jobs:
build:
name: Build Artifacts
strategy:
matrix:
include:
- build_id: sstart-linux-amd64
runner: ubuntu-latest
goos: linux
goarch: amd64
binary_name: sstart
- build_id: sstart-linux-arm64
runner: ubuntu-latest
goos: linux
goarch: arm64
binary_name: sstart
- build_id: sstart-darwin-amd64
runner: macos-latest
goos: darwin
goarch: amd64
binary_name: sstart
- build_id: sstart-darwin-arm64
runner: macos-latest
goos: darwin
goarch: arm64
binary_name: sstart
runs-on: ${{ matrix.runner }}
steps:
- name: Checkout code
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Set up Go
uses: actions/setup-go@v6
with:
go-version-file: go.mod
- name: Install Linux ARM64 cross-compilation toolchain (Linux ARM64 only)
if: matrix.goos == 'linux' && matrix.goarch == 'arm64'
run: |
sudo apt-get update
sudo apt-get install -y gcc-aarch64-linux-gnu g++-aarch64-linux-gnu binutils-aarch64-linux-gnu
echo "CC=aarch64-linux-gnu-gcc" >> $GITHUB_ENV
echo "CXX=aarch64-linux-gnu-g++" >> $GITHUB_ENV
echo "AR=aarch64-linux-gnu-ar" >> $GITHUB_ENV
echo "AS=aarch64-linux-gnu-as" >> $GITHUB_ENV
- name: Calculate version
id: version
uses: actions/github-script@v8
with:
script: |
// Extract version from tag (remove 'v' prefix if present)
const tag = context.ref.replace('refs/tags/', '');
const version = tag.startsWith('v') ? tag.substring(1) : tag;
const buildDate = new Date().toISOString();
core.setOutput('version', version);
core.setOutput('tag', tag);
core.setOutput('date', buildDate);
console.log(`Version: ${version}`);
console.log(`Tag: ${tag}`);
console.log(`Build date: ${buildDate}`);
- name: Build binary
env:
CGO_ENABLED: 1
CGO_LDFLAGS: -lm
GOOS: ${{ matrix.goos }}
GOARCH: ${{ matrix.goarch }}
run: |
go build \
-ldflags="-s -w -X github.com/dirathea/sstart/internal/cli.version=${{ steps.version.outputs.version }} -X github.com/dirathea/sstart/internal/cli.commit=${{ github.sha }} -X github.com/dirathea/sstart/internal/cli.date=${{ steps.version.outputs.date }}" \
-o ${{ matrix.binary_name }} \
./cmd/sstart
- name: Prepare release archive
run: |
mkdir -p release
# Use lowercase OS and arch names for the archive filename
# Format: sstart-{VERSION}-{os}-{arch}.tar.gz
OS_NAME="${{ matrix.goos }}"
ARCH_NAME="${{ matrix.goarch }}"
ARCHIVE_NAME="sstart-${{ steps.version.outputs.version }}-${OS_NAME}-${ARCH_NAME}"
# Create temporary directory for archive contents
TEMP_DIR=$(mktemp -d)
# Copy binary to temp directory
cp ${{ matrix.binary_name }} "${TEMP_DIR}/sstart"
# Copy LICENSE and README if they exist
cp LICENSE README.md "${TEMP_DIR}/" 2>/dev/null || true
# Create archive with binary at root (not in a subdirectory)
# Use -C to change into temp directory and archive contents directly
tar -czf "release/${ARCHIVE_NAME}.tar.gz" -C "${TEMP_DIR}" .
# Clean up
rm -rf "${TEMP_DIR}"
# Verify archive structure (binary should be at root)
echo "Archive contents:"
tar -tzf "release/${ARCHIVE_NAME}.tar.gz" | head -10
- name: Upload build artifacts
uses: actions/upload-artifact@v7
with:
name: release-${{ matrix.build_id }}
path: release/*
retention-days: 1
release:
name: Publish Release
needs: build
runs-on: ubuntu-latest
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
steps:
- name: Checkout code
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Calculate version
id: version
uses: actions/github-script@v8
with:
script: |
// Extract version from tag (remove 'v' prefix if present)
const tag = context.ref.replace('refs/tags/', '');
const version = tag.startsWith('v') ? tag.substring(1) : tag;
core.setOutput('version', version);
core.setOutput('tag', tag);
console.log(`Version: ${version}`);
console.log(`Tag: ${tag}`);
- name: Download all artifacts
uses: actions/download-artifact@v8
with:
path: artifacts
- name: Prepare release assets
run: |
mkdir -p release
# Copy all release archives from artifacts
for dir in artifacts/release-*/; do
if [ -d "$dir" ]; then
echo "Copying from $dir"
find "$dir" -type f \( -name "*.tar.gz" -o -name "*.zip" \) -exec cp {} release/ \;
fi
done
# Create checksums
cd release
sha256sum * > checksums.txt
echo "Release assets:"
ls -la
- name: Publish GitHub Release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ steps.version.outputs.tag }}
name: Release ${{ steps.version.outputs.version }}
body: |
Release ${{ steps.version.outputs.version }}
## Assets
- Pre-built binaries for Linux (amd64, arm64) and macOS (amd64, arm64)
- Checksums file for verification
files: release/*
draft: false
prerelease: false
env:
GITHUB_TOKEN: ${{ secrets.HOMEBREW_TAP_TOKEN }}