name: Build & Release ThemeChanger

on:
  push:
    branches:
      - main

jobs:
  release:
    name: Build and Upload Release ZIP
    runs-on: windows-latest

    permissions:
      contents: write  # Needed for creating/updating releases

    steps:
      - name: Checkout code
        uses: actions/checkout@v4

      - name: Set up Go
        uses: actions/setup-go@v5
        with:
          go-version: '1.21'

      - name: Tidy dependencies
        run: go mod tidy

      - name: Build executable
        run: go build -ldflags="-H windowsgui" -o themechanger.exe

      - name: Create ZIP with icon and binary
        run: Compress-Archive -Path themechanger.exe,icon.ico,dark.jpg,light.jpg -DestinationPath themechanger.zip

      - name: Create or update release
        uses: softprops/action-gh-release@v2
        with:
          tag_name: latest
          name: Latest Build
          files: themechanger.zip
          body: |
            ✅ Automatic build from latest commit to `main`  
            🛠️ Includes `themechanger.exe` and `icon.ico`  
            🔄 Ready to drop into `shell:startup`

        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
