name: build Workflow

on:
  workflow_call:  
    inputs:
      image_name:
        required: true
        type: string
        default: ubuntu
      image_tag:
        required: false
        type: string
        default: latest
      run_platform:
        required: false
        type: string
        default: amd64
    secrets:
      TEST_CMD:
        required: true
      
jobs:
  build:
    runs-on: ${{ inputs.run_platform }}
    container: 
      image: ${{ inputs.image_name }}:${{ inputs.image_tag }}
    steps:

      - name: Checkout code
        uses: actions/checkout@v4
        env:
          https_proxy: ${{ secrets.https_proxy }}
          http_proxy: ${{ secrets.http_proxy }}
        with:
          ref: ${{ github.event.pull_request.head.sha }}
    
      - name: Run build stage
        env:
          https_proxy: ""
          http_proxy: ""
          no_proxy: "*"
        shell: bash
        run: |
          if [ -d "./build" ]; then
            ls -lah ./build
          fi

          echo "removing CMakeCache.txt"
          rm -rf ./build/CMakeCache.txt

          source /opt/ros/humble/setup.bash
          eval "${{ secrets.BUILD_CMD}}"

          echo "ls -lah ${{vars.PROJECT_ARTIFACTS_DIR}}"
          ls -lah ${{vars.PROJECT_ARTIFACTS_DIR}}
          
          echo "ls -lah ${{vars.WHL_ARTIFACTS_DIR}}"
          ls -lah ${{vars.WHL_ARTIFACTS_DIR}}
        
      - name: upload build artifact
        if: github.action
        uses: actions/upload-artifact@v3
        with:
          name: build_artifact
          path: |
            ${{vars.WHL_ARTIFACTS_DIR}}
          retention-days: 3
      