-
Notifications
You must be signed in to change notification settings - Fork 27
270 lines (238 loc) · 10.8 KB
/
ci-cd.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
name: CI/CD
on:
push:
branches:
- 'release/**'
- 'master'
pull_request:
branches:
- 'master'
- '**'
jobs:
build:
if: |
(github.event_name == 'push' || github.event_name == 'pull_request') &&
github.actor != 'github-actions[bot]' &&
!(github.event_name == 'pull_request' &&
startsWith(github.event.pull_request.head.ref, 'release/') &&
github.event.pull_request.base.ref == 'master')
name: ${{ matrix.target }} (${{ matrix.runner }})
runs-on: ${{ matrix.runner }}
timeout-minutes: 240
strategy:
fail-fast: false
matrix:
include:
- runner: ubuntu-latest
target: x86_64-unknown-linux-gnu
svm_target_platform: linux-amd64
platform: linux
arch: amd64
# - runner: ubuntu-latest
# target: aarch64-unknown-linux-gnu
# svm_target_platform: linux-aarch64
# platform: linux
# arch: arm64
- runner: macos-12
target: x86_64-apple-darwin
svm_target_platform: macosx-amd64
platform: darwin
arch: amd64
- runner: macos-latest
target: aarch64-apple-darwin
svm_target_platform: macosx-aarch64
platform: darwin
arch: arm64
- runner: windows-latest
target: x86_64-pc-windows-msvc
svm_target_platform: windows-amd64
platform: win32
arch: amd64
env:
BUILD_TYPE: release
steps:
- uses: actions/checkout@v2
with:
ref: ${{ github.ref_name }}
- uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}
- uses: Swatinem/rust-cache@v2
with:
key: ${{ matrix.target }}
cache-on-failure: true
- name: Apple M1 setup
if: matrix.target == 'aarch64-apple-darwin'
run: |
echo "SDKROOT=$(xcrun -sdk macosx --show-sdk-path)" >> $GITHUB_ENV
echo "MACOSX_DEPLOYMENT_TARGET=$(xcrun -sdk macosx --show-sdk-platform-version)" >> $GITHUB_ENV
- name: Linux ARM setup
if: matrix.target == 'aarch64-unknown-linux-gnu'
run: |
sudo apt-get update -y
sudo apt-get install -y gcc-aarch64-linux-gnu
echo "CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=aarch64-linux-gnu-gcc" >> $GITHUB_ENV
- name: Install MSVC target
if: matrix.target == 'x86_64-pc-windows-msvc'
run: rustup target add x86_64-pc-windows-msvc
- name: Install OpenSSL development libraries
if: matrix.target == 'aarch64-unknown-linux-gnu' || matrix.target == 'x86_64-unknown-linux-gnu'
run: |
sudo apt-get update -y
sudo apt-get install -y libssl-dev pkg-config
- name: Setup cross-compilation for pkg-config
if: matrix.target == 'aarch64-unknown-linux-gnu'
run: |
echo "PKG_CONFIG_ALLOW_CROSS=1" >> $GITHUB_ENV
echo "PKG_CONFIG_SYSROOT_DIR=/usr/aarch64-linux-gnu" >> $GITHUB_ENV
echo "PKG_CONFIG_PATH=/usr/lib/aarch64-linux-gnu/pkgconfig" >> $GITHUB_ENV
echo "PKG_CONFIG_LIBDIR=/usr/lib/aarch64-linux-gnu/pkgconfig" >> $GITHUB_ENV
- name: Extract version name
id: extract_version
run: echo "VERSION_NAME=${GITHUB_REF#refs/heads/release/}" >> $GITHUB_ENV
- name: Install and setup NASM on Windows
if: matrix.target == 'x86_64-pc-windows-msvc'
shell: pwsh
run: |
choco install nasm
$nasmPath = "C:\Program Files\NASM"
$env:PATH += ";$nasmPath"
echo "$nasmPath" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
echo "NASM_PATH=$nasmPath" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
refreshenv
nasm -v
- name: Install vcpkg on Windows
if: matrix.target == 'x86_64-pc-windows-msvc'
shell: pwsh
run: |
git clone https://github.com/Microsoft/vcpkg.git C:\vcpkg
C:\vcpkg\bootstrap-vcpkg.bat
C:\vcpkg\vcpkg integrate install
echo "VCPKG_ROOT=C:\vcpkg" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
echo "C:\vcpkg" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
- name: Install CMake on Windows
if: matrix.target == 'x86_64-pc-windows-msvc'
shell: pwsh
run: |
choco install cmake --installargs 'ADD_CMAKE_TO_PATH=System'
refreshenv
cmake --version
echo "CMAKE_TOOLCHAIN_FILE=C:/vcpkg/scripts/buildsystems/vcpkg.cmake" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
- name: Install dependencies with vcpkg on Windows
if: matrix.target == 'x86_64-pc-windows-msvc'
shell: pwsh
run: |
C:\vcpkg\vcpkg install openssl:x64-windows-static-md zlib:x64-windows-static-md
- name: Build binaries
working-directory: cli
env:
SVM_TARGET_PLATFORM: ${{ matrix.svm_target_platform }}
CMAKE_TOOLCHAIN_FILE: C:/vcpkg/scripts/buildsystems/vcpkg.cmake
shell: bash
run: |
set -eo pipefail
target="${{ matrix.target }}"
flags=()
if [[ "$target" != *msvc* && "$target" != "aarch64-unknown-linux-gnu" ]]; then
flags+=(--features jemalloc)
fi
[[ "$target" == *windows* ]] && exe=".exe"
if [[ "$target" == *windows* ]]; then
export PATH="$PATH:/c/Program Files/NASM:/c/vcpkg"
export NASM="$NASM_PATH/nasm.exe"
echo "NASM location: $NASM"
"$NASM" -v
echo "CMAKE_TOOLCHAIN_FILE: $CMAKE_TOOLCHAIN_FILE"
ls -l "$CMAKE_TOOLCHAIN_FILE" || echo "Toolchain file not found!"
fi
if [[ "${{ env.BUILD_TYPE }}" == "release" ]]; then
RUST_BACKTRACE=1 CMAKE_TOOLCHAIN_FILE="$CMAKE_TOOLCHAIN_FILE" cargo build --release --target "$target" "${flags[@]}" -vv
else
RUST_BACKTRACE=1 CMAKE_TOOLCHAIN_FILE="$CMAKE_TOOLCHAIN_FILE" cargo build --target "$target" "${flags[@]}" -vv
fi
- name: Archive binaries
id: artifacts
if: startsWith(github.ref, 'refs/heads/release/')
env:
PLATFORM_NAME: ${{ matrix.platform }}
TARGET: ${{ matrix.target }}
ARCH: ${{ matrix.arch }}
VERSION_NAME: ${{ env.VERSION_NAME }}
shell: bash
run: |
RELEASE_DIR="${{ github.workspace }}/documentation/docs/public/releases/${PLATFORM_NAME}-${ARCH}"
VERSION_DIR="$RELEASE_DIR/${{ env.VERSION_NAME }}"
BUILD_DIR="${{ github.workspace }}/target/${TARGET}/${{ env.BUILD_TYPE }}"
mkdir -p "$RELEASE_DIR"
mkdir -p "$VERSION_DIR"
FILE_NAME="rindexer_${PLATFORM_NAME}-${ARCH}.tar.gz"
BINARY_NAME="rindexer_cli"
[[ "$PLATFORM_NAME" == "win32" ]] && BINARY_NAME="rindexer_cli.exe"
if [ "$PLATFORM_NAME" == "linux" ] || [ "$PLATFORM_NAME" == "darwin" ]; then
tar -czvf "$RELEASE_DIR/$FILE_NAME" -C "$BUILD_DIR" "$BINARY_NAME"
tar -czvf "$VERSION_DIR/$FILE_NAME" -C "$BUILD_DIR" "$BINARY_NAME"
echo "file_name=$FILE_NAME" >> $GITHUB_OUTPUT
else
cd $BUILD_DIR
7z a -tzip "$RELEASE_DIR/rindexer_${PLATFORM_NAME}-${ARCH}.zip" "$BINARY_NAME"
7z a -tzip "$VERSION_DIR/rindexer_${PLATFORM_NAME}-${ARCH}.zip" "$BINARY_NAME"
echo "file_name=rindexer_${PLATFORM_NAME}-${ARCH}.zip" >> $GITHUB_OUTPUT
fi
- name: Run tests
shell: bash
run: |
set -eo pipefail
target="${{ matrix.target }}"
flags=()
if [[ "$target" != *msvc* && "$target" != "aarch64-unknown-linux-gnu" ]]; then
flags+=(--features jemalloc)
fi
cargo test --exclude rindexer_rust_playground --workspace --release --target "$target" "${flags[@]}"
- name: Upload artifact
if: startsWith(github.ref, 'refs/heads/release/') && matrix.target != 'x86_64-pc-windows-msvc'
uses: actions/upload-artifact@v2
with:
name: ${{ matrix.platform }}-${{ matrix.arch }}
path: |
${{ github.workspace }}/documentation/docs/public/releases/${{ matrix.platform }}-${{ matrix.arch }}/${{ env.VERSION_NAME }}
${{ github.workspace }}/documentation/docs/public/releases/${{ matrix.platform }}-${{ matrix.arch }}/rindexer_${{ matrix.platform }}-${{ matrix.arch }}.tar.gz
- name: Upload artifact for windows
if: startsWith(github.ref, 'refs/heads/release/') && matrix.target == 'x86_64-pc-windows-msvc'
uses: actions/upload-artifact@v2
with:
name: ${{ matrix.platform }}-${{ matrix.arch }}
path: |
${{ github.workspace }}/documentation/docs/public/releases/${{ matrix.platform }}-${{ matrix.arch }}/${{ env.VERSION_NAME }}
${{ github.workspace }}/documentation/docs/public/releases/${{ matrix.platform }}-${{ matrix.arch }}/rindexer_${{ matrix.platform }}-${{ matrix.arch }}.zip
finalize:
name: Commit and push changes
runs-on: ubuntu-latest
needs: build
if: github.actor != 'github-actions[bot]' && startsWith(github.ref, 'refs/heads/release/')
steps:
- uses: actions/checkout@v2
with:
ref: ${{ github.ref_name }}
- name: Download artifacts
uses: actions/download-artifact@v2
with:
path: ${{ github.workspace }}/documentation/docs/public/releases
- name: Commit and push changes
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
git config --global user.name "github-actions"
git config --global user.email "github-actions@github.com"
git add documentation/docs/public/releases
git commit -m "Add release binaries for ${{ env.VERSION_NAME }}"
git push origin HEAD:refs/heads/${{ github.ref_name }}
- name: Clean up uploaded artifacts
if: matrix.target != 'x86_64-pc-windows-msvc'
run: |
rm -rf ${{ github.workspace }}/documentation/docs/public/releases/${{ matrix.platform }}-${{ env.VERSION_NAME }}/rindexer_${{ matrix.platform }}-${{ matrix.arch }}.tar.gz
rm -rf ${{ github.workspace }}/documentation/docs/public/releases/${{ matrix.platform }}/rindexer_${{ matrix.platform }}-${{ matrix.arch }}.tar.gz
- name: Clean up uploaded artifacts for windows
if: matrix.target == 'x86_64-pc-windows-msvc'
run: |
rm -rf ${{ github.workspace }}/documentation/docs/public/releases/${{ matrix.platform }}-${{ env.VERSION_NAME }}/rindexer_${{ matrix.platform }}-${{ matrix.arch }}.zip
rm -rf ${{ github.workspace }}/documentation/docs/public/releases/${{ matrix.platform }}/rindexer_${{ matrix.platform }}-${{ matrix.arch }}.zip