|
| 1 | +#!/bin/bash |
| 2 | +# shellcheck disable=SC2024 |
| 3 | + |
| 4 | +set -euo pipefail |
| 5 | + |
| 6 | +pkgname=$INPUT_PKGNAME |
| 7 | +commit_username=$INPUT_COMMIT_USERNAME |
| 8 | +commit_email=$INPUT_COMMIT_EMAIL |
| 9 | +ssh_private_key=$INPUT_SSH_PRIVATE_KEY |
| 10 | +commit_message=$INPUT_COMMIT_MESSAGE |
| 11 | +allow_empty_commits=$INPUT_ALLOW_EMPTY_COMMITS |
| 12 | +force_push=$INPUT_FORCE_PUSH |
| 13 | +ssh_keyscan_types=$INPUT_SSH_KEYSCAN_TYPES |
| 14 | + |
| 15 | +export HOME=/home/builder |
| 16 | + |
| 17 | +echo '::group::Adding aur.archlinux.org to known hosts' |
| 18 | +ssh-keyscan -v -t "$ssh_keyscan_types" aur.archlinux.org >>~/.ssh/known_hosts |
| 19 | +echo '::endgroup::' |
| 20 | + |
| 21 | +echo '::group::Importing private key' |
| 22 | +echo "$ssh_private_key" >~/.ssh/aur |
| 23 | +chmod -vR 600 ~/.ssh/aur* |
| 24 | +ssh-keygen -vy -f ~/.ssh/aur >~/.ssh/aur.pub |
| 25 | +echo '::endgroup::' |
| 26 | + |
| 27 | +echo '::group::Checksums of SSH keys' |
| 28 | +sha512sum ~/.ssh/aur ~/.ssh/aur.pub |
| 29 | +echo '::endgroup::' |
| 30 | + |
| 31 | +echo '::group::Configuring git' |
| 32 | +git config --global user.name "$commit_username" |
| 33 | +git config --global user.email "$commit_email" |
| 34 | +echo '::endgroup::' |
| 35 | + |
| 36 | +echo '::group::Cloning AUR package into /tmp/local-repo' |
| 37 | +git clone -v "https://aur.archlinux.org/${pkgname}.git" /tmp/local-repo |
| 38 | +echo '::endgroup::' |
| 39 | + |
| 40 | +echo '::group::Generating PKGBUILD and .SRCINFO' |
| 41 | +cd /tmp/local-repo |
| 42 | + |
| 43 | +echo 'Copying PKGBUILD...' |
| 44 | +cp -v /PKGBUILD ./ |
| 45 | + |
| 46 | +echo "Updating .SRCINFO" |
| 47 | +makepkg --printsrcinfo >.SRCINFO |
| 48 | + |
| 49 | +echo '::endgroup::' |
| 50 | + |
| 51 | +echo '::group::Publishing' |
| 52 | +git remote add aur "ssh://aur@aur.archlinux.org/${pkgname}.git" |
| 53 | +git add -fv PKGBUILD .SRCINFO |
| 54 | +case "$allow_empty_commits" in |
| 55 | +true) |
| 56 | + git commit --allow-empty -m "$commit_message" |
| 57 | + ;; |
| 58 | +false) |
| 59 | + git diff-index --quiet HEAD || git commit -m "$commit_message" # use `git diff-index --quiet HEAD ||` to avoid error |
| 60 | + ;; |
| 61 | +*) |
| 62 | + echo "::error::Invalid Value: inputs.allow_empty_commits is neither 'true' nor 'false': '$allow_empty_commits'" |
| 63 | + exit 2 |
| 64 | + ;; |
| 65 | +esac |
| 66 | +case "$force_push" in |
| 67 | +true) |
| 68 | + git push -v --force aur master |
| 69 | + ;; |
| 70 | +false) |
| 71 | + git push -v aur master |
| 72 | + ;; |
| 73 | +*) |
| 74 | + echo "::error::Invalid Value: inputs.force_push is neither 'true' nor 'false': '$force_push'" |
| 75 | + exit 3 |
| 76 | + ;; |
| 77 | +esac |
| 78 | +echo '::endgroup::' |
0 commit comments