-
-
Notifications
You must be signed in to change notification settings - Fork 30
345 lines (305 loc) · 10.6 KB
/
release.yaml
File metadata and controls
345 lines (305 loc) · 10.6 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
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
# Copyright (c) 2021 Blacknon. All rights reserved.
# Use of this source code is governed by an MIT license
# that can be found in the LICENSE file.
name: Release Job.
on:
push:
branches:
- master
paths-ignore:
- '**/README.md'
permissions:
contents: write
jobs:
build:
strategy:
matrix:
include:
- goos: linux
goarch: amd64
os: ubuntu-latest
archive_ext: tar.gz
- goos: darwin
goarch: amd64
os: macos-latest
archive_ext: tar.gz
- goos: darwin
goarch: arm64
os: macos-latest
archive_ext: tar.gz
- goos: windows
goarch: amd64
os: windows-latest
archive_ext: zip
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v5
- name: Set up Go
uses: actions/setup-go@v6
with:
go-version-file: go.mod
cache: false
- name: Get version
id: package_version
shell: bash
run: |
set -euo pipefail
VERSION="$(go run ./cmd/lssh --version | grep -Eo '[0-9]+\.[0-9]+\.[0-9]+' | head -n1)"
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
- name: Install nfpm
if: matrix.goos == 'linux'
shell: bash
run: |
set -euo pipefail
go install github.com/goreleaser/nfpm/v2/cmd/nfpm@latest
echo "$(go env GOPATH)/bin" >> "$GITHUB_PATH"
- name: Build binaries
shell: bash
env:
GOOS: ${{ matrix.goos }}
GOARCH: ${{ matrix.goarch }}
run: |
set -euo pipefail
mkdir -p dist/bin
ext=""
if [ "${GOOS}" = "windows" ]; then
ext=".exe"
fi
cmds="lssh lscp lsftp lssync lsdiff lsmon lsshell lsmux lspipe"
if [ "${GOOS}" != "windows" ]; then
cmds="${cmds} lsshfs"
fi
for cmd in ${cmds}; do
go build -o "dist/bin/${cmd}${ext}" "./cmd/${cmd}"
done
- name: Create release packages
shell: bash
env:
VERSION: ${{ steps.package_version.outputs.version }}
GOOS: ${{ matrix.goos }}
GOARCH: ${{ matrix.goarch }}
ARCHIVE_EXT: ${{ matrix.archive_ext }}
run: |
set -euo pipefail
mkdir -p dist/packages dist/nfpm
package_name() {
case "$1" in
full) echo "lssh" ;;
core) echo "lssh-core" ;;
transfer) echo "lssh-transfer" ;;
monitor) echo "lssh-monitor" ;;
sysadmin) echo "lssh-sysadmin" ;;
esac
}
package_description() {
case "$1" in
full) echo "Full lssh suite with SSH, transfer, monitoring, and parallel shell tools." ;;
core) echo "Core SSH client package for the lssh suite." ;;
transfer)
if [ "$GOOS" = "windows" ]; then
echo "Transfer and diff tools package for the lssh suite, including lscp, lsftp, lssync, and lsdiff."
else
echo "Transfer, diff, and mount tools package for the lssh suite, including lscp, lsftp, lssync, lsdiff, and lsshfs."
fi
;;
monitor) echo "Monitoring tools package for the lssh suite, including lsmon." ;;
sysadmin) echo "Sysadmin tools package for the lssh suite, including lsshell, lsmux, and lspipe." ;;
esac
}
package_binaries() {
case "$1" in
full)
if [ "$GOOS" = "windows" ]; then
echo "lssh lscp lsftp lssync lsdiff lsmon lsshell lsmux lspipe"
else
echo "lssh lscp lsftp lssync lsdiff lsshfs lsmon lsshell lsmux lspipe"
fi
;;
core) echo "lssh" ;;
transfer)
if [ "$GOOS" = "windows" ]; then
echo "lscp lsftp lssync lsdiff"
else
echo "lscp lsftp lssync lsdiff lsshfs"
fi
;;
monitor) echo "lsmon" ;;
sysadmin) echo "lsshell lsmux lspipe" ;;
esac
}
deb_arch() {
case "$1" in
amd64) echo "amd64" ;;
arm64) echo "arm64" ;;
*) echo "$1" ;;
esac
}
rpm_arch() {
case "$1" in
amd64) echo "x86_64" ;;
arm64) echo "aarch64" ;;
*) echo "$1" ;;
esac
}
create_archive() {
local package_id="$1"
local pkg
local base
local root
pkg="$(package_name "$package_id")"
base="${pkg}_${VERSION}_${GOOS}_${GOARCH}"
root="dist/archive/${base}"
rm -rf "$root"
mkdir -p "$root/bin" "$root/completion/bash" "$root/completion/fish" "$root/completion/zsh"
cp README.md LICENSE.md "$root/"
for bin in $(package_binaries "$package_id"); do
local ext=""
if [ "$GOOS" = "windows" ]; then
ext=".exe"
fi
cp "dist/bin/${bin}${ext}" "$root/bin/${bin}${ext}"
if [ -f "completion/bash/${bin}" ]; then
cp "completion/bash/${bin}" "$root/completion/bash/${bin}"
fi
if [ -f "completion/fish/${bin}.fish" ]; then
cp "completion/fish/${bin}.fish" "$root/completion/fish/${bin}.fish"
fi
if [ -f "completion/zsh/_${bin}" ]; then
cp "completion/zsh/_${bin}" "$root/completion/zsh/_${bin}"
fi
done
if [ "$GOOS" = "windows" ]; then
powershell -NoLogo -NoProfile -Command "\$source = Join-Path (Get-Location) '${root}'; \$destination = Join-Path (Get-Location) 'dist/packages/${base}.zip'; Compress-Archive -Path (Join-Path \$source '*') -DestinationPath \$destination -Force"
else
tar -C "dist/archive" -czf "dist/packages/${base}.tar.gz" "${base}"
fi
}
create_nfpm_config() {
local package_id="$1"
local pkg
local desc
local config_path
pkg="$(package_name "$package_id")"
desc="$(package_description "$package_id")"
config_path="dist/nfpm/${pkg}.yaml"
cat > "$config_path" <<EOF
name: ${pkg}
arch: $(deb_arch "$GOARCH")
platform: linux
version: ${VERSION}
section: net
priority: optional
maintainer: blacknon <blacknon@orebibou.com>
description: |
${desc}
vendor: blacknon
homepage: https://github.com/blacknon/lssh
license: MIT
contents:
- src: ./README.md
dst: /usr/share/doc/${pkg}/README.md
- src: ./LICENSE.md
dst: /usr/share/doc/${pkg}/LICENSE.md
EOF
for bin in $(package_binaries "$package_id"); do
cat >> "$config_path" <<EOF
- src: ./dist/bin/${bin}
dst: /usr/bin/${bin}
file_info:
mode: 0755
EOF
if [ -f "completion/bash/${bin}" ]; then
cat >> "$config_path" <<EOF
- src: ./completion/bash/${bin}
dst: /usr/share/bash-completion/completions/${bin}
file_info:
mode: 0644
EOF
fi
if [ -f "completion/fish/${bin}.fish" ]; then
cat >> "$config_path" <<EOF
- src: ./completion/fish/${bin}.fish
dst: /usr/share/fish/vendor_completions.d/${bin}.fish
file_info:
mode: 0644
EOF
fi
if [ -f "completion/zsh/_${bin}" ]; then
cat >> "$config_path" <<EOF
- src: ./completion/zsh/_${bin}
dst: /usr/share/zsh/vendor-completions/_${bin}
file_info:
mode: 0644
EOF
fi
done
}
for package_id in full core transfer monitor sysadmin; do
create_archive "$package_id"
if [ "$GOOS" = "linux" ]; then
pkg="$(package_name "$package_id")"
create_nfpm_config "$package_id"
nfpm package --packager deb --config "dist/nfpm/${pkg}.yaml" --target "dist/packages/${pkg}_${VERSION}_$(deb_arch "$GOARCH").deb"
nfpm package --packager rpm --config "dist/nfpm/${pkg}.yaml" --target "dist/packages/${pkg}-${VERSION}-1.$(rpm_arch "$GOARCH").rpm"
fi
done
- name: Upload artifacts
uses: actions/upload-artifact@v6
with:
name: release-${{ matrix.goos }}-${{ matrix.goarch }}
path: dist/packages/*
if-no-files-found: error
overwrite: true
create-release:
needs:
- build
runs-on: ubuntu-latest
outputs:
version: ${{ steps.package_version.outputs.version }}
steps:
- uses: actions/checkout@v5
- name: Set up Go
uses: actions/setup-go@v6
with:
go-version-file: go.mod
cache: false
- name: Get version
id: package_version
shell: bash
run: |
set -euo pipefail
VERSION="$(go run ./cmd/lssh --version | grep -Eo '[0-9]+\.[0-9]+\.[0-9]+' | head -n1)"
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
- name: Create release
shell: bash
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
set -euo pipefail
gh release create "v${{ steps.package_version.outputs.version }}" \
--repo "${{ github.repository }}" \
--title "Version ${{ steps.package_version.outputs.version }}" \
--draft
upload-release:
needs:
- build
- create-release
runs-on: ubuntu-latest
steps:
- uses: actions/download-artifact@v7
with:
pattern: release-*
path: dist/packages
merge-multiple: true
- name: List build artifact files
shell: bash
run: |
set -euo pipefail
find dist/packages -maxdepth 1 -type f | sort
- name: Upload release assets
shell: bash
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
set -euo pipefail
gh release upload "v${{ needs.create-release.outputs.version }}" dist/packages/* --clobber --repo "${{ github.repository }}"