-
Notifications
You must be signed in to change notification settings - Fork 0
349 lines (319 loc) · 12.3 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
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
346
347
348
349
name: Release
on:
push:
# Sequence of patterns matched against refs/tags
tags:
- 'v*' # Push events to matching v*, i.e. v1.0, v20.15.10
jobs:
pre:
name: pre
runs-on: ubuntu-latest
steps:
- name: pre1
run: |
env
exit 0
test:
name: test
runs-on: ubuntu-latest
steps:
- name: Set up Go 1.16
uses: actions/setup-go@v2
with:
go-version: 1.16
- name: Check out code into the Go module directory
uses: actions/checkout@v2
- name: Get dependencies
env:
CGO_ENABLED: 0
run: |
go get -v -t -d .
- name: Test
run: go test ./...
cr_release:
name: create_release
needs: [pre, test] #don't create a release too early
runs-on: ubuntu-latest
steps:
- name: Check out code for changelog creation
uses: actions/checkout@v2
with:
fetch-depth: 0 #otherwise only one commit is fetched
- name: Create Changelog
id: create_changelog
run: |
git fetch --tags
git tag #for debug
git log --oneline #for debug
previousTag=$(git tag --sort=-v:refname | head -2 | tail -1)
echo previous tag: $previousTag #for debug
changelog=$(git log --oneline --pretty="%s" $previousTag..HEAD)
echo changelog1: "$changelog" #for debug
changelog=$(echo "$changelog" | sed 's/^/- /')
echo changelog2: "$changelog" #for debug
echo changes since $previousTag: > ./changelog.md
echo "$changelog" >> ./changelog.md
- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # token provided by Actions, no need to set it
with:
tag_name: ${{ github.ref }}
release_name: Release ${{ github.ref }}
draft: true #we'll undraft at the end if the build step was successfull (= all assets uploaded to the release)
prerelease: false
body_path: ./changelog.md
- name: Output Release URL File
run: echo "${{ steps.create_release.outputs.upload_url }}" > release_url.txt
- name: Save Release URL File for publish
uses: actions/upload-artifact@v1
with:
name: release_url
path: ./release_url.txt
- name: Output Release ID File
run: echo "${{ steps.create_release.outputs.id }}" > release_id.txt
- name: Save Release ID File for publish
uses: actions/upload-artifact@v1
with:
name: release_id
path: ./release_id.txt
build:
needs: [cr_release]
strategy:
matrix:
os: [linux, darwin, windows]
arch: [amd64, 386, arm64, arm]
exclude:
- os: windows
arch: arm64
- os: windows
arch: arm
- os: darwin
arch: arm
- os: darwin
arch: 386
include:
- os: windows
file_extension: '.exe'
- os: windows
ci_image: ubuntu-latest
- os: linux
file_extension: ''
- os: linux
ci_image: ubuntu-latest
- os: darwin
file_extension: ''
- os: darwin
#ci_image: macos-11.0
# macos-11.0 used to be available has been transitioned into private beta :(
# https://github.com/actions/virtual-environments/issues/2486
ci_image: macos-latest
- os: darwin
no_upx: true
name: Build
runs-on: ${{ matrix.ci_image }}
env:
GOOS: ${{ matrix.os }}
GOARCH: ${{ matrix.arch }}
steps:
- name: Set up Go 1.16
uses: actions/setup-go@v2
with:
go-version: 1.16
id: go
- name: Check out code into the Go module directory
uses: actions/checkout@v2
- name: Get dependencies
env:
GOOS: ${{ matrix.os }}
GOARCH: ${{ matrix.arch }}
CGO_ENABLED: 0
run: |
go get -v -t -d .
- name: Build
run: go build -v -a -tags netgo -ldflags='-s -w -extldflags "-static"' .
- name: compress with upx
if: ${{ matrix.no_upx != true }}
run: sudo apt-get -y update && sudo apt-get -y install upx && upx ./getignore${{ matrix.file_extension }}
# 20220105: temp remove of Apple codesigning as cert needs renewal
# - name: Import darwin code-signing certificates
# if: ${{ matrix.os == 'darwin' }}
# uses: Apple-Actions/import-codesign-certs@v1
# with:
# p12-file-base64: ${{ secrets.APPLE_DEVELOPER_CERTIFICATE_P12_BASE64 }} #dev id cert as b64
# p12-password: ${{ secrets.APPLE_DEVELOPER_CERTIFICATE_PASSWORD }} #pw for cert
# - name: Sign darwin binary with Gon
# if: ${{ matrix.os == 'darwin' }}
# env:
# AC_USERNAME: ${{ secrets.AC_USERNAME }} #apple id
# AC_PASSWORD: ${{ secrets.AC_PASSWORD }} #app specific pw for apple id
# run: |
# brew tap mitchellh/gon
# brew install mitchellh/gon/gon
# gon -log-level=debug -log-json ./gon.json
# rm -f ./getignore
# unzip getignore
- name: Upload artifact
uses: actions/upload-artifact@v1
with:
name: getignore_${{ matrix.os }}_${{ matrix.arch }}${{ matrix.file_extension }}
path: ./getignore${{ matrix.file_extension }}
- name: Load Release URL File from release job
uses: actions/download-artifact@v1
with:
name: release_url
- name: Get Release File Name & Upload URL
id: get_release_info
run: |
value=`cat release_url/release_url.txt`
echo ::set-output name=upload_url::$value
- name: Upload Release Asset
id: upload-release-asset
uses: actions/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.get_release_info.outputs.upload_url }} # references get_release_info step above
asset_name: getignore_${{ matrix.os }}_${{ matrix.arch }}${{ matrix.file_extension }}
asset_path: ./getignore${{ matrix.file_extension }}
asset_content_type: application/octet-stream
cr_darwin_universal_binary:
needs: [build]
# macos-11.0 used to be available has been transitioned into private beta :(
# https://github.com/actions/virtual-environments/issues/2486
#runs-on: macos-11.0
runs-on: macos-latest
steps:
- name: Check out code
uses: actions/checkout@v2
- name: Download darwin_amd64 artifact
uses: actions/download-artifact@v1
with:
name: getignore_darwin_amd64
- name: Download darwin_arm64 artifact
uses: actions/download-artifact@v1
with:
name: getignore_darwin_arm64
- name: package darwin universal binary
run: |
lipo -create getignore_darwin_arm64/getignore getignore_darwin_amd64/getignore -output getignore
# 20220105: temp remove of Apple codesigning as cert needs renewal
# - name: Import darwin code-signing certificates
# uses: Apple-Actions/import-codesign-certs@v1
# with:
# p12-file-base64: ${{ secrets.APPLE_DEVELOPER_CERTIFICATE_P12_BASE64 }} #Apple Dev ID cert as b64
# p12-password: ${{ secrets.APPLE_DEVELOPER_CERTIFICATE_PASSWORD }} #pw for cert
# - name: Sign darwin binary with Gon
# env:
# AC_USERNAME: ${{ secrets.AC_USERNAME }} #apple id
# AC_PASSWORD: ${{ secrets.AC_PASSWORD }} #app specific pw for apple id
# run: |
# brew tap mitchellh/gon
# brew install mitchellh/gon/gon
# gon -log-level=debug -log-json ./gon.json
# rm -f ./getignore
# unzip getignore
- name: Upload artifact
uses: actions/upload-artifact@v1
with:
name: getignore_darwin_universal2
path: ./getignore
- name: Load Release URL File from release job
uses: actions/download-artifact@v1
with:
name: release_url
- name: Get Release File Name & Upload URL
id: get_release_info
run: |
value=`cat release_url/release_url.txt`
echo ::set-output name=upload_url::$value
- name: Upload Release Asset
id: upload-release-asset
uses: actions/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.get_release_info.outputs.upload_url }} # references get_release_info step above
asset_name: getignore_darwin_universal2
asset_path: ./getignore
asset_content_type: application/octet-stream
build_containers:
#needs: [build]
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v2
- name: Split tag string into semantic version parts
id: semver
run: |
git fetch --tags
git tag #for debug
export vcur=$(git tag --sort=-v:refname | head -1 | sed 's/v//1')
export vmajor=$(echo $vcur | cut -d. -f1)
export vminor=$(echo $vcur | cut -d. -f2)
export vpatch=$(echo $vcur | cut -d. -f3)
echo ::set-output name=vcur::$vcur
echo ::set-output name=vmajor::$vmajor
echo ::set-output name=vminor::$vminor
echo ::set-output name=vpatch::$vpatch
echo version: $vcur
echo version major: $vmajor
echo version minor: $vminor
echo version patch: $vpatch
- name: Prepare docker-buildx
run: |
docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
docker buildx create --name mybuilder
docker buildx ls #for debug
docker buildx inspect --bootstrap
docker buildx use mybuilder
- name: Docker login
env:
DOCKER_USER: chko
DOCKER_PASS: ${{ secrets.DOCKER_PASS }}
run: |
docker login -u "$DOCKER_USER" -p "$DOCKER_PASS"
- name: Build and Push container images with docker-buildx
env:
vcur: ${{ steps.semver.outputs.vcur }}
vmajor: ${{ steps.semver.outputs.vmajor }}
vminor: ${{ steps.semver.outputs.vminor }}
vpatch: ${{ steps.semver.outputs.vpatch }}
run: |
docker buildx inspect #for debug
echo version: $ver - major: $vmajor - minor: $vminor - patch: $vpatch #for debug
destrepo=chko/getignore
docker buildx build -t "$destrepo:latest" -t "$destrepo:$vcur" -t "$destrepo:$vmajor" --platform linux/amd64,linux/386,linux/arm64,linux/arm/v7,linux/arm/v6 --push .
docker buildx stop
- name: Update container repo README
env:
#exact env var names for docker-pushrm
DOCKER_USER: chko
DOCKER_PASS: ${{ secrets.DOCKER_PASS }}
run: |
# download latest docker-pushrm release from github
# (because we keep the release that this workflow creates drafted until the end of the workflow run the version we're downloading is NOT the one we're currently releasing)
export FILENAME=docker-pushrm_linux_amd64 && export DESTDIR=. && DOWNLOAD_URL=$(curl --silent --fail --show-error https://api.github.com/repos/christian-korneck/docker-pushrm/releases/latest | jq -r ".assets | map(select(.name == \"$FILENAME\"))[0].browser_download_url") && curl --silent --fail --show-error -L $DOWNLOAD_URL -o "$DESTDIR/docker-pushrm" && chmod +rx "$DESTDIR/docker-pushrm"
# this automatically uses README.md
./docker-pushrm --short "getignore - get gitignore templates quickly in the shell for a wide variety of languages" chko/getignore
undraft_release:
needs: [build, build_containers, cr_darwin_universal_binary] #only undraft the release when assets were uploaded
runs-on: ubuntu-latest
steps:
- name: Load Release ID File from release job
uses: actions/download-artifact@v1
with:
name: release_id
- name: Get Release ID
id: get_release_id_info
run: |
value=`cat release_id/release_id.txt`
echo ::set-output name=release_id::$value
- name: Undraft release
id: undraft_release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
RELEASE_ID: ${{ steps.get_release_id_info.outputs.release_id }} # references other step
run: |
curl --verbose --fail --show-error --location --request PATCH "https://api.github.com/repos/$GITHUB_REPOSITORY/releases/$RELEASE_ID" --header "Authorization: token $GITHUB_TOKEN" --header 'Content-Type: application/json' --header 'Accept: application/vnd.github.everest-preview+json' --data-raw '{"draft": false}'