|
| 1 | +name: AUR Git Sync |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + paths: |
| 8 | + - 'packages/*/*-git/**' |
| 9 | + workflow_dispatch: |
| 10 | + |
| 11 | +jobs: |
| 12 | + sync-git-packages: |
| 13 | + runs-on: ubuntu-latest |
| 14 | + container: |
| 15 | + image: archlinux:latest |
| 16 | + steps: |
| 17 | + - name: Install Git |
| 18 | + run: pacman -Syu --noconfirm git |
| 19 | + |
| 20 | + - name: Checkout |
| 21 | + uses: actions/checkout@v6 |
| 22 | + with: |
| 23 | + fetch-depth: 0 |
| 24 | + |
| 25 | + - name: Install dependencies |
| 26 | + run: | |
| 27 | + pacman -S --noconfirm base-devel openssh sudo pacman-contrib |
| 28 | +
|
| 29 | + - name: Setup build user |
| 30 | + run: | |
| 31 | + useradd -m build |
| 32 | + echo "build ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers.d/build |
| 33 | + chown -R build:build "$GITHUB_WORKSPACE" |
| 34 | + sudo -u build bash -c "git config --global --add safe.directory $GITHUB_WORKSPACE" |
| 35 | +
|
| 36 | + - name: Setup SSH |
| 37 | + run: | |
| 38 | + mkdir -p ~/.ssh |
| 39 | + echo "${{ secrets.AUR_SSH_PRIVATE_KEY }}" > ~/.ssh/id_aur |
| 40 | + chmod 600 ~/.ssh/id_aur |
| 41 | + echo "Host aur.archlinux.org |
| 42 | + IdentityFile ~/.ssh/id_aur |
| 43 | + User aur" > ~/.ssh/config |
| 44 | + ssh-keyscan aur.archlinux.org >> ~/.ssh/known_hosts |
| 45 | +
|
| 46 | + - name: Find and Publish Modified Git Packages |
| 47 | + env: |
| 48 | + GIT_SSH_COMMAND: ssh -i ~/.ssh/id_aur -o StrictHostKeyChecking=accept-new |
| 49 | + run: | |
| 50 | + git config --global --add safe.directory "$GITHUB_WORKSPACE" |
| 51 | + |
| 52 | + # If manual trigger, find all -git directories. Otherwise, find only modified ones. |
| 53 | + if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then |
| 54 | + echo "Manual trigger: Scanning all -git packages..." |
| 55 | + changed_dirs=$(find packages -type d -name "*-git") |
| 56 | + else |
| 57 | + echo "Push trigger: Finding modified -git packages..." |
| 58 | + # Get list of files modified in the push, filter to packages/*/*-git/ |
| 59 | + changed_dirs=$(git diff-tree --no-commit-id --name-only -r HEAD | grep -E '^packages/[^/]+/[^/]+-git/' | cut -d/ -f1-3 | sort -u || true) |
| 60 | + fi |
| 61 | + |
| 62 | + if [ -z "$changed_dirs" ]; then |
| 63 | + echo "No modified git packages found." |
| 64 | + exit 0 |
| 65 | + fi |
| 66 | + |
| 67 | + for dir in $changed_dirs; do |
| 68 | + if [ -f "$dir/PKGBUILD" ]; then |
| 69 | + echo "::group::Syncing $dir" |
| 70 | + pkgname=$(grep -oP '^pkgname=\K.*' "$dir/PKGBUILD") |
| 71 | + |
| 72 | + echo "Regenerating .SRCINFO for $pkgname..." |
| 73 | + sudo -u build bash -c "cd $dir && makepkg --printsrcinfo > .SRCINFO" |
| 74 | + |
| 75 | + echo "Cloning AUR repository..." |
| 76 | + git clone aur@aur.archlinux.org:$pkgname.git aur_repo |
| 77 | + |
| 78 | + find aur_repo -maxdepth 1 -not -name ".git" -not -name "aur_repo" -exec rm -rf {} + |
| 79 | + cp $dir/PKGBUILD aur_repo/ |
| 80 | + cp $dir/.SRCINFO aur_repo/ |
| 81 | + |
| 82 | + cd aur_repo |
| 83 | + git config user.name "${{ secrets.AUR_USERNAME }}" |
| 84 | + git config user.email "${{ secrets.AUR_EMAIL }}" |
| 85 | + git add PKGBUILD .SRCINFO |
| 86 | + |
| 87 | + if git diff --staged --quiet; then |
| 88 | + echo "No changes to push for $pkgname" |
| 89 | + else |
| 90 | + pkgver=$(grep -oP '^pkgver=\K.*' PKGBUILD) |
| 91 | + pkgrel=$(grep -oP '^pkgrel=\K.*' PKGBUILD) |
| 92 | + git commit -m "Update to $pkgver-$pkgrel" |
| 93 | + git push origin master |
| 94 | + echo "Successfully synced $pkgname to AUR!" |
| 95 | + fi |
| 96 | + |
| 97 | + cd .. |
| 98 | + rm -rf aur_repo |
| 99 | + echo "::endgroup::" |
| 100 | + fi |
| 101 | + done |
0 commit comments