name: OSDK Test

on:
  pull_request:
    paths:
      - framework/**
      - osdk/**
      - tools/**
      - Cargo.toml
  push:
    branches:
      - main

jobs:
  osdk-test:
    runs-on: ubuntu-latest
    timeout-minutes: 30
    container: asterinas/asterinas:0.4.2
    steps:
      - run: echo "Running in asterinas/asterinas:0.4.2"

      - uses: actions/checkout@v4

      - name: Lint
        id: lint
        run: cd osdk && cargo clippy -- -D warnings

        # The OSDK unit test features a recursive call of Cargo,
        # which will break when RUSTUP_HOME is altered in the case
        # of actions/checkout@v4
      - name: Unit test
        id: unit_test
        run: cd osdk && cargo build && RUSTUP_HOME=/root/.rustup cargo test
  
  # Test OSDK in the same environment 
  # as described in the OSDK User Guide in the Asterinas Book.
  osdk-doc-env-test:
    runs-on: ubuntu-latest
    timeout-minutes: 15
    container: asterinas/osdk:0.4.2
    steps:
      - run: echo "Running in asterinas/osdk:0.4.2"

      - uses: actions/checkout@v4

      - name: Unit test
        id: unit_test
        # Github's actions/checkout@v4 will result in a new user (not root) 
        # and thus not using the Rust environment we set up in the container. 
        # So the RUSTUP_HOME needs to be set here. 
        # This only breaks when we invoke Cargo in the integration test of OSDK 
        # since the OSDK toolchain is not nightly.
        run: cd osdk && cargo build && RUSTUP_HOME=/root/.rustup cargo test
    
