-
Notifications
You must be signed in to change notification settings - Fork 0
247 lines (229 loc) · 7.46 KB
/
release.yml
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
name: Release
on: push
env:
APP: usql
VER: ${{ github.ref_name }}
GO_VERSION: stable
jobs:
build_for_linux:
name: Build for Linux
runs-on: ubuntu-24.04
strategy:
fail-fast: false
matrix:
arch: [amd64, arm, arm64]
steps:
- name: Install build dependencies
run: |
sudo apt-get -qq update
sudo apt-get install -y \
build-essential \
qemu-user \
gcc-arm-linux-gnueabihf \
g++-arm-linux-gnueabihf \
gcc-aarch64-linux-gnu \
g++-aarch64-linux-gnu \
libstdc++6-armhf-cross \
libstdc++6-arm64-cross \
libc6-dev-armhf-cross \
libc6-dev-arm64-cross \
file
- name: Checkout
uses: actions/checkout@v4
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
- name: Build ${{ matrix.arch }}
run: |
./build.sh -v $VER -a ${{ matrix.arch }}
- name: Build ${{ matrix.arch }} (static)
if: matrix.arch != 'arm'
run: |
./build.sh -v $VER -a ${{ matrix.arch }} -s
- name: Archive artifacts
uses: actions/upload-artifact@v4
with:
name: dist-linux-${{ matrix.arch }}
path: build/linux/**/*
if-no-files-found: error
build_for_macos:
name: Build for macOS
runs-on: macos-latest
strategy:
matrix:
arch: [amd64, arm64]
steps:
- name: Install build dependencies
run: |
brew install coreutils
- name: Checkout
uses: actions/checkout@v4
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
- name: Build ${{ matrix.arch }}
run: |
./build.sh -v $VER -a ${{ matrix.arch }}
- name: Archive artifacts
uses: actions/upload-artifact@v4
with:
name: dist-darwin-${{ matrix.arch }}
path: build/darwin/**/*
if-no-files-found: error
build_for_macos_universal:
name: Build for macOS (universal)
needs:
- build_for_macos
runs-on: macos-latest
steps:
- name: Install build dependencies
run: |
brew install coreutils
- name: Download artifacts
uses: actions/download-artifact@v4
- name: Build universal
run: |
if [ "$VER" = "master" ]; then
VER=0.0.0-dev
fi
export WORKDIR=$PWD/build/darwin/universal/$VER
mkdir -p $WORKDIR
gtar -jxvf dist-darwin-amd64/*/*/*.tar.bz2 -C $WORKDIR $APP
gtar -jxvf dist-darwin-amd64/*/*/*.tar.bz2 -C $WORKDIR LICENSE
mv $WORKDIR/$APP $WORKDIR/$APP-amd64
gtar -jxvf dist-darwin-arm64/*/*/*.tar.bz2 -C $WORKDIR $APP
mv $WORKDIR/$APP $WORKDIR/$APP-arm64
file $WORKDIR/$APP-{amd64,arm64}
lipo -create -output $WORKDIR/$APP $WORKDIR/$APP-amd64 $WORKDIR/$APP-arm64
chmod +x $WORKDIR/$APP
file $WORKDIR/$APP
rm $WORKDIR/$APP-{amd64,arm64}
sudo /usr/sbin/purge
gtar -C $WORKDIR -cjf $WORKDIR/$APP-${VER#v}-darwin-universal.tar.bz2 $APP LICENSE
ls -alh $WORKDIR/*
sha256sum $WORKDIR/*
- name: Archive artifacts
uses: actions/upload-artifact@v4
with:
name: dist-darwin-universal
path: build/darwin/**/*
if-no-files-found: error
build_for_windows:
name: Build for Windows
runs-on: windows-latest
steps:
- name: Install build dependencies
run: choco install zip
- name: Checkout
uses: actions/checkout@v4
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
- name: Build amd64
shell: bash
run: |
./build.sh -v $VER
- name: Archive artifacts
uses: actions/upload-artifact@v4
with:
name: dist-windows
path: build/windows/**/*
if-no-files-found: error
draft_release:
name: Draft Release
needs:
- build_for_linux
- build_for_macos
- build_for_macos_universal
- build_for_windows
runs-on: ubuntu-24.04
steps:
- name: Download artifacts
uses: actions/download-artifact@v4
- name: Extract artifacts
run: |
mkdir /tmp/scan
mkdir scan
for i in dist-*/*/*/*.tar.bz2; do
name=$(basename $i|cut -d- -f1)
ver=$(sed -e 's/\.tar\.bz2$//' <<< $(basename $i)|cut -d- -f2-)
echo "extracting $i ($name $ver)"
tar -C /tmp/scan -jv -f $i -x $name
hash=$(sha256sum /tmp/scan/$name|awk '{print $1}')
mv /tmp/scan/$name ./scan/$name-$ver-${hash:0:8}
done
for i in dist-*/*/*/*.zip; do
name=$(basename $i|cut -d- -f1)
ver=$(sed -e 's/\.zip$//' <<< $(basename $i)|cut -d- -f2-)
echo "extracting $i ($name $ver)"
unzip -d /tmp/scan $i $name.exe
hash=$(sha256sum /tmp/scan/$name.exe|awk '{print $1}')
mv /tmp/scan/$name.exe ./scan/$name-$ver-${hash:0:8}.exe
done
file ./scan/*
sha256sum ./scan/*
- name: Submit to VirusTotal
id: virustotal
uses: crazy-max/ghaction-virustotal@v4
with:
vt_api_key: ${{ secrets.VIRUSTOTAL_API_KEY }}
request_rate: 4
files: |
./scan/*
- name: Generate Release Notes
id: generate_release_notes
uses: softprops/action-gh-release@v2
if: startsWith(github.ref, 'refs/tags/v')
with:
name: ${{ env.APP }} ${{ env.VER }}
draft: true
generate_release_notes: true
files: |
dist-*/*/*/*.tar.bz2
dist-*/*/*/*.zip
- name: Add VirusTotal Info to Release Notes
if: startsWith(github.ref, 'refs/tags/v')
run: |
# github api url
url=https://api.github.com/repos/${GITHUB_REPOSITORY}/releases/${{ steps.generate_release_notes.outputs.id }}
echo "url: $url"
# get release notes
release=$(
curl \
-s \
-L \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
-H "X-GitHub-Api-Version: 2022-11-28" \
$url
)
tag_name=$(jq -r .tag_name <<< "$release")
target_commitish=$(jq -r .target_commitish <<< "$release")
body=$(jq -r .body <<< "$release")
echo "tag_name: $tag_name target_commitish: $target_commitish"
# append virustotal details to release notes
nl=$'\n'
body+="$nl$nl[VirusTotal](https://www.virustotal.com) analysis:$nl"
while read -r -d, line; do
name=$(sed -e 's/^\.\/scan\/\([^=]\+\)=.*/\1/' <<< "$line")
vturl=$(sed -e 's/.*=\(https.*\)/\1/' <<< "$line")
body+="* [$name]($vturl)$nl"
done <<< "${{ steps.virustotal.outputs.analysis }}"
echo -e "body:\n$body"
# update release notes
export tag_name target_commitish body
curl \
-s \
-L \
-X PATCH \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
-H "X-GitHub-Api-Version: 2022-11-28" \
--variable '%tag_name' \
--varable '%target_commitish' \
--variable '%body' \
--expand-data '{"tag_name": "{{tag_name:json}}", "body": "{{body:trim:json}}"}' \
$url