-
-
Notifications
You must be signed in to change notification settings - Fork 5
243 lines (228 loc) · 6.85 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
name: Build and release
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
on:
push:
tags:
- "*"
jobs:
prepare:
runs-on: ubuntu-latest
name: Prepare
outputs:
branch: ${{ steps.branch.outputs.name }}
version: ${{ steps.version.outputs.tag }}
strategy: ${{ steps.set-matrix.outputs.matrix }}
steps:
- name: Setup matrix
id: set-matrix
run: echo "matrix=[{\"runner\":\"ubuntu-latest\",\"os\":\"linux\",\"arch\":\"amd64\"},{\"runner\":\"ubuntu-latest\",\"os\":\"linux\",\"arch\":\"arm64\"},{\"runner\":\"macos-latest\",\"os\":\"darwin\",\"arch\":\"amd64\"},{\"runner\":\"macos-latest\",\"os\":\"darwin\",\"arch\":\"arm64\"}]" >> "$GITHUB_OUTPUT"
- name: Extract branch name
id: branch
run: echo "name=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" >> "$GITHUB_OUTPUT"
- name: Extract version
id: version
run: echo "tag=${GITHUB_REF#refs/*/}" >> "$GITHUB_OUTPUT"
build:
runs-on: ${{ matrix.runner }}
name: Build ${{ matrix.os }}/${{ matrix.arch }}
needs:
- prepare
strategy:
matrix:
include: ${{fromJson(needs.prepare.outputs.strategy)}}
env:
CGO: 0
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- run: git fetch --force --tags
- name: Install Go
uses: actions/setup-go@v4
with:
go-version-file: 'go.mod'
- name: Set CGO
if: ${{ matrix.os == 'darwin' }}
run: echo "CGO=1" >> $GITHUB_ENV
- name: Build
run: |
GOOS=${{ matrix.os }} GOARCH=${{ matrix.arch }} CGO_ENABLED=${{ env.CGO }} go build -ldflags "-s -w -X 'main.version=${{ needs.prepare.outputs.version }}'" -o "$GITHUB_WORKSPACE"/dist/dl-${{ matrix.os }}-${{ matrix.arch }} .
- name: Upload artifact
uses: actions/upload-artifact@v3
with:
path: dist/dl-${{ matrix.os }}-${{ matrix.arch }}
name: bin
retention-days: 1
archives:
name: Packing ${{ matrix.os }}-${{ matrix.arch }}.tar.gz
runs-on: ubuntu-latest
needs:
- build
- prepare
strategy:
matrix:
include: ${{fromJson(needs.prepare.outputs.strategy)}}
steps:
- name: Download artifacts
uses: actions/download-artifact@v3
with:
name: bin
path: dist
- name: Create archives
run: |
cd "$GITHUB_WORKSPACE"/dist &&
mv dl-${{ matrix.os }}-${{ matrix.arch }} dl &&
chmod a+x dl &&
tar -czvf dl-${{ needs.prepare.outputs.version }}-${{ matrix.os }}-${{ matrix.arch }}.tar.gz dl
- name: Upload artifact
uses: actions/upload-artifact@v3
with:
path: dist/dl-${{ needs.prepare.outputs.version }}-${{ matrix.os }}-${{ matrix.arch }}.tar.gz
name: releases
retention-days: 1
packages:
name: Create ${{ matrix.arch }}.${{ matrix.type }}
runs-on: ubuntu-latest
needs:
- build
- prepare
strategy:
matrix:
package: [ deb, archlinux, rpm ]
arch: [ amd64, arm64 ]
include:
- type: pkg.tar.zst
package: archlinux
- type: deb
package: deb
- type: rpm
package: rpm
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Download artifacts
uses: actions/download-artifact@v3
with:
name: bin
path: bin
- name: Prepare binary
run: |
cd "$GITHUB_WORKSPACE"/bin &&
mv dl-linux-${{ matrix.arch }} dl &&
chmod a+x dl
- name: Download nFPM
run: |
cd "$GITHUB_WORKSPACE" &&
wget https://github.com/goreleaser/nfpm/releases/download/v2.35.2/nfpm_2.35.2_Linux_x86_64.tar.gz &&
tar -xzvf nfpm_2.35.2_Linux_x86_64.tar.gz
- name: Create package
env:
PKG_VERSION: ${{ needs.prepare.outputs.version }}
PKG_ARCH: ${{ matrix.arch }}
run: |
cd "$GITHUB_WORKSPACE" &&
mkdir -p dist &&
./nfpm package -p ${{ matrix.package }} -t dist/dl-${{ needs.prepare.outputs.version }}-linux-${{ matrix.arch }}.${{ matrix.type }}
- name: Upload artifact
uses: actions/upload-artifact@v3
with:
path: dist/
name: releases
retention-days: 1
checksum:
name: Create checksum
runs-on: ubuntu-latest
needs:
- packages
- archives
steps:
- name: Download artifacts
uses: actions/download-artifact@v3
with:
name: releases
- name: Generate checksum
uses: jmgilman/actions-generate-checksum@v1
with:
patterns: |
*.tar.gz
*.pkg.tar.zst
*.deb
*.rpm
- name: Upload artifact
uses: actions/upload-artifact@v3
with:
name: releases
path: checksum.txt
retention-days: 1
release:
name: Release
runs-on: ubuntu-latest
needs:
- checksum
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Changelog
uses: varrcan/generate-pretty-changelog-action@v1
- name: Download artifacts
uses: actions/download-artifact@v3
with:
name: releases
- name: Release
uses: softprops/action-gh-release@v1
with:
prerelease: ${{ contains(github.ref, '-rc') }}
body_path: ${{ github.workspace }}/CHANGELOG.md
files: |
checksum.txt
*.tar.gz
*.pkg.tar.zst
*.deb
*.rpm
aur-publish:
name: AUR Publish
runs-on: ubuntu-latest
environment: production
if: "!contains(github.ref, '-rc')"
needs:
- release
steps:
- name: Publish AUR package
uses: ATiltedTree/create-aur-release@v1
with:
package_name: dl-bin
commit_username: "dlbot"
commit_email: dl@varme.pw
ssh_private_key: ${{ secrets.AUR_KEY }}
fury-publish:
name: Fury publish ${{ matrix.arch }}.${{ matrix.type }}
runs-on: ubuntu-latest
environment: production
if: "!contains(github.ref, '-rc')"
needs:
- release
- prepare
strategy:
matrix:
arch: [ amd64, arm64 ]
type: [ deb, rpm ]
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Download artifacts
uses: actions/download-artifact@v3
with:
name: releases
path: dist
- name: Publish Fury package
env:
FURY_TOKEN: ${{ secrets.FURY_TOKEN }}
run: |
bash ./.github/scripts/fury-upload.sh dl-${{ needs.prepare.outputs.version }}-linux-${{ matrix.arch }}.${{ matrix.type }}