name: Build and Deploy on Tag
on:
  push:
    tags:
      - "v*"

env:
  PACKAGE_AND_BREW: ${{ secrets.PACKAGE_AND_BREW }}
  VERSION: ${{ gitea.ref_name }}
  
jobs:
  build-arch:
    name: "🔨 Build for Arch Linux/Static Builds"
    runs-on: arch-builder
    steps:
      - uses: actions/checkout@v4
      - run: pacman --noconfirm -Sy mbedtls zip zig ninja
      - run: pacman --config /opt/cross/ppc/pacman.conf --noconfirm -Sy mbedtls
      - run: cp Packaging/Linux/PKGBUILD /home/build/PKGBUILD
      - run: cp Packaging/Linux/build-arch.sh /home/build/build-arch.sh
      - run: chmod 755 /home/build/build-arch.sh
      - run: chown build:build /home/build/PKGBUILD
      - run: chown build:build /home/build/build-arch.sh
      - run: su build -c /home/build/build-arch.sh
      - run: env -C Packaging/Tools bash build.sh
      - uses: akkuman/gitea-release-action@v1
        env:
          NODE_OPTIONS: '--experimental-fetch' # if nodejs < 18
        with:
          prerelease: true
          files: |-
            artifacts/** 
  
  update-tap-and-build-win32:
    name: "🔨 Build win32 and update the tap 🍺"
    runs-on: global-container-mingw
    steps:
      - uses: actions/checkout@v4
      - run: |
          env -C Packaging/WinToolsIntel bash build.sh

      - uses: akkuman/gitea-release-action@v1
        env:
          NODE_OPTIONS: '--experimental-fetch' # if nodejs < 18
        with:
          prerelease: true
          files: |-
            artifacts/** 

      - uses: actions/checkout@v4
        with:
          ref: "master"
          path: "tapdir"
          repository: "tesses50/tesses-tap.git"
          token: ${{ env.PACKAGE_AND_BREW }}
      - run: |
          cd tapdir
          bash ../Packaging/edit-formula.sh
          git config user.name "Tesses Gitea Bot"
          git config user.email "noreply@tesses.net"
          git add .
          git commit -m "Push tessesframework=${{ env.VERSION }}"
          git push
