Merge pull request #39 from firezone/bump-elixir-versions #117
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
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/') |