fix(backup/op): failing test #80
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: Continuous Integration | |
on: | |
push: | |
branches: [ master ] | |
jobs: | |
flake-health-check: | |
runs-on: ubuntu-latest | |
name: Flake Health Check | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: DeterminateSystems/nix-installer-action@main | |
- uses: DeterminateSystems/flake-checker-action@main | |
with: | |
ignore-missing-flake-lock: false | |
fail-mode: true | |
get-changes: | |
runs-on: ubuntu-latest | |
outputs: | |
changed_crates: ${{ steps.extract-crates.outputs.changed_crates }} | |
rebuild_all: ${{ steps.check-root-changes.outputs.rebuild_all }} | |
binaries: ${{ steps.generate-matrix.outputs.available_binaries }} | |
matrix: ${{ steps.generate-matrix.outputs.matrix }} | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- uses: actions-rust-lang/setup-rust-toolchain@v1 | |
- name: Extract Changed Crates | |
id: extract-crates | |
run: | | |
changes=$(git diff --name-only ${{ github.event.before }} ${{ github.event.ref }} | grep -oP 'crates/[^/]+/' | sort -u) | |
crates=$(echo "$changes" | sed -E 's/crates\/([^\/]+)\//\1/g' | sort -u) | |
readarray -t crates <<< "$crates" | |
changed_crates=$(IFS=, ; echo "${crates[*]}") | |
echo "changed_crates=$changed_crates" >> "$GITHUB_OUTPUT" | |
echo "Changed Crates: $changed_crates" | |
# If any of the root files have changed we should rebuild all crates. | |
- name: Check for Root Changes | |
id: check-root-changes | |
if: ${{ steps.extract-crates.outputs.changed_crates == '' }} | |
run: | | |
changes=$(git diff --name-only ${{ github.event.before }} ${{ github.event.ref }} | grep -oP '^(Cargo.toml|Cargo.lock|flake.nix|.github/workflows/ci.yml)$' | sort -u) | |
if [ -n "$changes" ]; then | |
echo "rebuild_all=true" >> "$GITHUB_OUTPUT" | |
echo "All Crates will be rebuilt due to changes in root build files." | |
fi | |
- name: Generate Matrix | |
id: generate-matrix | |
run: | | |
if [ "${{ steps.check-root-changes.outputs.rebuild_all }}" == true ]; then | |
crates=$(find crates -mindepth 1 -maxdepth 1 -type d -exec basename {} \;) | |
else | |
readarray -d ',' -t crates <<< '${{ steps.extract-crates.outputs.changed_crates }}' | |
fi | |
echo "Crates: ${crates[*]}" | |
if [ ${#crates[@]} -eq 0 ]; then | |
echo "No crates have changed." | |
echo "matrix={}" >> "$GITHUB_OUTPUT" | |
exit 0 | |
fi | |
cargo_metadata=$(cargo metadata --no-deps --format-version 1) | |
readarray -t default_members < <(echo "$cargo_metadata" | jq -r '.workspace_default_members[] | split("#")[0]' | xargs -n1 basename) | |
echo "available_binaries=$(echo "$cargo_metadata" | jq -r '.packages | map(select(.targets[].kind[] | contains("bin")) | .name) | join(",")')" >> "$GITHUB_OUTPUT" | |
# We only want to build the crates defined as default members. | |
readarray -t crates < <(comm -12 <(printf "%s\n" "${crates[@]}" | sort) <(printf "%s\n" "${default_members[@]}" | sort)) | |
echo "Default Members: ${default_members[*]}" | |
echo "Crates to Build: ${crates[*]}" | |
matrix='{"system": ["x86_64-linux","aarch64-linux","x86_64-windows","aarch64-windows","x86_64-darwin","aarch64-darwin"],"crate": [' | |
for crate in "${crates[@]}"; do | |
matrix+="\"$crate\"," | |
done | |
matrix="${matrix::-1}]}" | |
echo "$matrix" | jq . | |
echo "matrix=$matrix" >> "$GITHUB_OUTPUT" | |
build-artifacts: | |
needs: [ get-changes ] | |
if: ${{ needs.get-changes.outputs.matrix != '{}' }} | |
strategy: | |
fail-fast: false | |
matrix: ${{ fromJson(needs.get-changes.outputs.matrix) }} | |
runs-on: ${{ endsWith(matrix.system, 'darwin') && 'macos-latest' || 'ubuntu-latest' }} | |
name: Build ${{ matrix.crate }} for ${{ matrix.system }} | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Set Swap Space | |
if: ${{ !endsWith(matrix.system, 'darwin') && !env.ACT }} | |
uses: pierotofy/set-swap-space@master | |
with: | |
swap-size-gb: 12 | |
- uses: cachix/install-nix-action@v30 | |
- uses: DeterminateSystems/magic-nix-cache-action@v8 | |
- run: nix build .#${{ matrix.crate }}-${{ matrix.system }}-dev -L --accept-flake-config | |
- uses: actions/[email protected] | |
if: ${{ contains(needs.get-changes.outputs.binaries, matrix.crate) }} | |
with: | |
name: ${{ matrix.crate }}-${{ matrix.system }} | |
path: result/bin/ | |
if-no-files-found: error | |
- run: touch "build-success-${{ matrix.crate }}-${{ matrix.system }}" | |
- uses: actions/upload-artifact@v4 | |
with: | |
name: build-success-${{ matrix.crate }}-${{ matrix.system }} | |
path: build-success-${{ matrix.crate }}-${{ matrix.system }} | |
determine-tests: | |
needs: [ get-changes, build-artifacts ] | |
if: ${{ needs.get-changes.outputs.matrix != '{}' && always() }} | |
runs-on: ubuntu-latest | |
outputs: | |
test-matrix: ${{ steps.get-test-matrix.outputs.matrix }} | |
steps: | |
- uses: actions/download-artifact@v4 | |
with: | |
pattern: build-success-* | |
- name: Get Test Matrix | |
id: get-test-matrix | |
shell: bash | |
run: | | |
crate_systems=$(echo '${{ needs.get-changes.outputs.matrix }}' | jq -r '.crate[] as $crate | .system[] as $system | "\($crate)-\($system)"') | |
build_success_files=$(find . -maxdepth 2 -type f -name "build-success-*" -exec basename {} \;) | |
echo "Build Success Files: $build_success_files" | |
declare -A found_artifacts=() | |
for crate_system in $crate_systems; do | |
echo "Checking for build-success-$crate_system" | |
if [[ ${build_success_files[*]} =~ build-success-$crate_system ]]; then | |
echo "Found build-success-$crate_system" | |
readarray -d '-' -t split <<< "$crate_system" | |
split_len=${#split[@]} | |
crate=$(IFS=$'-' ; echo "${split[*]:0:$split_len-2}") | |
system=$(IFS=$'-' ; echo "${split[*]:$split_len-2:2}") | |
found_artifacts["$crate"]+="$system," | |
fi | |
done | |
if [ ${#found_artifacts[@]} = 0 ]; then | |
echo "No artifacts found." | |
echo "matrix={}" >> "$GITHUB_OUTPUT" | |
exit 0 | |
fi | |
matrix='{"system": ["x86_64-linux","aarch64-linux","x86_64-windows","aarch64-windows","x86_64-darwin","aarch64-darwin"], "crate": [' | |
for crate in "${!found_artifacts[@]}"; do | |
systems=${found_artifacts["$crate"]} | |
systems=${systems::-1} | |
matrix+="{\"name\": \"$crate\", \"systems\": [\"${systems//,/\",\"}\"]}," | |
done | |
matrix="${matrix::-1}]}" | |
echo "$matrix" | jq . | |
echo "matrix=$matrix" >> "$GITHUB_OUTPUT" | |
# We always want to cleanup the matrix artifacts. | |
- uses: geekyeggo/delete-artifact@v5 | |
if: ${{ always() }} | |
with: | |
name: build-success-* | |
run-tests: | |
needs: [ determine-tests ] | |
if: ${{ needs.determine-tests.outputs.test-matrix != '{}' }} | |
strategy: | |
fail-fast: false | |
matrix: ${{ fromJson(needs.determine-tests.outputs.test-matrix) }} | |
runs-on: ${{ endsWith(matrix.system, 'darwin') && 'macos-latest' || 'ubuntu-latest' }} | |
name: Run Tests for ${{ matrix.crate.name }} on ${{ matrix.system }} | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: cachix/install-nix-action@v30 | |
- uses: DeterminateSystems/magic-nix-cache-action@v8 | |
- name: Should we run tests? | |
id: should-run-tests | |
run: | | |
echo "run_tests=false" >> "$GITHUB_OUTPUT" | |
host_system=$(nix eval --raw nixpkgs#system) | |
successful_builds=(${{ matrix.crate.systems }}) | |
# If crate.systems does not contain the host system, the build was not successful and we should exit. | |
if [[ ${successful_builds[*]} =~ $host_system ]]; then | |
echo "Build was not successful for $host_system." | |
exit 0 | |
fi | |
echo "run_tests=true" >> "$GITHUB_OUTPUT" | |
- name: Run Tests | |
if: ${{ steps.should-run-tests.outputs.run_tests == 'true' }} | |
run: nix develop --impure -c cargo nextest run --package ${{ matrix.crate.name }} --all-features | |
- name: Run Doc Tests | |
if: ${{ steps.should-run-tests.outputs.run_tests == 'true' }} | |
run: nix develop --impure -c cargo test --doc --package ${{ matrix.crate.name }} |