Files
letro-authentication-service/.github/workflows/build.yaml
2023-09-14 14:37:28 +02:00

138 lines
3.9 KiB
YAML

name: Build
on:
push:
branches: [ main ]
tags:
- 'v*'
pull_request:
branches: [ main ]
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
env:
CARGO_TERM_COLOR: always
CARGO_NET_GIT_FETCH_WITH_CLI: "true"
jobs:
build:
name: Build binaries
runs-on: ubuntu-22.04
env:
SDKROOT: /opt/MacOSX11.3.sdk
permissions:
contents: read
steps:
- name: Checkout the code
uses: actions/checkout@v4.0.0
- name: Setup OPA
uses: open-policy-agent/setup-opa@v2.1.0
with:
version: 0.55.0
- name: Install Node
uses: actions/setup-node@v3.8.1
with:
node-version: 18
- name: Install Rust toolchain
run: |
rustup toolchain install stable
rustup target add x86_64-unknown-linux-musl
rustup target add aarch64-unknown-linux-musl
rustup target add x86_64-apple-darwin
rustup target add aarch64-apple-darwin
rustup default stable
- name: Setup Rust build cache
uses: Swatinem/rust-cache@v2.7.0
with:
save-if: "${{ github.event_name != 'pull_request' }}"
- name: Install zig and cargo-zigbuild
run: pip3 install ziglang==0.11.0 cargo-zigbuild==0.17.1
- name: Download the macOS SDK
run: curl -L "https://github.com/phracker/MacOSX-SDKs/releases/download/11.3/MacOSX11.3.sdk.tar.xz" | tar -J -x -C /opt
- name: Install Node dependencies
working-directory: ./frontend
run: npm ci
- name: Build frontend
working-directory: ./frontend
run: npm run build
- name: Build policies
working-directory: ./policies
run: make
- name: Force Cargo to create the target directory
# Run `cargo clean` with an empty package name to force it to create the target directory
# This fails because there is no package with an empty name, but the target directory is created
# See https://github.com/rust-lang/cargo/issues/12441
# This is needed because `cargo-zigbuild` sometimes (wrongly) creates the target directory
# See https://github.com/rust-cross/cargo-zigbuild/issues/165
run: |
cargo clean -p '' \
--target x86_64-unknown-linux-musl \
--target aarch64-unknown-linux-musl \
--target x86_64-apple-darwin \
--target aarch64-apple-darwin \
|| true
- name: Build the binary
run: |
cargo zigbuild \
--release \
--target x86_64-unknown-linux-musl \
--target aarch64-unknown-linux-musl \
--target x86_64-apple-darwin \
--target aarch64-apple-darwin \
--no-default-features \
--features dist \
-p mas-cli
- name: Upload the artifacts
uses: actions/upload-artifact@v3.1.3
with:
path: |
target/x86_64-unknown-linux-musl/release/mas-cli
target/aarch64-unknown-linux-musl/release/mas-cli
target/x86_64-apple-darwin/release/mas-cli
target/aarch64-apple-darwin/release/mas-cli
frontend/dist/
policies/policy.wasm
#release:
# name: Release
# if: startsWith(github.ref, 'refs/tags/')
# runs-on: ubuntu-latest
# needs:
# - build
# steps:
# - name: Download the artifacts from the previous job
# uses: actions/download-artifact@v3
# with:
# path: artifacts
# - name: Create the various archives
# run: |
# mkdir -p dist
# mv artifacts/
# - name: Prepare a release
# uses: softprops/action-gh-release@v1
# with:
# files: |
# mas-cli-aarch64-linux.tar.gz
# mas-cli-aarch64-macos.tar.gz
# mas-cli-x86_64-linux.tar.gz
# mas-cli-x86_64-macos.tar.gz
# draft: true