-
Notifications
You must be signed in to change notification settings - Fork 17
264 lines (226 loc) · 10.9 KB
/
nightly.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
name: Nightly
on:
schedule:
- cron: '0 0 * * *'
workflow_dispatch:
inputs:
release_version:
description: 'Tag to use for the build. Example: v1.0.0. *Null = master'
required: false
default: ''
latest:
description: 'Tag as latest ?'
type: boolean
required: false
default: false
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
env:
CARGO_TERM_COLOR: always
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_REGION: eu-central-1
AWS_BUCKET: gear-builds
jobs:
build:
name: Build binaries
strategy:
fail-fast: false
matrix:
include:
- target: x86_64-unknown-linux-gnu
os: ubuntu-latest
docker: amazonlinux:2023
file_ext: tar.xz
- target: aarch64-unknown-linux-musl
os: ubuntu-latest
file_ext: tar.xz
- target: x86_64-apple-darwin
os: macOS-latest
file_ext: tar.xz
- target: aarch64-apple-darwin
os: macOS-latest
file_ext: tar.xz
- target: x86_64-pc-windows-msvc
os: windows-latest
file_ext: zip
runs-on: ${{ matrix.os }}
container: ${{ matrix.docker }}
continue-on-error: true
steps:
- name: Set artifact name
run: echo "ARTIFACT_NAME=gear-${{ github.event.inputs.release_version || 'nightly' }}-${{ matrix.target }}.${{ matrix.file_ext }}" >> $GITHUB_ENV
- name: Configure Amazon Linux
if: matrix.docker == 'amazonlinux:2023'
run: |
yum update -y && yum install -y clang gcc git gzip make tar unzip wget xz
wget https://cmake.org/files/v3.24/cmake-3.24.0-linux-x86_64.sh
chmod +x cmake-3.24.0-linux-x86_64.sh
./cmake-3.24.0-linux-x86_64.sh --skip-license --prefix=/usr/local
rm cmake-3.24.0-linux-x86_64.sh
wget https://github.com/protocolbuffers/protobuf/releases/download/v3.20.2/protoc-3.20.2-linux-x86_64.zip
unzip protoc-3.20.2-linux-x86_64.zip -d /usr/local
rm protoc-3.20.2-linux-x86_64.zip
wget https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip
unzip awscli-exe-linux-x86_64.zip
./aws/install
- name: Checkout `gear-tech/gear`
uses: actions/checkout@v3
with:
repository: gear-tech/gear
ref: ${{ github.event.inputs.release_version || 'master' }}
- name: Checkout `gear-tech/builds`
uses: actions/checkout@v3
with:
path: builds
- name: Setup toolchain on Linux
if: matrix.os == 'ubuntu-latest'
uses: dtolnay/rust-toolchain@stable
- name: Add macOS x86 target
if: matrix.target == 'x86_64-apple-darwin'
run: sed -i '' 's/"wasm32-unknown-unknown"/"x86_64-apple-darwin", "wasm32-unknown-unknown"/g' rust-toolchain.toml
- name: Add macOS ARM target
if: matrix.target == 'aarch64-apple-darwin'
run: sed -i '' 's/"wasm32-unknown-unknown"/"aarch64-apple-darwin", "wasm32-unknown-unknown"/g' rust-toolchain.toml
- name: List toolchains and targets
run: |
rustup toolchain list
rustup target list --installed
- name: Install Protoc
uses: arduino/setup-protoc@v2
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
- name: Fix for `git rev-parse`
if: matrix.os == 'ubuntu-latest'
run: git config --global --add safe.directory `pwd`
- name: Build
if: matrix.target != 'aarch64-unknown-linux-musl'
run: cargo build -p gear-cli -F cli --profile production --target ${{ matrix.target }}
- name: Install cross
if: matrix.target == 'aarch64-unknown-linux-musl'
uses: taiki-e/install-action@cross
- name: Build for Linux on ARM
if: matrix.target == 'aarch64-unknown-linux-musl'
run: |
cp builds/gear.diff ./
git apply gear.diff
cross build -p gear-cli -F cli --profile production --target ${{ matrix.target }}
- name: Linux artifacts
if: matrix.os == 'ubuntu-latest'
run: |
cd target/${{ matrix.target }}/production
XZ_OPT=-9 tar -cvJf ../../../${{ env.ARTIFACT_NAME }} gear
- name: macOS artifacts
if: matrix.os == 'macos-latest'
run: |
cd target/${{ matrix.target }}/production
tar -cvJf ../../../${{ env.ARTIFACT_NAME }} gear
- name: Windows artifacts
if: matrix.os == 'windows-latest'
env:
ARTIFACT_NAME: gear-${{ github.event.inputs.release_version || 'nightly' }}-${{ matrix.target }}.${{ matrix.file_ext }}
run: |
cd target/${{ matrix.target }}/production
7z a "..\..\..\${{ env.ARTIFACT_NAME }}" gear.exe
- name: Upload artifacts
uses: actions/upload-artifact@v3
env:
ARTIFACT_NAME: gear-${{ github.event.inputs.release_version || 'nightly' }}-${{ matrix.target }}.${{ matrix.file_ext }}
with:
if-no-files-found: ignore
path: ${{ env.ARTIFACT_NAME }}
- name: Update latest symlink for release artifacts (Linux/macOS)
if: >
github.event.inputs.release_version != '' &&
github.event.inputs.latest == 'true' &&
runner.os != 'Windows'
run: |
latest_artifact=$(aws s3api list-objects --bucket ${{ env.AWS_BUCKET }} --query "reverse(sort_by(Contents, &LastModified))[?contains(Key, 'gear-${{ github.event.inputs.release_version }}-${{ matrix.target }}')].[Key]" --output text)
aws s3api put-object --bucket ${{ env.AWS_BUCKET }} --key gear-latest-${{ matrix.target }}.${{ matrix.file_ext }} --website-redirect-location /$latest_artifact
- name: Update latest symlink for release artifacts (Windows)
if: >
github.event.inputs.release_version != '' &&
github.event.inputs.latest == 'true' &&
runner.os == 'Windows'
run: |
$latest_artifact = aws s3api list-objects --bucket ${{ env.AWS_BUCKET }} --query "reverse(sort_by(Contents, &LastModified))[?contains(Key, 'gear-${{ github.event.inputs.release_version }}-${{ matrix.target }}')].[Key]" --output text
aws s3api put-object --bucket ${{ env.AWS_BUCKET }} --key "gear-latest-${{ matrix.target }}.${{ matrix.file_ext }}" --website-redirect-location "/$latest_artifact"
shell: pwsh
publish:
name: Publish artifacts
needs: build
runs-on: ubuntu-latest
steps:
- name: Checkout `gear-tech/builds`
uses: actions/checkout@v3
- name: Download artifacts
uses: actions/download-artifact@v3
- name: List artifacts
run: ls -la artifact/
- name: AWS login
uses: aws-actions/configure-aws-credentials@v3
with:
aws-access-key-id: ${{ env.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ env.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ env.AWS_REGION }}
- name: Delete old nightly artifacts
if: github.event.inputs.release_version == ''
run: |
aws s3 rm s3://${{ env.AWS_BUCKET }}/ --recursive --exclude "*" --include "gear-nightly*"
- name: Publish artifacts
run: |
aws s3 sync ./artifact/ s3://${{ env.AWS_BUCKET }}/ --exclude "*" --include "gear-*"
- name: Generate index page
run: |
echo "<!DOCTYPE html>
<html lang='en'>
<head>
<meta charset='UTF-8'>
<title>Gear Builds</title>
<link rel="stylesheet" href="static/styles.css">
<link rel="icon" href="static/favicon.ico">
</head>
<body>
<div class='container'>
<div class='header'>
<h1>Gear Builds</h1>
</div>
<div class='builds'>
<h3 id='gear-nightly'>Nightly Builds<a href='#gear-nightly'></a></h3>
<ul>" > src/index.html
artifacts=$(aws s3api list-objects --bucket ${{ env.AWS_BUCKET }} --region ${{ env.AWS_REGION }} --query 'reverse(sort_by(Contents, &LastModified))[].Key' | jq -r '.[]' | grep gear-n)
for artifact in $artifacts; do
filename=$(basename "$artifact")
filesize_bytes=$(aws s3api head-object --bucket ${{ env.AWS_BUCKET }} --key "$artifact" --region ${{ env.AWS_REGION }} --query 'ContentLength' --output text)
filesize_mb=$(echo "$filesize_bytes / 1024 / 1024" | bc -l | xargs printf "%.2f")
last_modified=$(aws s3api head-object --bucket ${{ env.AWS_BUCKET }} --key "$artifact" --region ${{ env.AWS_REGION }} --query 'LastModified' --output text | xargs -I {} date -u -d {} "+%d.%m.%Y %H:%M:%S UTC")
echo " <li><a href='https://${{ env.AWS_BUCKET }}.s3.amazonaws.com/$filename'>$filename</a> ($filesize_mb MB, $last_modified)</li>"
done >> src/index.html
echo " </ul>
</div>" >> src/index.html
release_versions=$(aws s3api list-objects --bucket ${{ env.AWS_BUCKET }} --region ${{ env.AWS_REGION }} --query 'Contents[].Key' | jq -r '.[]' | grep 'gear-v' | sed -E 's/gear-v([0-9.]+)-.*/\1/' | sort -ur)
for version in $release_versions; do
echo " <div class='builds'>
<h3 id='gear-v$version'>Release Builds - <a href='#gear-v$version'>v$version</a></h3>
<ul>"
artifacts=$(aws s3api list-objects --bucket ${{ env.AWS_BUCKET }} --region ${{ env.AWS_REGION }} --query 'reverse(sort_by(Contents, &LastModified))[].Key' | jq -r '.[]' | grep "gear-v$version")
for artifact in $artifacts; do
filename=$(basename "$artifact")
filesize_bytes=$(aws s3api head-object --bucket ${{ env.AWS_BUCKET }} --key "$artifact" --region ${{ env.AWS_REGION }} --query 'ContentLength' --output text)
filesize_mb=$(echo "$filesize_bytes / 1024 / 1024" | bc -l | xargs printf "%.2f")
last_modified=$(aws s3api head-object --bucket ${{ env.AWS_BUCKET }} --key "$artifact" --region ${{ env.AWS_REGION }} --query 'LastModified' --output text | xargs -I {} date -u -d {} "+%d.%m.%Y %H:%M:%S UTC")
echo " <li><a href='https://${{ env.AWS_BUCKET }}.s3.amazonaws.com/$filename'>$filename</a> ($filesize_mb MB, $last_modified)</li>"
done >> src/index.html
echo " </ul>
</div>"
done >> src/index.html
echo " </div>
<div class='footer'>
© 2024 Gear Technologies, Inc. All Rights Reserved.
</div>
</body>
</html>" >> src/index.html
- name: Publish index page
run: |
aws s3 sync ./src/ s3://${{ env.AWS_BUCKET }}/