name: Linux
on:
  push:
    tags:
      - "*"

permissions:
  contents: write

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - name: Check out repository code
        uses: actions/checkout@v6
        with:
          submodules: "recursive"
      - name: Docker caching
        uses: ScribeMD/docker-cache@0.5.0
        id: cache
        continue-on-error: true
        with:
          key: wiiudownloader-docker-cache-${{ hashFiles('Dockerfile.linux') }}
      - name: Build Docker container
        if: steps.cache.outputs.cache-hit != 'true'
        run: |
          docker build . --file Dockerfile.linux --tag builder
      - name: Build artifacts
        run: |
          docker run --rm -v ${PWD}:/project builder bash -lc "curl -Lo db.go -H 'User-Agent: NUSspliBuilder/2.1' 'https://napi.v10lator.de/db?t=go' && go build -C cmd/WiiUDownloader -o ../../WiiUDownloader ."
      - name: Deploy WiiUDownloader
        run: |
          docker run --privileged --rm -e DEPLOY_GTK_VERSION=3 -e OUTPUT="WiiUDownloader-Linux-x86_64.AppImage" -e UPDATE_INFORMATION="gh-releases-zsync|Xpl0itU|WiiUDownloader|latest|WiiUDownloader-*.AppImage.zsync" -v ${PWD}:/project builder linuxdeploy.AppImage --plugin gtk --plugin checkrt --output=appimage --create-desktop-file --executable=WiiUDownloader --appdir dist --icon-file data/WiiUDownloader.png
      - name: Upload Linux Artifact
        uses: ncipollo/release-action@v1
        with:
          allowUpdates: True
          makeLatest: True
          omitBody: True
          omitBodyDuringUpdate: True
          omitNameDuringUpdate: True
          artifacts: "WiiUDownloader-*.AppImage"
          token: ${{ secrets.GITHUB_TOKEN }}
