feat: snapshot tests during CI #541
Workflow file for this run
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: | |
workflow_dispatch: | |
push: | |
branches: ["main"] | |
pull_request: | |
types: [opened, synchronize, reopened, ready_for_review] | |
branches: ["*"] | |
env: | |
CARGO_TERM_COLOR: always | |
# Disable incremental compilation for faster from-scratch builds | |
CARGO_INCREMENTAL: 0 | |
CARGO_PROFILE_TEST_DEBUG: 0 | |
CARGO_PROFILE_RELEASE_LTO: true | |
CARGO_PROFILE_RELEASE_CODEGEN_UNITS: 1 | |
jobs: | |
sanity: | |
name: Sanity | |
timeout-minutes: 30 | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: Swatinem/rust-cache@v2 | |
with: | |
prefix-key: ${{ runner.os }} | |
- name: Check format | |
run: cargo fmt-amaru | |
- name: Run clippy | |
run: cargo clippy-amaru | |
build: | |
name: Build on ${{ matrix.environments.runner }} with target ${{ matrix.environments.target }} | |
strategy: | |
fail-fast: false | |
matrix: | |
environments: | |
- runner: ubuntu-latest | |
target: x86_64-unknown-linux-gnu | |
- runner: macos-latest | |
target: aarch64-apple-darwin | |
- runner: windows-latest | |
target: x86_64-pc-windows-msvc | |
command: test --profile dev-debug | |
- runner: ubuntu-latest | |
target: wasm32-unknown-unknown | |
packages: -p amaru-ledger -p amaru-ouroboros -p slot-arithmetic | |
command: build | |
setup: rustup target add wasm32-unknown-unknown | |
- runner: ubuntu-latest | |
target: riscv32im-risc0-zkvm-elf | |
packages: -p amaru-ledger -p slot-arithmetic | |
extra-args: +nightly -Zbuild-std=std,panic_abort | |
command: build | |
setup: | | |
curl -L https://risczero.com/install | bash | |
/home/runner/.risc0/bin/rzup install | |
rustup toolchain add nightly-x86_64-unknown-linux-gnu | |
rustup component add rust-src --toolchain nightly-x86_64-unknown-linux-gnu | |
# Disabled for now | |
#- runner: ubuntu-latest | |
# target: aarch64-unknown-linux-musl | |
# cross-compile: true | |
timeout-minutes: 30 | |
runs-on: ${{ matrix.environments.runner }} | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: Swatinem/rust-cache@v2 | |
with: | |
prefix-key: ${{ runner.os }}-${{ matrix.environments.target }} | |
- name: Run tests | |
run: | | |
set +e | |
EXTRA_ARGS="${{ matrix.environments.extra-args || '' }}" | |
SCOPE="${{ matrix.environments.packages || '--workspace' }}" | |
COMMAND="${{ matrix.environments.command || 'test' }}" | |
if [[ -n "${{ matrix.environments.setup }}" ]]; then | |
echo "Running setup command: ${{ matrix.environments.setup }}" | |
${{ matrix.environments.setup }} | |
fi | |
if [[ "${{ matrix.environments.cross-compile }}" == "true" ]] ; then | |
cargo install cross --git https://github.com/cross-rs/cross | |
# cross doesn't load .cargo/config.toml, see https://github.com/cross-rs/cross/issues/562 | |
$HOME/.cargo/bin/cross $COMMAND --locked --all-features $SCOPE --target ${{ matrix.environments.target }} | |
else | |
cargo $EXTRA_ARGS $COMMAND $SCOPE --locked --target ${{ matrix.environments.target }} | |
fi | |
exitcode="$?" | |
if [[ "${{ matrix.environments.optional }}" == "true" && "$exitcode" != "0" ]] ; then | |
# Propagate failure as a warning | |
# but do not fail the job | |
echo "::warning::Tests failed with exit code $exitcode" | |
exit 0 | |
else | |
exit "$exitcode" | |
fi | |
shell: bash | |
snapshots: | |
name: Snapshots | |
runs-on: ubuntu-latest | |
if: ${{ !github.event.pull_request.draft }} | |
env: | |
AMARU_PEER_ADDRESS: 127.0.0.1:3001 | |
strategy: | |
matrix: | |
network: [ preprod ] | |
cardano_node_version: [ 10.1.4 ] | |
steps: | |
- uses: actions/checkout@v4 | |
- id: date-time | |
shell: bash | |
run: echo "timestamp=$(/bin/date -u "+%Y%m%d-%H%M%S")" >> $GITHUB_OUTPUT | |
- name: Restore cardano-node DB | |
id: cache-cardano-node-db | |
uses: actions/cache/restore@v4 | |
with: | |
# The path should match the one used for the 'Nightly Sync' workflow. | |
path: ${{ runner.temp }}/db-${{ matrix.network }} | |
# The key should also match | |
key: cardano-node-ogmios-${{ matrix.network }}-${{ steps.date-time.outputs.timestamp }} | |
restore-keys: | | |
cardano-node-ogmios-${{ matrix.network }}- | |
- name: Check if cardano-node-db is available | |
if: steps.cache-cardano-node-db.outputs.cache-hit == '' | |
run: | | |
echo "Haskell node db not available, aborting job." | |
exit 1 | |
- name: Spawn Haskell Node | |
id: spawn-cardano-node | |
shell: bash | |
run: | | |
docker pull ghcr.io/intersectmbo/cardano-node:${{ matrix.cardano_node_version }} | |
make HASKELL_NODE_CONFIG_DIR=cardano-node-config NETWORK=${{ matrix.network }} download-haskell-config | |
docker run -d --name cardano-node \ | |
-v ${{ runner.temp }}/db-${{ matrix.network }}:/db \ | |
-v ${{ runner.temp }}/ipc:/ipc \ | |
-v ./cardano-node-config:/config \ | |
-v ./cardano-node-config:/genesis \ | |
-p 3001:3001 \ | |
ghcr.io/intersectmbo/cardano-node:${{ matrix.cardano_node_version }} run \ | |
--config /config/config.json \ | |
--database-path /db \ | |
--socket-path /ipc/node.socket \ | |
--topology /config/topology.json | |
- uses: Swatinem/rust-cache@v2 | |
- name: Build Amaru | |
run: | | |
cargo build --release --locked | |
- name: Cache Amaru's ledger.db | |
id: cache-ledger-db | |
uses: actions/cache@v3 | |
with: | |
path: | | |
~/ledger.db/163 | |
~/ledger.db/164 | |
~/ledger.db/165 | |
key: ${{ runner.OS }}-ledger-cache-${{ hashFiles('.ledger.db/**') }} | |
restore-keys: | | |
${{ runner.OS }}-ledger-cache- | |
- name: Full bootstrap amaru | |
if: steps.cache-ledger-db.outputs.cache-hit != 'true' | |
run: | | |
make bootstrap | |
- name: Light bootstrap amaru | |
if: steps.cache-ledger-db.outputs.cache-hit == 'true' | |
run: | | |
make import-headers | |
make import-nonces | |
# - name: Run node | |
# timeout-minutes: 30 | |
# shell: bash | |
# run: | | |
# set -eo pipefail | |
# # Make sure amaru runs long enough so that snapshot tests can be executed | |
# AMARU_TRACE="amaru=debug" cargo run --release -- --with-json-traces daemon --peer-address=$AMARU_PEER_ADDRESS --network=${{ matrix.network }} | while read -r line; do | |
# TARGET_EPOCH=173 | |
# | |
# MESSAGE=$(echo $line | jq -r '.fields.message' 2>/dev/null) | |
# EPOCH=$(echo $line | jq -r '.fields.epoch' 2>/dev/null) | |
# | |
# echo "line: $line" | |
# echo "message: $MESSAGE" | |
# echo "epoch: $EPOCH" | |
# | |
# | |
# if [ "$MESSAGE" == "stake_distribution.snapshot" ] && [ "$EPOCH" == "$TARGET_EPOCH" ]; then | |
# echo "Target epoch reached, stopping the process." | |
# pkill -P $$ | |
# break | |
# fi | |
# done | |
# | |
# - name: Run tests | |
# run: cargo test --release --locked -p amaru -- --ignored | |
- name: Teardown haskell node | |
shell: bash | |
run: | | |
docker stop ${{ steps.spawn-cardano-node.outputs.container }} | |
docker rm ${{ steps.spawn-cardano-node.outputs.container }} | |
examples: | |
name: Examples | |
strategy: | |
fail-fast: false | |
matrix: | |
projects: | |
- path: ledger-in-nodejs | |
commands: | | |
rustup target add wasm32-unknown-unknown | |
make | |
defaults: | |
run: | |
working-directory: examples/${{ matrix.projects.path }} | |
timeout-minutes: 30 | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: Swatinem/rust-cache@v2 | |
with: | |
prefix-key: ${{ matrix.projects.path }} | |
- name: Run commands | |
run: ${{ matrix.projects.commands }} |