-
Notifications
You must be signed in to change notification settings - Fork 0
136 lines (119 loc) · 3.59 KB
/
release.yml
File metadata and controls
136 lines (119 loc) · 3.59 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
name: Release
on:
push:
tags:
- "v*"
permissions:
contents: write
jobs:
build:
name: Package (${{ matrix.goos }}/${{ matrix.goarch }})
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include:
- goos: windows
goarch: amd64
asset_name: hackctl_windows_amd64.zip
- goos: darwin
goarch: amd64
asset_name: hackctl_darwin_amd64.tar.gz
- goos: darwin
goarch: arm64
asset_name: hackctl_darwin_arm64.tar.gz
- goos: linux
goarch: amd64
asset_name: hackctl_linux_amd64.tar.gz
- goos: linux
goarch: arm64
asset_name: hackctl_linux_arm64.tar.gz
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: go.mod
cache: true
- name: Build metadata
id: meta
shell: bash
run: |
set -euo pipefail
echo "version=${GITHUB_REF_NAME}" >> "$GITHUB_OUTPUT"
echo "build_date=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" >> "$GITHUB_OUTPUT"
- name: Build binary
shell: bash
env:
GOOS: ${{ matrix.goos }}
GOARCH: ${{ matrix.goarch }}
CGO_ENABLED: 0
VERSION: ${{ steps.meta.outputs.version }}
COMMIT: ${{ github.sha }}
BUILD_DATE: ${{ steps.meta.outputs.build_date }}
run: |
set -euo pipefail
mkdir -p build
binary_name="hackctl"
if [ "$GOOS" = "windows" ]; then
binary_name="hackctl.exe"
fi
ldflags="-s -w"
ldflags+=" -X github.com/hackctl/hackctl/cli/internal/buildinfo.Version=${VERSION}"
ldflags+=" -X github.com/hackctl/hackctl/cli/internal/buildinfo.Commit=${COMMIT}"
ldflags+=" -X github.com/hackctl/hackctl/cli/internal/buildinfo.Date=${BUILD_DATE}"
go build -trimpath -ldflags "$ldflags" -o "build/${binary_name}" ./cmd/hackctl
- name: Package archive
shell: bash
env:
GOOS: ${{ matrix.goos }}
ASSET_NAME: ${{ matrix.asset_name }}
run: |
set -euo pipefail
rm -rf package dist
mkdir -p package dist
if [ "$GOOS" = "windows" ]; then
cp build/hackctl.exe package/hackctl.exe
(
cd package
zip -q "../dist/${ASSET_NAME}" hackctl.exe
)
else
cp build/hackctl package/hackctl
chmod +x package/hackctl
(
cd package
tar -czf "../dist/${ASSET_NAME}" hackctl
)
fi
- name: Upload packaged artifact
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.asset_name }}
path: dist/${{ matrix.asset_name }}
if-no-files-found: error
release:
name: Create GitHub release
runs-on: ubuntu-latest
needs: build
permissions:
contents: write
steps:
- name: Download packaged artifacts
uses: actions/download-artifact@v4
with:
path: dist
merge-multiple: true
- name: Generate checksums
shell: bash
run: |
set -euo pipefail
cd dist
sha256sum * > checksums.txt
- name: Publish release assets
uses: softprops/action-gh-release@v2
with:
files: dist/*
generate_release_notes: true
prerelease: ${{ contains(github.ref_name, '-') }}