name: Build

on:
  push:
    paths-ignore:
      - '**.md'
  pull_request:
    paths-ignore:
      - '**.md'

jobs:
  build:
    runs-on: windows-latest

    steps:
    - uses: actions/checkout@v3

    - uses: actions/checkout@v3
      with:
        repository: 'itsmattkc/msvc420'
        path: msvc420

    - name: Setup cmake
      uses: jwlawson/actions-setup-cmake@v1.13
      with:
        # Use minimum supported version
        cmake-version: '3.13.x'

    - name: Build wrappers
      shell: cmd
      run: |
        call .\msvc420\bin\VCVARS32.BAT x86
        cd wrappers
        mkdir build
        cd build
        cmake .. -G "NMake Makefiles" -DCMAKE_BUILD_TYPE=Release
        cmake --build .
    
    - name: Generate patched MSIL
      shell: cmd
      run: |
        msil\patch.bat

    - name: Build installer
      shell: cmd
      run: |
        setup\nsis\makensis.exe setup\dotnet9x.nsi

    - name: Upload Artifact
      uses: actions/upload-artifact@master
      with:
        name: setup
        path: |
          setup/dotnet9x.exe

    - name: Upload Continuous Release
      if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/master' && github.repository == 'itsmattkc/dotnet9x' }}
      shell: bash
      env:
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
      run: |
        curl -fLOSs --retry 2 --retry-delay 60 https://github.com/probonopd/uploadtool/raw/master/upload.sh
        bash upload.sh setup/dotnet9x.exe