tempesta 0.0.11

The lightest and fastest CLI for managing bookmarks, written in Rust
name: Release Binaries

on:
  push:
    tags:
      - "v*.*.*"

permissions:
  contents: write  # Required to create a GitHub Release

jobs:
  build-macos:
    name: Build macOS Binaries
    runs-on: macos-latest
    strategy:
      matrix:
        target: [aarch64-apple-darwin, x86_64-apple-darwin]

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

      - name: Install Rust
        uses: dtolnay/rust-toolchain@stable

      - name: Add target
        run: rustup target add ${{ matrix.target }}

      - name: Build binary
        run: cargo build --release --target ${{ matrix.target }}

      - name: Rename and compress binary
        run: |
          mkdir -p bin
          cp target/${{ matrix.target }}/release/tempesta bin/tempesta
          tar -czvf bin/tempesta-${{ matrix.target }}.tar.gz -C bin tempesta

      - name: Upload binary as artifact
        uses: actions/upload-artifact@v4
        with:
          name: tempesta-${{ matrix.target }}
          path: bin/tempesta-${{ matrix.target }}.tar.gz

  build-linux:
    name: Build Arch Linux Package
    runs-on: ubuntu-latest
    container: archlinux:latest  # Use Arch Linux as a container environment

    steps:
      - name: Install dependencies (inside Arch container)
        run: |
          pacman -Syu --noconfirm base-devel sudo
          useradd -m aurbuilder
          echo "aurbuilder ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers.d/aurbuilder
          mkdir -p /home/aurbuilder/build
          chown -R aurbuilder /home/aurbuilder

      - name: Checkout repository
        uses: actions/checkout@v4  # Keep the repository in the default workspace

      - name: Move repository to aurbuilder's home
        run: |
          mv /__w/tempesta/tempesta /home/aurbuilder/build/tempesta
          chown -R aurbuilder /home/aurbuilder/build/tempesta

      - name: Install Rust
        run: |
          sudo -u aurbuilder bash -c "
          pacman -S --noconfirm rustup;
          rustup default stable;
          rustup target add x86_64-unknown-linux-gnu
          "

      - name: Build binary
        run: |
          sudo -u aurbuilder bash -c "
          cd /home/aurbuilder/build/tempesta;
          cargo build --release --target x86_64-unknown-linux-gnu;
          mkdir -p bin;
          cp target/x86_64-unknown-linux-gnu/release/tempesta bin/tempesta;
          chmod +x bin/tempesta
          "

      - name: Create Arch Linux Package
        run: |
          sudo -u aurbuilder bash -c "
          cd /home/aurbuilder/build/tempesta;
          mkdir -p pacman_pkg;
          cd bin;
          tar -czvf ../pacman_pkg/tempesta.tar.gz tempesta;
          cd ../pacman_pkg;

          # Create PKGBUILD
          cat <<EOF > PKGBUILD
          pkgname=tempesta
          pkgver=${{ github.ref_name }}
          pkgrel=1
          pkgdesc='A CLI application written in Rust'
          arch=('x86_64')
          url='https://github.com/x71c9/tempesta'
          license=('MIT')
          depends=('glibc')
          makedepends=('cargo')
          source=('tempesta.tar.gz')
          sha256sums=('SKIP')

          package() {
            install -Dm755 tempesta "\$pkgdir/usr/bin/tempesta"
          }
          EOF

          makepkg --printsrcinfo > .SRCINFO;
          makepkg -cf;
          mv *.pkg.tar.zst ../bin/
          "

      - name: Upload Linux Package as Artifact
        uses: actions/upload-artifact@v4
        with:
          name: tempesta-linux
          path: /home/aurbuilder/build/tempesta/bin/tempesta-*.pkg.tar.zst

  release:
    name: Create GitHub Release
    needs: [build-macos, build-linux]
    runs-on: ubuntu-latest

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

      - name: Download artifacts
        uses: actions/download-artifact@v4
        with:
          name: tempesta-aarch64-apple-darwin
          path: bin
      - name: Download artifacts
        uses: actions/download-artifact@v4
        with:
          name: tempesta-x86_64-apple-darwin
          path: bin
      - name: Download Linux artifacts
        uses: actions/download-artifact@v4
        with:
          name: tempesta-linux
          path: bin

      - name: Create GitHub Release
        uses: softprops/action-gh-release@v2
        with:
          files: bin/**
          token: ${{ secrets.GITHUB_TOKEN }}
          draft: false
          prerelease: false

      - name: Trigger Homebrew Tap Update
        run: |
          curl -X POST -H "Accept: application/vnd.github.v3+json" \
               -H "Authorization: token ${{ secrets.HOMEBREW_PAT }}" \
               https://api.github.com/repos/x71c9/homebrew-x71c9/dispatches \
               -d '{"event_type": "update-homebrew", "client_payload": {"tag": "${{ github.ref_name }}"}}'

  update-aur:
    name: Update AUR
    needs: release
    runs-on: ubuntu-latest

    steps:
      - name: Checkout AUR Repository
        run: |
          mkdir -p ~/.ssh
          echo "${{ secrets.AUR_SSH_PRIVATE_KEY }}" > ~/.ssh/id_ed25519
          chmod 600 ~/.ssh/id_ed25519
          ssh-keyscan -t ed25519 aur.archlinux.org >> ~/.ssh/known_hosts
          git clone ssh://aur@aur.archlinux.org/tempesta.git aur-tempesta
          cd aur-tempesta

      - name: Update PKGBUILD and Push to AUR
        run: |
          cd aur-tempesta
          cat <<EOF > PKGBUILD
          pkgname=tempesta
          pkgver=${{ github.ref_name }}
          pkgrel=1
          pkgdesc="A CLI application written in Rust"
          arch=('x86_64')
          url="https://github.com/x71c9/tempesta"
          license=('MIT')
          depends=('glibc')
          makedepends=('cargo')
          source=("https://github.com/x71c9/tempesta/releases/download/v${{ github.ref_name }}/tempesta-x86_64-unknown-linux-gnu.tar.gz")
          sha256sums=('SKIP')
          package() {
            install -Dm755 tempesta "\$pkgdir/usr/bin/tempesta"
          }
          EOF

          makepkg --printsrcinfo > .SRCINFO

          git add PKGBUILD .SRCINFO
          git commit -m "Update to version ${{ github.ref_name }}"
          git push origin master