name: Test PKGBUILD-git

on:
  push:
    branches: master
  pull_request:
    branches: master

jobs:
  build:
    runs-on: ubuntu-latest
    container: archlinux:latest
    
    steps:
    - name: Setup Arch
      run: |
        pacman -Sy --noconfirm --needed base-devel git sudo
        useradd -m builder
        echo "builder ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers
    
    - name: Checkout
      uses: actions/checkout@v4
      with:
        fetch-depth: 0
    
    - name: Set permissions
      run: chown -R builder:builder .
    
    - name: Build
      run: |
        sudo -u builder bash -c '
          cd AUR
          makepkg -p PKGBUILD-git -si --noconfirm
        '
    
    - name: Test
      run: |
        clrsync_cli --help
        pacman -Ql clrsync-git
    
    - name: Upload artifact
      uses: actions/upload-artifact@v4
      with:
        name: clrsync-git
        path: AUR/*.pkg.tar.zst
