-
Notifications
You must be signed in to change notification settings - Fork 9
252 lines (227 loc) · 7.33 KB
/
ci.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
---
name: CI
on:
pull_request:
branches:
- main
push:
branches:
- main
tags:
- "*"
jobs:
static-analysis:
runs-on: ubuntu-20.04
env:
MIX_ENV: dev
WIREGUARDNIF_BUILD: true
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
with:
python-version: '3.9'
- uses: erlef/setup-beam@v1
with:
otp-version: 26
elixir-version: 1.15
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
components: clippy, rustfmt
- uses: actions/cache@v2
name: Setup Elixir cache
with:
path: |
deps
_build
key: ${{ runner.os }}-mix-otp-25-${{ hashFiles('**/mix.lock') }}
- uses: actions/cache@v2
name: Setup Python cache
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
- uses: actions/cache@v2
name: Setup Rust cache
with:
path: |
~/.cargo/registry
~/.cargo/git
native/wireguard_nif/target
key: ${{ runner.os }}-cargo-${{ hashFiles('**/native/wireguard_nif/Cargo.lock') }}
- name: Install Elixir dependencies
run: mix deps.get --only dev
- name: Install Python dependencies
run: pip install -r requirements.txt
- name: Run pre-commit
run: |
pre-commit install
SKIP=no-commit-to-branch pre-commit run --all-files
tests:
env:
MIX_ENV: test
WIREGUARDNIF_BUILD: true
runs-on: ubuntu-20.04
name: "[${{matrix.otp}}/${{matrix.elixir}}] Tests on wireguard_nif [OTP/Elixir]"
strategy:
fail-fast: false
matrix:
otp: [22, 23, 24, 25, 26]
elixir: [1.13, 1.14, 1.15]
exclude:
- otp: 26
elixir: 1.13
- otp: 22
elixir: 1.14
- otp: 22
elixir: 1.15
- otp: 23
elixir: 1.15
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
- uses: erlef/setup-beam@v1
with:
otp-version: ${{matrix.otp}}
elixir-version: ${{matrix.elixir}}
- name: Cache hex deps
id: mix-cache
uses: actions/cache@v2
with:
path: |
deps
_build
!_build/*/lib/wireguardex
key: ${{ runner.os }}[${{ matrix.otp }}/${{ matrix.elixir }}]-mix-v1-${{ hashFiles('**/mix.lock') }}
- run: sudo setcap 'cap_net_admin+eip' $(ls -1 $INSTALL_DIR_FOR_OTP/erts-*/bin/beam.smp)
- run: mix local.hex --force
- run: mix local.rebar --force
- run: mix deps.get
- run: mix deps.compile
- run: mix compile --warning-as-errors
env:
RUST_BACKTRACE: 1
- run: mix test
draft-release:
runs-on: ubuntu-20.04
needs:
- static-analysis
- tests
outputs:
tag_name: ${{ steps.release_drafter.outputs.tag_name }}
steps:
- uses: release-drafter/release-drafter@v5
id: release_drafter
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
build-release-nifs:
name: NIF ${{ matrix.nif }} - ${{ matrix.target }} (${{ matrix.os }})
runs-on: ${{ matrix.os }}
needs:
- draft-release
defaults:
run:
working-directory: "./native/wireguard_nif"
strategy:
fail-fast: false
matrix:
target:
- aarch64-unknown-linux-gnu
- aarch64-unknown-linux-musl
- x86_64-unknown-linux-gnu
- x86_64-unknown-linux-musl
- aarch64-apple-darwin
- x86_64-apple-darwin
os:
- ubuntu-20.04
- macos-11
nif:
- "2.15"
- "2.16"
- "2.17"
# Exclude combinations of build OSes and targets that don't make sense
exclude:
- os: macos-11
target: aarch64-unknown-linux-gnu
- os: macos-11
target: aarch64-unknown-linux-musl
- os: macos-11
target: x86_64-unknown-linux-gnu
- os: macos-11
target: x86_64-unknown-linux-musl
- os: ubuntu-20.04
target: aarch64-apple-darwin
- os: ubuntu-20.04
target: x86_64-apple-darwin
env:
NIF_DIRECTORY: "native/wireguard_nif"
RUSTLER_NIF_VERSION: ${{ matrix.nif }}
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Install Rust
uses: actions-rs/toolchain@v1
with:
toolchain: stable
target: ${{ matrix.target }}
override: true
profile: minimal
- name: Install cross
if: ${{ contains(matrix.os, 'ubuntu') }}
# Use main cross-rs to have Zig support
run: cargo install cross --git https://github.com/cross-rs/cross --locked
- name: Extract project info
shell: bash
run: |
echo "PROJECT_NAME=$(sed -n 's/^name = "\(.*\)"/\1/p' Cargo.toml | head -n1)" >> $GITHUB_ENV
echo "PROJECT_VERSION=$(sed -n 's/^ @version "\(.*\)"/\1/p' ../../mix.exs | head -n1)" >> $GITHUB_ENV
- name: Build with Cross
if: ${{ contains(matrix.os, 'ubuntu') }}
run: cross build --release --target=${{ matrix.target }}
- name: Build with Cargo
shell: bash
if: ${{ ! contains(matrix.os, 'ubuntu') }}
run: cargo build --release --target=${{ matrix.target }}
- name: Rename lib
id: rename
shell: bash
run: |
LIB_PREFIX="lib"
LIB_SUFFIX=".so"
case ${{ matrix.target }} in
*-apple-darwin) LIB_SUFFIX=".dylib" ;;
esac;
CICD_INTERMEDIATES_DIR=$(mktemp -d)
LIB_DIR="${CICD_INTERMEDIATES_DIR}/released"
mkdir -p "${LIB_DIR}"
LIB_NAME="${LIB_PREFIX}${{ env.PROJECT_NAME }}${LIB_SUFFIX}"
LIB_PATH="${LIB_DIR}/${LIB_NAME}"
cp "target/${{ matrix.target }}/release/${LIB_NAME}" "${LIB_DIR}"
# Use ".so" for macOS
# See: https://www.erlang.org/doc/man/erlang.html#load_nif-2
LIB_FINAL_SUFFIX="${LIB_SUFFIX}"
case ${{ matrix.target }} in
*-apple-darwin) LIB_FINAL_SUFFIX=".so" ;;
esac;
LIB_FINAL_NAME="${LIB_PREFIX}${PROJECT_NAME}-v${PROJECT_VERSION}-nif-${RUSTLER_NIF_VERSION}-${{ matrix.target }}${LIB_FINAL_SUFFIX}"
# Copy lib to final name
cp "${LIB_PATH}" "${LIB_FINAL_NAME}"
tar -cvzf "${LIB_FINAL_NAME}.tar.gz" "${LIB_FINAL_NAME}"
LIB_FINAL_PATH="${NIF_DIRECTORY}/${LIB_FINAL_NAME}.tar.gz"
echo ::set-output name=LIB_FINAL_PATH::${LIB_FINAL_PATH}
echo ::set-output name=LIB_FINAL_NAME::${LIB_FINAL_NAME}.tar.gz
- name: Upload release
uses: actions/upload-artifact@v2
with:
name: ${{ steps.rename.outputs.LIB_FINAL_NAME }}
path: ${{ steps.rename.outputs.LIB_FINAL_PATH }}
- name: Release
uses: softprops/action-gh-release@v1
with:
tag_name: ${{ needs.draft-release.outputs.tag_name }}
draft: true
files: ${{ steps.rename.outputs.LIB_FINAL_PATH }}
if: startsWith(github.ref, 'refs/heads/main') || startsWith(github.ref, 'refs/tags/')