Skip to content

Commit

Permalink
chore(ci): add build matrix testing (#75)
Browse files Browse the repository at this point in the history
  • Loading branch information
leet4tari authored Nov 13, 2024
1 parent 56b408d commit 991f32d
Show file tree
Hide file tree
Showing 4 changed files with 349 additions and 3 deletions.
116 changes: 116 additions & 0 deletions .github/workflows/build_tests.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
[
{
"name": "linux-x86_64",
"runs-on": "ubuntu-20.04",
"rust": "nightly-2024-07-07",
"target": "x86_64-unknown-linux-gnu",
"cross": false
},
{
"name": "linux-arm64",
"runs-on": "ubuntu-latest",
"rust": "stable",
"target": "aarch64-unknown-linux-gnu",
"cross": true
},
{
"name": "linux-riscv64",
"runs-on": "ubuntu-latest",
"rust": "stable",
"target": "riscv64gc-unknown-linux-gnu",
"cross": true
},
{
"name": "macos-x86_64",
"runs-on": "macos-13",
"rust": "stable",
"target": "x86_64-apple-darwin",
"cross": false
},
{
"name": "macos-arm64",
"runs-on": "macos-14",
"rust": "stable",
"target": "aarch64-apple-darwin",
"cross": false
},
{
"name": "windows-x64-2019",
"runs-on": "windows-2019",
"rust": "stable",
"target": "x86_64-pc-windows-msvc",
"cross": false
},
{
"name": "windows-x64-2022",
"runs-on": "windows-2022",
"rust": "stable",
"target": "x86_64-pc-windows-msvc",
"cross": false,
"build_enabled": true,
"best_effort": true
},
{
"name": "windows-arm64",
"runs-on": "windows-latest",
"rust": "stable",
"target": "aarch64-pc-windows-msvc",
"cross": false,
"build_enabled": true,
"best_effort": true
},
{
"name": "ios-x86_64",
"runs-on": "macos-latest",
"rust": "stable",
"target": "x86_64-apple-ios",
"cross": false,
"build_enabled": true,
"best_effort": true
},
{
"name": "ios-aarch64",
"runs-on": "macos-latest",
"rust": "stable",
"target": "aarch64-apple-ios",
"cross": false,
"build_enabled": true,
"best_effort": true
},
{
"name": "ios-aarch64-sim",
"runs-on": "macos-latest",
"rust": "stable",
"target": "aarch64-apple-ios-sim",
"cross": false,
"build_enabled": true,
"best_effort": true
},
{
"name": "android-x86_64",
"runs-on": "ubuntu-latest",
"rust": "stable",
"target": "x86_64-linux-android",
"cross": true,
"build_enabled": true,
"best_effort": true
},
{
"name": "android-aarch64",
"runs-on": "ubuntu-latest",
"rust": "stable",
"target": "aarch64-linux-android",
"cross": true,
"build_enabled": true,
"best_effort": true
},
{
"name": "android-riscv64",
"runs-on": "ubuntu-latest",
"rust": "nightly-2024-07-07",
"target": "riscv64-linux-android",
"cross": true,
"build_enabled": true,
"best_effort": true
}
]
187 changes: 187 additions & 0 deletions .github/workflows/build_tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,187 @@
---
name: Build Test Matrix

'on':
push:
tags:
- "v[0-9]+.[0-9]+.[0-9]*"
branches:
- "build-ci-*"
schedule:
- cron: "05 00 * * *"
workflow_dispatch:

env:
toolchain: nightly-2024-07-07
matrix-json-file: ".github/workflows/build_tests.json"
CARGO_HTTP_MULTIPLEXING: false
CARGO_UNSTABLE_SPARSE_REGISTRY: true
CARGO: cargo
#CARGO_OPTIONS: "--locked"
CARGO_OPTIONS: "-vv"
CARGO_CACHE: true

concurrency:
# https://docs.github.com/en/actions/examples/using-concurrency-expressions-and-a-test-matrix
group: '${{ github.workflow }} @ ${{ github.event.pull_request.head.label || github.head_ref || github.ref }}'
cancel-in-progress: ${{ !startsWith(github.ref, 'refs/tags/v') || github.ref != 'refs/heads/development' }}

permissions: {}

jobs:
matrix-prep:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- uses: actions/checkout@v4
with:
submodules: false

- name: Set Matrix
id: set-matrix
run: |
#
# build all targets images
# matrix=$( jq -s -c .[] .github/workflows/build_binaries.json )
#
# build only single target image
# matrix_selection=$( jq -c '.[] | select( ."name" == "windows-x64" )' ${{ env.matrix-json-file }} )
# matrix_selection=$( jq -c '.[] | select( ."name" | contains("macos") )' ${{ env.matrix-json-file }} )
#
# build select target images - build_enabled
matrix_selection=$( jq -c '.[] | select( ."build_enabled" != false )' ${{ env.matrix-json-file }} )
#
# Setup the json build matrix
matrix=$(echo ${matrix_selection} | jq -s -c '{"builds": .}')
echo $matrix
echo $matrix | jq .
echo "matrix=${matrix}" >> $GITHUB_OUTPUT
matrix-check:
# Debug matrix
if: ${{ false }}
runs-on: ubuntu-latest
needs: matrix-prep
steps:
- name: Install json2yaml
run: |
sudo npm install -g json2yaml
- name: Check matrix definition
run: |
matrix='${{ needs.matrix-prep.outputs.matrix }}'
echo $matrix
echo $matrix | jq .
echo $matrix | json2yaml
builds:
name: Building ${{ matrix.builds.name }} on ${{ matrix.builds.runs-on }}
needs: matrix-prep
continue-on-error: ${{ matrix.builds.best_effort || false }}
strategy:
fail-fast: false
max-parallel: 5
matrix: ${{ fromJson(needs.matrix-prep.outputs.matrix) }}

runs-on: ${{ matrix.builds.runs-on }}

steps:
- name: Checkout source code
uses: actions/checkout@v4
with:
submodules: recursive

- name: Setup Rust toolchain
uses: dtolnay/rust-toolchain@master
with:
components: rustfmt, clippy
toolchain: ${{ matrix.builds.rust }}
targets: ${{ matrix.builds.target }}

- name: Install Linux dependencies - Ubuntu
if: ${{ startsWith(runner.os,'Linux') && ( ! matrix.builds.cross ) }}
run: |
sudo apt-get update
sudo bash scripts/install_ubuntu_dependencies.sh
rustup target add ${{ matrix.builds.target }}
- name: Install macOS dependencies
if: startsWith(runner.os,'macOS')
run: |
# openssl, cmake and autoconf already installed
# brew install zip coreutils automake protobuf
brew install zip coreutils automake
rustup target add ${{ matrix.builds.target }}
- name: Install macOS-14 missing dependencies - hack
if: ${{ startsWith(runner.os,'macOS') && startsWith(runner.arch,'ARM64') }}
run: |
brew install libtool
- name: Install Windows dependencies
if: startsWith(runner.os,'Windows')
run: |
# choco upgrade protoc -y
rustup target add ${{ matrix.builds.target }}
- name: Declare Android/iOS envs
shell: bash
run: |
if [[ "${{ matrix.builds.target }}" =~ "android" ]]; then
echo "CFLAGS=-DMDB_USE_ROBUST=0" >> $GITHUB_ENV
echo "TARGET_PLATFORM=android" >> $GITHUB_ENV
elif [[ "${{ matrix.builds.target }}" =~ "ios" ]]; then
echo "TARGET_PLATFORM=ios" >> $GITHUB_ENV
if [[ "${{ matrix.builds.target }}" =~ "-sim" ]]; then
echo "TARGET_SIM=-sim" >> $GITHUB_ENV
fi
elif [[ "${{ matrix.builds.target }}" =~ "linux-gnu" ]]; then
echo "TARGET_PLATFORM=linux" >> $GITHUB_ENV
elif [[ "${{ matrix.builds.target }}" =~ "apple-darwin" ]]; then
echo "TARGET_PLATFORM=macos" >> $GITHUB_ENV
fi
# Strip begining
tempEnv="${{ matrix.builds.target }}"
echo "TARGET_ARCH=${tempEnv/-*/}" >> $GITHUB_ENV
# Strip outside of *_X_*
tempEnv="${{ matrix.libffis }}"
tempEnv=${tempEnv#*_}
echo "TARGET_NAME=${tempEnv%_*}" >> $GITHUB_ENV
- name: Cache cargo files and outputs
if: ${{ ( ! startsWith(github.ref, 'refs/tags/v') ) && ( ! matrix.builds.cross ) && ( env.CARGO_CACHE ) }}
uses: Swatinem/rust-cache@v2
with:
key: ${{ matrix.builds.target }}

- name: Install and setup cargo cross
if: ${{ matrix.builds.cross }}
shell: bash
run: |
#cargo install cross
cargo install cross --git https://github.com/cross-rs/cross
echo "CARGO=cross" >> $GITHUB_ENV
- name: Setup build release targets
# if: ${{ startsWith(github.ref, 'refs/tags/v') }}
shell: bash
run: |
# echo "TS_BUILD=release" >> $GITHUB_ENV
if [[ "${{ env.TS_BUILD }}" == "release" ]]; then
echo "CARGO_OPTIONS=${{ env.CARGO_OPTIONS }} --${{ env.TS_BUILD }}" >> $GITHUB_ENV
fi
- name: Show command used for Cargo
shell: bash
run: |
echo "cargo command is: ${{ env.CARGO }}"
echo "cargo options is: ${{ env.CARGO_OPTIONS }}"
echo "cross flag: ${{ matrix.builds.cross }}"
- name: Build test for ${{ matrix.builds.target }}
shell: bash
run: |
${{ env.CARGO }} build ${{ env.CARGO_OPTIONS }} \
--target ${{ matrix.builds.target }} \
${{ matrix.builds.flags }}
43 changes: 40 additions & 3 deletions scripts/file_license_check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,45 @@
# Must be run from the repo root
#

#set -xo pipefail
set -e

check_for() {
if prog_location=$(which ${1}) ; then
if result=$(${1} --version 2>/dev/null); then
result="${1}: ${result} INSTALLED ✓"
else
result="${1}: INSTALLED ✓"
fi
else
result="${1}: MISSING ⨯"
fi
}

check_requirements() {
echo "List of requirements and possible test:"
req_progs=(
mktemp
rg
diff
)
for RProg in "${req_progs[@]}"; do
check_for ${RProg}
echo "${result}"
if [[ "${result}" == "${RProg}: MISSING ⨯" ]]; then
echo "!! Install ${RProg} and try again !!"
exit -1
fi
done

if [ ! -f .license.ignore ]; then
echo "!! No .license.ignore file !!"
exit -1
fi
}

check_requirements

diffparms=${diffparms:-"-u --suppress-blank-empty --strip-trailing-cr --color=never"}
rgTemp=${rgTemp:-$(mktemp)}

Expand All @@ -15,9 +52,7 @@ rgTemp=${rgTemp:-$(mktemp)}
# Exclude files without extensions as well as those with extensions that are not in the list
#
rg -i "Copyright.*The Tari Project" --files-without-match \
--one-file-system --no-follow \
-g '!{RandomX}' \
-g '!*.{Dockerfile,asc,bat,config,config.js,css,csv,drawio,env,gitkeep,hbs,html,ini,iss,json,lock,md,min.js,ps1,py,rc,scss,sh,sql,svg,toml,txt,yml,vue}' . \
-g '!*.{Dockerfile,asc,bat,config,config.js,css,csv,drawio,env,gitkeep,hbs,html,ini,iss,json,lock,md,min.js,ps1,py,rc,scss,sh,sql,svg,toml,txt,yml,vue,liquid,otf,d.ts,mjs}' . \
| while IFS= read -r file; do
if [[ -n $(basename "$file" | grep -E '\.') ]]; then
echo "$file"
Expand All @@ -42,4 +77,6 @@ if [ -n "${DIFFS}" ]; then
echo "Diff:"
echo "${DIFFS}"
exit 1
else
exit 0
fi
6 changes: 6 additions & 0 deletions scripts/install_ubuntu_dependencies.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
apt-get install --no-install-recommends --assume-yes \
git \
make \
cmake \
libc++-dev \
libc++abi-dev

0 comments on commit 991f32d

Please sign in to comment.