-
Notifications
You must be signed in to change notification settings - Fork 46
226 lines (192 loc) · 8.08 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
---
# Copyright 2022
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
name: release
# yamllint disable-line rule:truthy
on:
release:
types: [published]
workflow_dispatch:
env:
BIN_NAME: dcld
jobs:
checks:
name: verify release
runs-on: ubuntu-latest
outputs:
included: ${{ steps.release_info.outputs.included }}
matrix_os: ${{ steps.release_info.outputs.matrix_os }}
upload_url: ${{ steps.release_info.outputs.upload_url }}
steps:
- uses: actions/checkout@v2
- name: Get current version
id: current_version
run: |
git fetch --all --tags
tag="$(git describe --tags --exact-match)"
echo "::set-output name=version::${tag#v}"
shell: bash
- name: Get release info
id: release_info
run: |
release_info="$(curl -s https://api.github.com/repos/${{ github.repository }}/releases \
| jq '.[] | select(.tag_name == "v${{ steps.current_version.outputs.version }}")')"
echo "::set-output name=release_info::$release_info"
echo "$release_info"
asset_bin_url="$(echo "$release_info" \
| jq -r '.assets[] | select(.name | match("^${{ env.BIN_NAME }}$")) | .browser_download_url')"
echo "$asset_bin_url"
asset_ubuntu_tgz_url="$(echo "$release_info" \
| jq -r '.assets[] | select(.name | match("^${{ env.BIN_NAME }}.ubuntu.tar.gz$")) | .browser_download_url')"
echo "$asset_ubuntu_tgz_url"
asset_cosmovisor_url="$(echo "$release_info" \
| jq -r '.assets[] | select(.name | match("^cosmovisor$")) | .browser_download_url')"
echo "$asset_bin_url"
asset_service_url="$(echo "$release_info" \
| jq -r '.assets[] | select(.name | match("^cosmovisor.service$")) | .browser_download_url')"
echo "$asset_service_url"
asset_deploy_script_url="$(echo "$release_info" \
| jq -r '.assets[] | select(.name | match("^run_dcl_node$")) | .browser_download_url')"
echo "$asset_deploy_script_url"
asset_macos_tgz_url="$(echo "$release_info" \
| jq -r '.assets[] | select(.name | match("^${{ env.BIN_NAME }}.macos.tar.gz$")) | .browser_download_url')"
echo "$asset_macos_tgz_url"
upload_url="$(echo "$release_info" | jq -r '.upload_url')"
echo "::set-output name=upload_url::$upload_url"
echo "$upload_url"
# build json string to use later as a job matrix
included=()
if [[ -z "$asset_bin_url" || -z "$asset_ubuntu_tgz_url" || -z "$asset_cosmovisor_url" || -z "$asset_service_url" || -z "$asset_deploy_script_url" ]]; then
# os|bin-url|tgz-url|service-file-url|deploy-script-url|tgz-suffix
included+=("ubuntu-20.04|$asset_bin_url|$asset_ubuntu_tgz_url|$asset_cosmovisor_url|$asset_service_url|$asset_deploy_script_url|.ubuntu.tar.gz")
fi
if [[ -z "$asset_macos_tgz_url" ]]; then
# bin, service file and deploy script are not considered for macos job
included+=("macos-14|-||-|-|-|.macos.tar.gz")
fi
matrix_os="$(jq -ncR '
(input | split(" ")) |
[ .[] | split("|") | .[0] ] | if .|length > 0 then . else empty end
' <<<"${included[*]}"
)"
echo "::set-output name=matrix_os::$matrix_os"
echo "$matrix_os"
if [[ -n "$matrix_os" ]]; then
included_json="$(jq -ncR '
(input | split(" ")) |
[ .[] | split("|") |
{"os": .[0], "bin": .[1] | length, "tgz": .[2] | length, "cosmovisor": .[3] | length, "service": .[4] | length, "deploy_script": .[5] | length, "tgz_name_suffix": .[6]} ]
' <<<"${included[*]}"
)"
echo "::set-output name=included::$included_json"
echo "$included_json"
fi
shell: bash
- name: check release published
if: ${{ !steps.release_info.outputs.release_info }}
run: exit 1
release:
name: Release
needs: checks
if: needs.checks.outputs.matrix_os
strategy:
matrix:
os: ${{ fromJson(needs.checks.outputs.matrix_os) }}
include: ${{ fromJson(needs.checks.outputs.included) }}
runs-on: ${{ matrix.os }}
steps:
- name: Set up Go 1.x
uses: actions/setup-go@v4
with:
go-version: ^1.20
- name: Check out code into the Go module directory
uses: actions/checkout@v2
- uses: actions/cache@v3
with:
path: |
~/.cache/go-build
~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: build application binary
if: ${{ !matrix.bin || !matrix.tgz }}
run: |
make build
build/${{ env.BIN_NAME }} version
tar czf build/${{ env.BIN_NAME }}${{ matrix.tgz_name_suffix }} -C build ${{ env.BIN_NAME }}
shell: bash
- name: upload to GitHub (application binary)
if: ${{ !matrix.bin }}
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ needs.checks.outputs.upload_url }}
asset_path: build/${{ env.BIN_NAME }}
asset_name: ${{ env.BIN_NAME }}
asset_content_type: application/octet-stream # TODO check for less generic type
- name: upload to GitHub (archived application binary)
if: ${{ !matrix.tgz }}
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ needs.checks.outputs.upload_url }}
asset_path: build/${{ env.BIN_NAME }}${{ matrix.tgz_name_suffix }}
asset_name: ${{ env.BIN_NAME }}${{ matrix.tgz_name_suffix }}
asset_content_type: application/x-gtar
- name: build cosmovisor binary
if: ${{ !matrix.cosmovisor }}
run: |
go install github.com/cosmos/cosmos-sdk/cosmovisor/cmd/cosmovisor@v1.0.0
shell: bash
- name: get GOBIN
id: get_gobin
run: |
GOPATH=${GOPATH:-${HOME}/go}
GOBIN=${GOBIN:-${GOPATH}/bin}
echo "$GOBIN"
echo "::set-output name=gobin::$GOBIN"
shell: bash
- name: upload to GitHub (cosmovisor binary)
if: ${{ !matrix.cosmovisor }}
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ needs.checks.outputs.upload_url }}
asset_path: ${{ steps.get_gobin.outputs.gobin }}/cosmovisor
asset_name: cosmovisor
asset_content_type: application/octet-stream # TODO check for less generic type
- name: upload to GitHub (service file)
if: ${{ !matrix.service }}
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ needs.checks.outputs.upload_url }}
asset_path: deployment/cosmovisor.service
asset_name: cosmovisor.service
asset_content_type: text/plain
- name: upload to GitHub (deploy script)
if: ${{ !matrix.deploy_script }}
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ needs.checks.outputs.upload_url }}
asset_path: deployment/scripts/run_dcl_node
asset_name: run_dcl_node
asset_content_type: text/plain