name: Test OSDK

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

jobs:
  osdk-test:
    runs-on: ubuntu-latest
    timeout-minutes: 30
    strategy:
      matrix:
        # asterinas/asterinas:0.6.0 container is the developing container of asterinas,
        # asterinas/osdk:0.6.0 container is built with the intructions from Asterinas Book
        container: ['asterinas/asterinas:0.6.0', 'asterinas/osdk:0.6.0']
    container: ${{ matrix.container }}
    steps:
      - run: echo "Running in ${{ matrix.container }}"

      - uses: actions/checkout@v4

      - name: Lint
        id: lint
        if: matrix.container == 'asterinas/asterinas:0.6.0'
        run: make check_osdk

      # 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.
      - name: Unit test
        id: unit_test
        run: |
          cd osdk
          RUSTUP_HOME=/root/.rustup cargo +stable build
          RUSTUP_HOME=/root/.rustup cargo test
