algonaut 0.9.0

A Rusty sdk for the Algorand blockchain.
Documentation
name: Continuous integration

on:
  push:
    branches: [main]
  pull_request:

concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}

env:
  CARGO_TERM_COLOR: always
  RUSTFLAGS: -D warnings

jobs:
  # Gate the build jobs: a docs-only change skips them. Skipped jobs report
  # their check as "skipped", which branch protection treats as passing — so
  # the required checks stay green without burning a full CI run. (Workflow
  # level `paths-ignore` cannot be used: it would leave required checks stuck
  # in a pending "Expected" state forever.)
  changes:
    name: changes
    runs-on: ubuntu-latest
    outputs:
      code: ${{ steps.filter.outputs.code }}
    steps:
      # `dorny/paths-filter@v3` needs a checkout for `push` events (it shells
      # out to git to compare against the base). `pull_request` events use the
      # API and don't need this, but pushes to main were failing with
      # `fatal: not a git repository` until this step was added.
      - uses: actions/checkout@v4
      - uses: dorny/paths-filter@v3
        id: filter
        with:
          filters: |
            code:
              - '**'
              - '!**/*.md'
              - '!docs/**'

  cargo-fmt:
    name: cargo-fmt
    needs: changes
    if: needs.changes.outputs.code == 'true'
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: dtolnay/rust-toolchain@stable
        with:
          components: rustfmt
      - run: cargo fmt --all -- --check

  cargo-check:
    name: cargo-check
    needs: changes
    if: needs.changes.outputs.code == 'true'
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: dtolnay/rust-toolchain@stable
      - uses: Swatinem/rust-cache@v2
      - run: cargo check --workspace --all-targets

  cargo-check-wasm:
    name: cargo-check-wasm
    needs: changes
    if: needs.changes.outputs.code == 'true'
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: dtolnay/rust-toolchain@stable
        with:
          targets: wasm32-unknown-unknown
      - uses: Swatinem/rust-cache@v2
        with:
          key: wasm32
      - run: cargo check --target wasm32-unknown-unknown

  cargo-clippy:
    name: cargo-clippy
    needs: changes
    if: needs.changes.outputs.code == 'true'
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: dtolnay/rust-toolchain@stable
        with:
          components: clippy
      - uses: Swatinem/rust-cache@v2
      - run: cargo clippy --workspace --all-targets -- -D warnings

  cargo-test:
    name: cargo-test
    needs: changes
    if: needs.changes.outputs.code == 'true'
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: dtolnay/rust-toolchain@stable
      - uses: Swatinem/rust-cache@v2
      - run: cargo test --workspace --lib --examples --tests

  cargo-test-integration:
    name: cargo-test-integration
    needs: changes
    if: needs.changes.outputs.code == 'true'
    runs-on: ubuntu-24.04
    timeout-minutes: 30
    steps:
      - uses: actions/checkout@v4
      - uses: docker/setup-buildx-action@v3
      - uses: dtolnay/rust-toolchain@stable
      - uses: Swatinem/rust-cache@v2
        with:
          key: integration
      - name: Bring up the algorand test harness
        run: ./test-harness.sh up
      - name: Dump sandbox.log on harness failure
        if: failure()
        run: |
          test -f test-harness/.sandbox/sandbox.log \
            && cat test-harness/.sandbox/sandbox.log \
            || echo "No sandbox.log to dump."
      - name: Run cucumber integration tests
        run: cargo test --test cucumber --
      - name: Tear down the algorand test harness
        if: always()
        run: ./test-harness.sh down

  cargo-test-e2e:
    name: cargo-test-e2e
    needs: changes
    if: needs.changes.outputs.code == 'true'
    runs-on: ubuntu-24.04
    timeout-minutes: 20
    steps:
      - uses: actions/checkout@v4
      - uses: dtolnay/rust-toolchain@stable
      - uses: Swatinem/rust-cache@v2
        with:
          key: e2e
      # Unlike the cucumber harness, the sandbox pulls prebuilt images (no
      # source build, so no buildx) and binds the standard ports the e2e tests
      # default to (algod :4001, kmd :4002). Its own health-wait can time out
      # under load even when the node comes up moments later, so don't gate on
      # its exit code — the readiness poll below is the real check.
      - name: Bring up a local Algorand sandbox
        run: make sandbox || true
      - name: Wait for algod + kmd to be ready
        run: |
          token=$(printf 'a%.0s' {1..64})
          for i in $(seq 1 60); do
            if curl -sf -o /dev/null http://localhost:4001/genesis \
              && curl -sf -o /dev/null -H "X-KMD-API-Token: $token" http://localhost:4002/v1/wallets; then
              echo "algod + kmd ready"; exit 0
            fi
            sleep 2
          done
          echo "sandbox did not become ready"; docker ps -a
          cat sandbox/sandbox.log 2>/dev/null || true
          exit 1
      - name: Run the ARC-56 end-to-end tests
        run: make test-e2e
      - name: Dump sandbox logs on failure
        if: failure()
        run: |
          cat sandbox/sandbox.log 2>/dev/null || echo "No sandbox.log to dump."
          docker logs algorand-sandbox-algod 2>&1 | tail -100 || true
      - name: Tear down the sandbox
        if: always()
        run: make sandbox-down