-
Notifications
You must be signed in to change notification settings - Fork 9
255 lines (217 loc) · 8.68 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
name: Release
on:
workflow_dispatch:
inputs:
version:
description: "Version: Tag, build and release. (e.g. 1.2.3 or 1.2.4-rc)"
required: true
force:
description: "Enter 'force-reuse-tag', if you want to change an existing git tag. CAUTION!"
required: false
default: ""
jobs:
release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
# Clone all history to ensure goreleaser can create proper changelog.
fetch-depth: 0
- name: Set Version
run: |
VERSION="${{ github.event.inputs.version }}"
FORCE="${{ github.event.inputs.force }}"
echo "Inputs: version: $VERSION, force: $FORCE"
git fetch origin --tags
[[ "$FORCE" == "force-reuse-tag" ]] && GIT_ARG="--force" || GIT_ARG=""
source release/source.sh
echo "GORELEASER_PREVIOUS_TAG=$PROTOCURL_RELEASED_VVERSION" >> $GITHUB_ENV
set -x
git tag $GIT_ARG "v${{ github.event.inputs.version }}"
git push --tags $GIT_ARG
set +x
source release/source.sh
- name: Install Go and Goreleaser
run: |
sudo apt-get -q update
sudo apt-get -q install -y jq zip unzip curl
source release/source.sh
sudo ./release/20-install-go.sh "$GO_DOWNLOAD_URL" this-is-not-my-development-computer
wget -q "$GORELEASER_DOWNLOAD_URL"
sudo dpkg -i goreleaser*.deb
rm -f *.deb *.gz
- name: Delete GitHub Release (if force)
if: github.event.inputs.force == 'force-reuse-tag'
env:
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
run: |
echo "Deleting existing release, if it exists"
gh release delete -y "v${{ github.event.inputs.version }}" || true
- name: Build Archive
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
export PATH=$PATH:/usr/local/go/bin
export GORELEASER_CURRENT_TAG="v${{ github.event.inputs.version }}"
export GORELEASER_PREVIOUS_TAG="${{ env.GORELEASER_PREVIOUS_TAG }}"
./release/30-build-go-archive.sh
- name: DockerHub Login
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Setup QEMU for docker buildx
uses: docker/setup-qemu-action@v3
- name: Setup Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Check DockerHub image does not already exist (except if force or snapshot)
run: |
source release/source.sh
if [[ "${{ github.event.inputs.force }}" == "force-reuse-tag" || "$SNAPSHOT" == "true" ]]; then
echo "No check needed."
exit 0
fi
URL="https://hub.docker.com/v2/repositories/qaware/protocurl/tags/${{ github.event.inputs.version }}"
JSON="$(curl -s "$URL")"
if [[ "$JSON" == *"\"creator\""* ]]; then
echo "ERROR: qaware/protocurl:${{ github.event.inputs.version }} already exists on DockerHub!"
echo "If you know what you are doing and this is intentional, then you may set force -> 'force-reuse-tag'."
exit 1
fi
echo "OK. Building and pushing the docker image would not overwrite an existing tag."
- name: Prepare and Decide if qaware/protocurl:latest should be published
run: |
./release/40-generate-Dockerfile.sh
# https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#setting-an-environment-variable
echo "publish_latest=false" >> $GITHUB_ENV
source release/source.sh
if [[ "$SNAPSHOT" == "false" ]]; then
TAG=qaware/protocurl:latest
echo "$TAG will be set"
echo "publish_latest=true" >> $GITHUB_ENV
fi
- name: DockerHub Build and Release (with latest)
uses: docker/build-push-action@v5
if: env.publish_latest == 'true'
with:
platforms: linux/amd64,linux/arm64
build-args: VERSION=${{ github.event.inputs.version }}
tags: qaware/protocurl:${{ github.event.inputs.version }}, qaware/protocurl:latest
file: release/generated.Dockerfile
push: true
context: .
- name: DockerHub Build and Release (without latest)
uses: docker/build-push-action@v5
if: env.publish_latest == 'false'
with:
platforms: linux/amd64,linux/arm64
build-args: VERSION=${{ github.event.inputs.version }}
tags: qaware/protocurl:${{ github.event.inputs.version }}
file: release/generated.Dockerfile
push: true
context: .
- name: Test Release
run: |
git fetch --tags origin
export PROTOCURL_RELEASE_VERSION="${{ github.event.inputs.version }}"
./test/suite/test.sh "$PWD"
- name: Security Scan
uses: crazy-max/ghaction-container-scan@v3
continue-on-error: true
with:
image: qaware/protocurl:${{ github.event.inputs.version }}
severity_threshold: MEDIUM
dockerfile: release/generated.Dockerfile
post-release-test-windows:
runs-on: windows-latest
needs: [ release ]
steps:
- uses: actions/checkout@v4
- name: Choco Install curl
uses: crazy-max/ghaction-chocolatey@v3
with:
args: install curl -y --limit-output
- name: Download release
env:
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
run: |
$ErrorActionPreference = "Stop"
Write-Output "Downloading release from Github ..."
gh release download v${{ github.event.inputs.version }} --pattern '*windows*amd64*.zip'
Write-Output "working dir after download"
ls
Write-Output "Attempting to extract"
Expand-Archive *.zip -DestinationPath my-protocurl
Write-Output "After extract"
ls my-protocurl
- uses: actions/setup-node@v4
with:
node-version: "17.7.2"
- name: Start test server
run: |
$ErrorActionPreference = "Stop"
cd test
& ".\servers\native-start-server.ps1"
- name: Test extracted release and global installation
run: |
$ErrorActionPreference = "Stop"
& ".\test\suite\native-tests.ps1" "my-protocurl" ".exe" "localDirTests"
post-release-test-mac:
runs-on: macos-latest
needs: [ release ]
steps:
- uses: actions/checkout@v4
- name: Setup
run: "brew install powershell"
- uses: actions/setup-node@v4
with:
node-version: "17.7.2"
- name: Download release
env:
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
run: |
echo "Downloading release from Github ..."
ARCH="$(uname -m |
sed "s/x86_64/amd64/g" |
sed "s/x86_32/386/g" |
sed "s/aarch_64/arm64/g")"
echo "Arch: $ARCH"
gh release download v${{ github.event.inputs.version }} --pattern "*darwin*$ARCH*.zip"
echo "Working dir after Download"
ls
echo "Attempting to extract"
unzip *.zip -d my-protocurl
echo "After extract"
ls my-protocurl
- name: Start test server
run: |
cd test
pwsh servers/native-start-server.ps1
- name: Test extracted release and global installation
run: |
pwsh test/suite/native-tests.ps1 "my-protocurl" "" "localDirTests"
post-release-test-linux:
runs-on: ubuntu-latest
needs: [ release ]
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-node@v4
with:
node-version: "17.7.2"
- name: Start test server
run: |
cd test
pwsh servers/native-start-server.ps1
- name: "Run tests for linux package formats: deb, apk"
run: |
ARCH="$(uname -m |
sed "s/x86_64/amd64/g" |
sed "s/x86_32/386/g" |
sed "s/aarch_64/arm64/g")"
URL_NO_EXT="https://github.com/qaware/protocurl/releases/download/v${{github.event.inputs.version}}/protocurl_${{github.event.inputs.version}}_linux_${ARCH}"
docker run --network host -v $PWD/test:/home/test alpine:latest sh -c \
"cd home; apk add --no-cache bash && bash ./test/suite/linux/install-test-remove.sh alpine .apk $URL_NO_EXT"
docker run --network host -v $PWD/test:/home/test debian:11-slim bash -c \
"cd home; ./test/suite/linux/install-test-remove.sh debian .deb $URL_NO_EXT"