forked from javi11/altmount
-
Notifications
You must be signed in to change notification settings - Fork 0
222 lines (197 loc) · 6.56 KB
/
build-cli.yml
File metadata and controls
222 lines (197 loc) · 6.56 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
name: Build CLI Binaries
on:
workflow_call:
inputs:
version:
description: 'Version string (without leading v), e.g. 0.3.0 or dev-<sha>'
type: string
required: true
commit:
description: 'Short commit SHA'
type: string
required: true
upload-to-release:
description: 'Whether to attach archives to a GitHub release'
type: boolean
required: false
default: false
release-tag:
description: 'Release tag to attach archives to (when upload-to-release is true)'
type: string
required: false
default: ''
prerelease:
description: 'Mark the release as a prerelease'
type: boolean
required: false
default: false
jobs:
build-cli:
runs-on: ${{ matrix.runner }}
permissions:
contents: write
strategy:
matrix:
include:
# Linux builds
- goos: linux
goarch: amd64
runner: ubuntu-latest
cc: zig cc -target x86_64-linux-musl
- goos: linux
goarch: arm64
runner: ubuntu-latest
cc: zig cc -target aarch64-linux-musl
# macOS builds
- goos: darwin
goarch: amd64
runner: macos-latest
cc: ''
- goos: darwin
goarch: arm64
runner: macos-latest
cc: ''
# Windows builds
- goos: windows
goarch: amd64
runner: ubuntu-latest
cc: zig cc -target x86_64-windows-gnu
steps:
- uses: mlugg/setup-zig@v2
if: matrix.cc != ''
- uses: actions/setup-go@v6
with:
go-version: 1.26.0
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Download frontend build
uses: actions/download-artifact@v8
with:
name: frontend-build
path: frontend/dist/
- name: Install macFUSE
if: matrix.goos == 'darwin'
run: brew install --cask macfuse
- name: Compute timestamp
id: ts
run: echo "timestamp=$(date -u '+%Y-%m-%dT%H:%M:%SZ')" >> $GITHUB_OUTPUT
- name: Build ${{ matrix.goos }}-${{ matrix.goarch }} binary
env:
GOOS: ${{ matrix.goos }}
GOARCH: ${{ matrix.goarch }}
CGO_ENABLED: 1
CC: ${{ matrix.cc }}
run: |
EXT=""
if [ "${{ matrix.goos }}" = "windows" ]; then
EXT=".exe"
fi
go build \
-trimpath \
-tags=cli \
-ldflags="-s -w -X 'github.com/javi11/altmount/internal/version.Version=${{ inputs.version }}' -X 'github.com/javi11/altmount/internal/version.GitCommit=${{ inputs.commit }}' -X 'github.com/javi11/altmount/internal/version.Timestamp=${{ steps.ts.outputs.timestamp }}'" \
-o "altmount-cli-${{ matrix.goos }}-${{ matrix.goarch }}${EXT}" \
./cmd/altmount/main.go
- name: Create archive
run: |
EXT=""
if [ "${{ matrix.goos }}" = "windows" ]; then
EXT=".exe"
fi
BINARY_NAME="altmount-cli-${{ matrix.goos }}-${{ matrix.goarch }}${EXT}"
ARCHIVE_NAME="altmount-cli_v${{ inputs.version }}_${{ matrix.goos }}_${{ matrix.goarch }}"
if [ "${{ matrix.goos }}" = "windows" ]; then
zip "${ARCHIVE_NAME}.zip" "$BINARY_NAME"
else
tar -czf "${ARCHIVE_NAME}.tar.gz" "$BINARY_NAME"
fi
- name: Upload ${{ matrix.goos }}-${{ matrix.goarch }} artifacts
uses: actions/upload-artifact@v6
with:
name: cli-${{ matrix.goos }}-${{ matrix.goarch }}
path: |
altmount-cli_v${{ inputs.version }}_${{ matrix.goos }}_${{ matrix.goarch }}.*
retention-days: 1
create-universal-darwin:
runs-on: macos-latest
needs: build-cli
permissions:
contents: write
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Download darwin-amd64 binary
uses: actions/download-artifact@v8
with:
name: cli-darwin-amd64
path: ./artifacts/
- name: Download darwin-arm64 binary
uses: actions/download-artifact@v8
with:
name: cli-darwin-arm64
path: ./artifacts/
- name: Extract binaries
run: |
cd artifacts
tar -xzf altmount-cli_v${{ inputs.version }}_darwin_amd64.tar.gz
tar -xzf altmount-cli_v${{ inputs.version }}_darwin_arm64.tar.gz
- name: Create universal binary
run: |
lipo -create \
artifacts/altmount-cli-darwin-amd64 \
artifacts/altmount-cli-darwin-arm64 \
-output altmount-cli-darwin-universal
tar -czf "altmount-cli_v${{ inputs.version }}_darwin_universal.tar.gz" altmount-cli-darwin-universal
- name: Upload universal darwin artifact
uses: actions/upload-artifact@v6
with:
name: cli-darwin-universal
path: altmount-cli_v${{ inputs.version }}_darwin_universal.tar.gz
retention-days: 1
publish:
runs-on: ubuntu-latest
needs: [build-cli, create-universal-darwin]
permissions:
contents: write
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Download all CLI artifacts
uses: actions/download-artifact@v8
with:
pattern: cli-*
path: ./artifacts/
merge-multiple: true
- name: Create checksums
run: |
cd artifacts
sha512sum altmount-cli_v${{ inputs.version }}_*.* > checksums-cli.txt
cat checksums-cli.txt
- name: Upload combined artifacts (when not publishing to release)
if: ${{ !inputs.upload-to-release }}
uses: actions/upload-artifact@v6
with:
name: cli-release-bundle
path: |
artifacts/altmount-cli_v${{ inputs.version }}_*.*
artifacts/checksums-cli.txt
retention-days: 7
- name: Attach assets to GitHub Release
if: ${{ inputs.upload-to-release }}
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ inputs.release-tag }}
files: |
artifacts/altmount-cli_v${{ inputs.version }}_*.*
artifacts/checksums-cli.txt
draft: false
prerelease: ${{ inputs.prerelease }}
make_latest: ${{ !inputs.prerelease }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}