# Release a new TW Blue installer on github.
# This workflow runs on push.
name: Release
on:
  push:
    tags:
      - v20*
  workflow_dispatch:

jobs:
  build:
  # Builds an x64 binary and an installer of TW Blue.
    runs-on: windows-latest
    steps:
      - name: clone repo
        uses: actions/checkout@v4
        with:
          submodules: true
      - name: Get python interpreter
        uses: actions/setup-python@v4
        with:
          python-version: '3.10'

      - name: Install python packages
        run: python -m pip install -r requirements.txt

      - name: Build binary
        run: |
          .\scripts\build.ps1
          mv src/dist scripts\TWBlue64

      - name: make installer
        run: |
          cd scripts
          makensis twblue.nsi

      - name: Create portable
        working-directory: scripts\TWBlue64
        run: |
          7z a -tzip TWBlue_portable.zip .

      - name: Create new release
        env:
          gh_token: ${{ github.token }}
        run: |
          mkdir .release-assets
          mv scripts\TWBlue_setup.exe .release-assets\TWBlue_setup_${{github.ref_name}}.exe
          mv scripts\TWBlue64\TWBlue_portable.zip .release-assets\TWBlue_portable_${{github.ref_name}}.zip
          gh release create "${{github.ref_name}}" -F "release-notes.md" -t "${{github.ref_name}}" .release-assets\TWBlue_setup_${{github.ref_name}}.exe .release-assets\TWBlue_portable_${{github.ref_name}}.zip