name: .NET Core CI

on:
  push:
    branches: [ master ]

jobs:
  build:

    runs-on: windows-latest

    steps:
    - uses: actions/checkout@v2

    - name: Setup .NET
      uses: actions/setup-dotnet@v1
      with:
        dotnet-version: '8.0.x'

    - name: Restore dependencies
      run: dotnet restore ./Bot/Lunaris2.csproj

    - name: Build
      run: dotnet build ./Bot/Lunaris2.csproj --no-restore -c Release -o ./out

    - name: Publish
      run: dotnet publish ./Bot/Lunaris2.csproj --configuration Release --output ./out

    - name: Zip the build
      run: 7z a -tzip ./out/Bot.zip ./out/*

    - name: Get the tag name
      id: get_tag
      run: echo "::set-output name=tag::${GITHUB_REF#refs/tags/}"

    - name: Get the version
      id: get_version
      run: echo "::set-output name=version::$(date +%s).${{ github.run_id }}"

    - name: Create Release
      id: create_release
      uses: actions/create-release@v1
      env:
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token
      with:
        tag_name: ${{ steps.get_version.outputs.version }}
        release_name: Release v${{ steps.get_version.outputs.version }}
        draft: false
        prerelease: false

    - name: Upload Release Asset
      id: upload-release-asset 
      uses: actions/upload-release-asset@v1
      env:
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
      with:
        upload_url: ${{ steps.create_release.outputs.upload_url }}
        asset_path: ./out/Bot.zip
        asset_name: Bot.zip
        asset_content_type: application/zip
