name: AUR Package Update Check

on:
  schedule:
    - cron: '0 0 * * *'  # Runs at 00:00 UTC daily
  workflow_dispatch:      # Allows manual trigger

env:
  GIT_AUTHOR_NAME: ${{ secrets.GIT_AUTHOR_NAME }}
  GIT_AUTHOR_EMAIL: ${{ secrets.GIT_AUTHOR_EMAIL }}
  GIT_COMMITTER_NAME: ${{ secrets.GIT_COMMITTER_NAME }}
  GIT_COMMITTER_EMAIL: ${{ secrets.GIT_COMMITTER_EMAIL }}

jobs:
  check-updates:
    runs-on: ubuntu-latest
    container: 
      image: archlinux:base-devel
    
    steps:
      - name: Install dependencies
        run: |
          pacman -Syu --noconfirm
          pacman -S --noconfirm git openssh gnupg python python-pip

      - name: Checkout repository
        uses: actions/checkout@v4
        with:
          fetch-depth: 0

      - name: Import GPG key
        run: |
          echo "${{ secrets.GPG_PRIVATE_KEY }}" | gpg --import
          echo "trust\n5\ny\n" | gpg --command-fd 0 --edit-key ${{ secrets.GPG_KEY_ID }}

      - name: Setup Git config
        run: |
          git config --global user.name "${{ secrets.GIT_AUTHOR_NAME }}"
          git config --global user.email "${{ secrets.GIT_AUTHOR_EMAIL }}"
          git config --global commit.gpgsign true
          git config --global user.signingkey ${{ secrets.GPG_KEY_ID }}

      - name: Install Python dependencies
        run: pip install requests semver gitpython

      - name: Run update checker
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        run: python .github/scripts/update-checker.py 