# Release — creates ZIP packages for Chrome, Firefox and Opera on new tag
name: Release

on:
  push:
    tags:
      - 'v*'

permissions:
  contents: write

jobs:
  build-release:
    name: Build & Release
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6

      - name: Extract version from tag
        id: version
        run: echo "tag=${GITHUB_REF#refs/tags/}" >> "$GITHUB_OUTPUT"

      - name: Create Chrome/Edge ZIP (Manifest V3)
        run: |
          mkdir -p dist
          zip -r "dist/hellion-newtab-${{ steps.version.outputs.tag }}-chrome.zip" \
            manifest.json newtab.html src/js/*.js src/css/ assets/ _locales/ \
            -x "*.git*" "dist/*" ".github/*" "src/js/opera/*"

      - name: Create Firefox ZIP (Manifest V3)
        run: |
          cp manifest.json manifest.chrome-backup.json
          cp manifest.firefox.json manifest.json
          zip -r "dist/hellion-newtab-${{ steps.version.outputs.tag }}-firefox.zip" \
            manifest.json newtab.html src/js/*.js src/css/ assets/ _locales/ \
            -x "*.git*" "dist/*" ".github/*" "manifest.chrome-backup.json" "manifest.firefox.json" "src/js/opera/*"
          mv manifest.chrome-backup.json manifest.json

      - name: Create Opera/Opera GX ZIP (Manifest V3 + workaround)
        run: |
          cp manifest.json manifest.chrome-backup.json
          cp manifest.opera.json manifest.json
          zip -r "dist/hellion-newtab-${{ steps.version.outputs.tag }}-opera.zip" \
            manifest.json newtab.html src/js/*.js src/js/opera/ src/css/ assets/ _locales/ \
            -x "*.git*" "dist/*" ".github/*" "manifest.chrome-backup.json" "manifest.opera.json"
          mv manifest.chrome-backup.json manifest.json

      - name: Generate SHA256 checksums
        run: |
          cd dist
          sha256sum *.zip > checksums-sha256.txt
          cat checksums-sha256.txt

      - name: Create GitHub Release
        uses: softprops/action-gh-release@b4309332981a82ec1c5618f44dd2e27cc8bfbfda # v3
        with:
          name: "Hellion NewTab ${{ steps.version.outputs.tag }}"
          body: |
            ## Hellion NewTab ${{ steps.version.outputs.tag }}

            ### Installation
            - **Chrome / Edge / Brave / Vivaldi:** `hellion-newtab-${{ steps.version.outputs.tag }}-chrome.zip`
            - **Firefox:** `hellion-newtab-${{ steps.version.outputs.tag }}-firefox.zip`
            - **Opera / Opera GX:** `hellion-newtab-${{ steps.version.outputs.tag }}-opera.zip`

            See [README](README.md) for the full installation instructions.

            ### Checksums
            See `checksums-sha256.txt` to verify file integrity.
          files: |
            dist/hellion-newtab-${{ steps.version.outputs.tag }}-chrome.zip
            dist/hellion-newtab-${{ steps.version.outputs.tag }}-firefox.zip
            dist/hellion-newtab-${{ steps.version.outputs.tag }}-opera.zip
            dist/checksums-sha256.txt
          generate_release_notes: true