name: Release
on:
  push:
    tags:
      - v*.*.*
  # pull_request:
  #   branches:
  #     - master

permissions:
  contents: write
  actions: read

jobs:
  goreleaser:
    strategy:
      matrix:
        # platform: [ubuntu-latest, windows-latest, macos-13]
        platform: [ubuntu-latest]

    runs-on: ${{ matrix.platform }}
    steps:
      - name: Checkout
        uses: actions/checkout@v7
        with:
          fetch-depth: 0
      - name: Fetch all tags
        run: git fetch --force --tags
      - name: Set up Go
        uses: actions/setup-go@v7
        with:
          go-version: "1.26"

      - # LINUX ################################################################
        if: matrix.platform == 'ubuntu-latest'
        name: linux-deps
        run: |
          sudo apt-get -yq install gcc-aarch64-linux-gnu cmake pkg-config jq libusb-1.0-0-dev
      - if: matrix.platform == 'ubuntu-latest'
        name: install-unicorn
        run: |
          cd /tmp
          git clone https://github.com/unicorn-engine/unicorn.git
          cd unicorn
          mkdir build; cd build
          # cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_COMPILER=gcc-aarch64-linux-gnu -DUNICORN_ARCH=aarch64
          cmake .. -DCMAKE_BUILD_TYPE=Release -DUNICORN_ARCH=aarch64
          make
          sudo make install
      # -
      #   if: matrix.platform == 'ubuntu-latest'
      #   name: setup-snapcraft
      #   # FIXME: the mkdirs are a hack for https://github.com/goreleaser/goreleaser/issues/1715
      #   run: |
      #     sudo apt-get update
      #     sudo apt-get -yq --no-install-suggests --no-install-recommends install snapcraft
      #     mkdir -p $HOME/.cache/snapcraft/download
      #     mkdir -p $HOME/.cache/snapcraft/stage-packages
      # -
      #   name: snapcraft-login
      #   if: matrix.platform == 'ubuntu-latest'
      #   run: snapcraft login --with <(echo "${{ secrets.SNAPCRAFT_LOGIN }}")
      - if: matrix.platform == 'ubuntu-latest'
        name: Run GoReleaser
        uses: goreleaser/goreleaser-action@v7
        with:
          distribution: goreleaser
          version: latest
          args: release --clean -f hack/goreleaser/linux.yml
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
      - if: matrix.platform == 'ubuntu-latest'
        name: Upload assets
        uses: actions/upload-artifact@v7
        with:
          name: ipsw_linux
          path: dist/*

      # -  # WINDOWS ################################################################
      #   if: matrix.platform == 'windows-latest'
      #   name: windows-deps
      #   run: |
      #     choco install zig
      #     dir C:\ProgramData\chocolatey\bin
      #     dir C:\ProgramData\chocolatey\lib\zig\tools
      # -
      #   if: matrix.platform == 'windows-latest'
      #   name: Run GoReleaser
      #   uses: goreleaser/goreleaser-action@v7
      #   with:
      #     distribution: goreleaser
      #     version: latest
      #     args: release --clean -f hack/goreleaser/windows.yml
      #   env:
      #     GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
      #     SCOOP_TAP_GITHUB_TOKEN: ${{ secrets.GH_SCOOP }}
      # -
      #   if: matrix.platform == 'ubuntu-latest'
      #   name: Upload assets
      #   uses: actions/upload-artifact@v7
      #   with:
      #     name: disass_linux
      #     path: dist/*
      # -
      #   if: matrix.platform == 'windows-latest'
      #   name: Upload assets
      #   uses: actions/upload-artifact@v7
      #   with:
      #     name: ipsw_windows
      #     path: dist/*

      # -  # MACOS ################################################################
      #   if: matrix.platform == 'macos-13'
      #   name: macos-deps
      #   run: |
      #     brew tap anchore/syft
      #     brew install libusb unicorn syft
      #     # arch -arch arm64 brew install libusb unicorn
      #     # arch -arch x86_64 brew install libusb unicorn
      # -
      #   if: matrix.platform == 'macos-13'
      #   name: Run GoReleaser
      #   uses: goreleaser/goreleaser-action@v7
      #   with:
      #     distribution: goreleaser
      #     version: latest
      #     args: release --clean -f hack/goreleaser/darwin.yml
      #   env:
      #     GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
      #     SCOOP_TAP_GITHUB_TOKEN: ${{ secrets.GH_SCOOP }}
      # -
      #   if: matrix.platform == 'macos-13'
      #   name: Upload assets
      #   uses: actions/upload-artifact@v7
      #   with:
      #     name: ipsw_macos
      #     path: dist/*
