name: Netch CI
on: [push, pull_request]
jobs:
  build:
    name: Build
    runs-on: windows-latest
    steps:
    - name: Setup MSBuild
      uses: microsoft/setup-msbuild@v1.0.2

    - name: Checkout
      uses: actions/checkout@v2
      with:
        submodules: true

    - name: Build Solution
      shell: pwsh
      run: .\BUILD.ps1

    - name: Upload Artifact
      continue-on-error: true
      if: ${{ !startsWith(github.ref, 'refs/tags/') }}
      uses: actions/upload-artifact@v2
      with:
        name: Netch
        path: Netch\bin\x64\Release

    - name: Package
      if: ${{ github.event_name == 'push' && startsWith(github.ref, 'refs/tags/') }}
      shell: pwsh
      run: |
        New-Item -ItemType Directory -Path C:\builtfiles -Force > $null
        7z a -mx9 C:\builtfiles\Netch.7z .\Netch\bin\x64\Release\
        7z rn C:\builtfiles\Netch.7z Release Netch
        echo "Netch_SHA256=$(.\GetSHA256.ps1 C:\builtfiles\Netch.7z)" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
        echo "Netch_EXE_SHA256=$(.\GetSHA256.ps1 Netch\bin\x64\Release\Netch.exe)" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append

    - name: Release
      uses: softprops/action-gh-release@v1
      env:
        GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
      if: ${{ github.event_name == 'push' && startsWith(github.ref, 'refs/tags/') }}
      with:
        name: ${{ env.GITHUB_TAG_NAME }}
        prerelease: true
        draft: false
        files: |
          C:\builtfiles\Netch.7z
        body: |
          [![](https://img.shields.io/badge/Telegram-Channel-blue)](https://t.me/Netch) [![](https://img.shields.io/badge/Telegram-Group-green)](https://t.me/Netch_Discuss_Group)

          ## 更新日志
          * 这是 GitHub Actions 自动化部署，更新日志应该很快会手动更新

          ## 校验和
          | 文件名 | SHA256 |
          | :- | :- |
          | Netch.7z | ${{ env.Netch_SHA256 }} |