name: MSBuild

on:
    push:
        branches: ["master"]
    pull_request:
        branches: ["master"]

env:
    SOLUTION_FILE_PATH: .

    BUILD_CONFIGURATION: Release

permissions:
    contents: read

jobs:
    build:
        runs-on: windows-latest

        steps:
            - uses: actions/checkout@v3

            - uses: actions/cache@v3
              with:
                  key: ${{ runner.os }}-deno-${{ hashFiles('**/deps.ts') }}-${{ hashFiles('**/import_map.json') }}
                  path: |
                      ~\.deno
                      ~\AppData\Local\deno
            - uses: actions/cache@v3
              with:
                  path: |
                      C:\vcpkg
                      ./vcpkg

                  key: ${{ runner.os }}-vcpkg-${{ hashFiles('**/xmake.lua') }}
            - uses: actions/cache@v3
              with:
                  path: |
                      C:\Users\runneradmin\AppData\Local\.xmake

                  key: ${{ runner.os }}-xmake-${{ hashFiles('**/xmake.lua') }}
            - name: Add MSBuild to PATH
              uses: microsoft/setup-msbuild@v1.0.2
              with:
                  vs-prerelease: true

            - name: vcpkg-action

              uses: johnwason/vcpkg-action@v4
              with:
                  triplet: x64-windows-release
                  pkgs: "gtest cppunit"

                  token: ${{ github.token }}
            - name: Setup Deno

              uses: denoland/setup-deno@v1.1.0
              with:
                  deno-version: v1.33.1
            - uses: xmake-io/github-action-setup-xmake@v1

              with:
                  xmake-version: branch@dev
                  actions-cache-folder: ".xmake-cache"

            - run: deno task cache
            - run: xmake lua install.lua
            - run: deno run -A xmake.ts --mode=test --group=test --executable=C:\hostedtoolcache\windows\xmake\dev\x64\xmake.exe
            - run: C:\hostedtoolcache\windows\xmake\dev\x64\xmake.exe clean  -a
            - run: C:\hostedtoolcache\windows\xmake\dev\x64\xmake.exe f   -y -v --project=. "--file=./xmake.lua"
            - run: C:\hostedtoolcache\windows\xmake\dev\x64\xmake.exe build -v -y  -w --project=. "--file=./xmake.lua"
              continue-on-error: true
            - run: C:\hostedtoolcache\windows\xmake\dev\x64\xmake.exe clean  -a
            - run: C:\hostedtoolcache\windows\xmake\dev\x64\xmake.exe f   -y -v --project=. "--file=./xmake.lua" --mode=test
            - run: xmake.exe build -v -y  -w --project=. "--file=./xmake.lua" --group=test
            - run: xmake run --group=test
