# This workflow will install Python dependencies, run tests and lint with a single version of Python
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python

name: model-test

on:
  workflow_call:

jobs:
  model-test:
    runs-on: jiuding
    steps:
      - name: Checkout code
        uses: actions/checkout@v4

      - name: Check GPU free
        shell: bash
        run: tools/gpu_check.sh

      - name: FlagGems examples
        shell: bash
        run: |
          echo "current dir: $(pwd)"
          git config --global --add safe.directory ../FlagGems
          if [ "${{ github.event_name }}" == "pull_request" ]; then
            echo "This is a pull request event. PR number is ${{ github.event.pull_request.number }}"
            PR_ID=${{ github.event.pull_request.number }}
          elif [ "${{ github.event_name }}" == "push" ]; then
            PR_NUMBER=$(git log -1 --pretty=format:'%s' | grep -oE '#[0-9]+' | grep -oE '[0-9]+')
            echo "This is a push event. The relate PR number is ${PR_NUMBER}"
            PR_ID=${PR_NUMBER}
          fi
          bash tools/model-test.sh ${PR_ID}