-
Notifications
You must be signed in to change notification settings - Fork 3
/
action.yml
177 lines (175 loc) · 7.34 KB
/
action.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
# Copyright (c) 2021 SpyderMix Ltd.
name: 'Wireleap component test/build/staging/release action'
description: 'Run unit tests, build binaries, upload to staging location and perform tagged release'
author: 'Anton Pyrogovskyi <[email protected]>'
inputs:
token:
description: 'Token to access private repos and dispatch gh-test workflow'
required: true
ssh_key:
description: 'SSH private key for artifact upload to staging location'
required: true
upload_target:
description: 'Where to upload artifacts to (ssh/scp-style path: user@host:dir/)'
required: true
gpg_key:
description: 'GPG key for signing release binaries'
required: false
default: 'none'
runs:
using: 'composite'
steps:
- name: Fix https://github.com/actions/checkout/issues/290
run: "cd ${{ github.workspace }} && git fetch --tags --force"
shell: sh
- name: Set up private repo access
env:
GITHUB_TOKEN: ${{ inputs.token }}
run: "cat ${{ github.action_path }}/gitconfig-template | envsubst > ${{ github.action_path }}/gitconfig"
shell: sh
- name: Output version
run: "${{ github.workspace }}/contrib/gitversion.sh"
shell: sh
- name: Get dependencies, build and run unit tests
env:
DOCKER_OPTS: "-v ${{ github.action_path }}/gitconfig:/root/.gitconfig"
run: "${{ github.workspace }}/contrib/docker/run-tests.sh"
shell: sh
- name: Build binaries
env:
DOCKER_OPTS: "-v ${{ github.action_path }}/gitconfig:/root/.gitconfig"
run: "${{ github.workspace }}/contrib/docker/build-bin.sh build"
shell: sh
- name: Import GPG key
run: |
if [ "${{ inputs.gpg_key }}" = 'none' ]; then
echo '### No GPG key defined to sign release, aborting.'
exit 1
fi
echo "${{ inputs.gpg_key }}" | gpg --batch --import -
shell: sh
- name: Sign binaries
run: |
for i in build/*; do
"${{ github.action_path }}/helpers/gen-signature.sh" "$i"
done
shell: sh
- name: Set up SSH
run: |
mkdir -p "$HOME/.ssh"
echo "${{ inputs.ssh_key }}" > "$HOME/.ssh/id_rsa"
chmod go-rwx "$HOME/.ssh/id_rsa"
cp ${{ github.action_path }}/known_hosts "$HOME/.ssh/known_hosts"
shell: sh
- name: Deploy to staging location
run: "rsync -e 'ssh -o RequestTTY=no' -WavK build/ ${{ inputs.upload_target }}"
shell: sh
- name: Trigger gh-test workflow and wait for it to succeed
run: |
echo '### Triggering gh-test workflow ...'
curl -sS \
-H 'Accept: application/vnd.github.v3+json' \
-H "Authorization: token ${{ inputs.token }}" \
-X POST \
-d '{"ref":"master"}' \
'https://api.github.com/repos/wireleap/gh-test/actions/workflows/main.yml/dispatches'
sleep 10 # wait for it to "appear"
while ! curl -sS \
-H 'Accept: application/vnd.github.v3+json' \
-H "Authorization: token ${{ inputs.token }}" \
'https://api.github.com/repos/wireleap/gh-test/actions/workflows/main.yml/runs?per_page=1&event=workflow_dispatch' \
| jq --exit-status '.workflow_runs | .[0] | .status == "completed"' > /dev/null
do
echo '### Waiting for gh-test workflow to complete ...'
sleep 10
done
if curl -sS \
-H 'Accept: application/vnd.github.v3+json' \
-H "Authorization: token ${{ inputs.token }}" \
'https://api.github.com/repos/wireleap/gh-test/actions/workflows/main.yml/runs?per_page=1&event=workflow_dispatch' \
| jq --exit-status '.workflow_runs | .[0] | .conclusion == "success"' > /dev/null
then
echo '### Integration tests succeeded!'
else
echo '### Integration tests failed!'
exit 1
fi
# remove intermediate artifacts
rm -rf build
shell: sh
- name: Build, sign & upload release binaries
env:
DOCKER_OPTS: "-v ${{ github.action_path }}/gitconfig:/root/.gitconfig"
run: |
case "${{ github.event_name }}+${{ github.ref }}" in
'push+refs/tags/v'*) true ;;
*) echo '### No release tag pushed -- not a release build.'; exit 0 ;;
esac
if [ "${{ github.repository }}" = 'wireleap/client' ]; then
BUILD_USER="$(id -u)" \
BUILD_GROUP="$(id -g)" \
"${{ github.action_path }}/helpers/build-release-bin.sh" \
"${{ github.workspace }}" \
"${{ github.workspace }}/build" \
all
else
BUILD_USER="$(id -u)" \
BUILD_GROUP="$(id -g)" \
"${{ github.action_path }}/helpers/build-release-bin.sh" \
"${{ github.workspace }}" \
"${{ github.workspace }}/build" \
linux
BUILD_USER="$(id -u)" \
BUILD_GROUP="$(id -g)" \
"${{ github.action_path }}/helpers/build-release-bin.sh" \
"${{ github.workspace }}" \
"${{ github.workspace }}/build" \
darwin
fi
rm -rf ~/.gnupg
# create initial release
tag=${GITHUB_REF#refs/*/}
version=${tag#v}
output="$(curl -sS \
-H 'Accept: application/vnd.github.v3+json' \
-H "Authorization: token ${{ github.token }}" \
-X POST \
-d "{
\"tag_name\":\"$tag\",
\"draft\":true,
\"name\":\"$($GITHUB_WORKSPACE/contrib/gitversion.sh)\",
\"body\":\"The changelog for this version is located [here](https://github.com/${{ github.repository }}/blob/master/changelogs/$version.md).\"
}" \
'https://api.github.com/repos/${{ github.repository }}/releases'
)"
url="$( echo "$output" | jq -r '.url' )"
upload_url="$( echo "$output" | jq -r '.upload_url | split("{") | first' )"
[ "$upload_url" != 'null' ] || { echo '### null upload_url, aborting. query output:'; echo "$output"; exit 1; }
# upload release assets (binaries and .hash files)
for f in "${{ github.workspace }}/build/"*; do
name="$(basename "$f")"
if [ "${f##*.}" = 'hash' ]; then
ct='text/plain'
else
ct='application/octet-stream'
bname="$( echo "$name" | cut -d'_' -f1 )"
fi
curl -sS \
-H 'Accept: application/vnd.github.v3+json' \
-H "Authorization: token ${{ github.token }}" \
-H "Content-Type: $ct" \
-X POST \
--data-binary "@${f}" \
"$upload_url?name=$(basename "$f")&label=$(basename "$f")"
done
# undraft release
curl -sS \
-H 'Accept: application/vnd.github.v3+json' \
-H "Authorization: token ${{ github.token }}" \
-X PATCH \
-d "{\"tag_name\":\"$tag\",\"draft\":false}" \
"$url"
shell: sh
- name: Clean up private repo gitconfig
run: "shred -u ${{ github.action_path }}/gitconfig"
shell: sh