# Usage:
#
# Build:
#   uses: "./.github/workflows/build"
#   with:
#     build_type: Debug
#
#

name: Build

on:
  workflow_call:
    inputs:
      build_type:
        description: 'Build type to pass to `dotnet`, should be either "Debug" or "Release"'
        required: false
        default: "Debug"
        type: string
    outputs:
      schemas_changed:
        description: 'Have the schemas been updated?'
        value: ${{ jobs.Build.outputs.schemas_changed }}


  
jobs:
  Build:
    runs-on: windows-latest
    outputs:
      schemas_changed: ${{ steps.changed_files.outputs.files_changed }}
    steps:

    - name: Checkout Repo
      uses: actions/checkout@v2

    - name: Setup .NET
      uses: actions/setup-dotnet@v1

    # Disable Strong Name Verification to let us pull a switch-a-roo
    - name: Disable strong name validation
      run: "C:\\\"Program Files (x86)\"\\\"Microsoft SDKs\"\\Windows\\v10.0A\\bin\\\"NETFX 4.8 Tools\"\\x64\\sn.exe -Vr *"
       
    - name: Remove .csproj.user
      run: "rm .\\NewHorizons\\NewHorizons.csproj.user"

    - name: Build Project
      run: dotnet build -c ${{ inputs.build_type }}
        
    - name: Generate Schemas
      run: .\SchemaExporter\bin\${{ inputs.build_type }}\SchemaExporter.exe
      
    - name: Delete XML documentation
      run: rm .\NewHorizons\bin\${{ inputs.build_type }}\NewHorizons.xml
      
    - name: Upload Mod Artifact
      uses: actions/upload-artifact@v2
      with:
        name: xen.NewHorizons.${{ inputs.build_type }}
        path: .\NewHorizons\bin\${{ inputs.build_type }}
        
    - name: Upload Schemas Artifact
      uses: actions/upload-artifact@v2
      with:
        name: NewHorizons-Schemas-${{ inputs.build_type }}
        path: .\NewHorizons\Schemas

    - name: Verify Changed Schemas
      uses: tj-actions/verify-changed-files@v9.1
      id: changed_files
      with:
        files: NewHorizons/Schemas/**
      
