diff --git a/.github/workflows/package-updates.yml b/.github/workflows/package-updates.yml index 3ff6bf4e..1ff30f0f 100644 --- a/.github/workflows/package-updates.yml +++ b/.github/workflows/package-updates.yml @@ -16,7 +16,7 @@ jobs: - name: work around permission issue run: git config --global --add safe.directory /__w/packages/packages - - name: Clone repository + - name: Checkout uses: actions/checkout@v3 with: fetch-depth: 0 @@ -43,3 +43,22 @@ jobs: GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }} GIT_COMMIT_PACKAGES: true GIT_PUSH_PACKAGES: true + + push-aur: + if: github.repository == 'built-aur/packages' + runs-on: ubuntu-latest + container: ghcr.io/built-aur/packages:latest + + steps: + - name: work around permission issue + run: git config --global --add safe.directory /__w/packages/packages + + - name: Checkout + uses: actions/checkout@v3 + + - name: Push to AUR + run: ./scripts/push-aur-entrypoint.sh + env: + SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }} + COMMIT_USER: "MedzikUserBot" + COMMIT_EMAIL: "rm99iv9s@duck.com" diff --git a/scripts/docker/Dockerfile b/scripts/docker/Dockerfile index 7b8573be..c59fb77d 100644 --- a/scripts/docker/Dockerfile +++ b/scripts/docker/Dockerfile @@ -1,5 +1,6 @@ FROM medzik/archlinux:latest +COPY ssh_config /ssh_config COPY makepkg.x86-64.conf /etc/makepkg.x86-64.conf COPY makepkg.x86-64-v3.conf /etc/makepkg.x86-64-v3.conf diff --git a/scripts/docker/ssh_config b/scripts/docker/ssh_config new file mode 100644 index 00000000..a4c0f45c --- /dev/null +++ b/scripts/docker/ssh_config @@ -0,0 +1,3 @@ +Host aur.archlinux.org + IdentityFile ~/.ssh/aur + User aur diff --git a/scripts/push-aur-entrypoint.sh b/scripts/push-aur-entrypoint.sh new file mode 100755 index 00000000..92c75098 --- /dev/null +++ b/scripts/push-aur-entrypoint.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +set -o errexit -o pipefail -o nounset + +echo '::group::Initializing SSH directory' +mkdir -pv /home/build/.ssh +touch /home/build/.ssh/known_hosts +cp -v /ssh_config /home/build/.ssh/config +chown -vR build:build /home/build +chmod -vR 600 /home/build/.ssh/* +echo '::endgroup::' + +exec su -c 'bash -c ./scripts/publish-aur.sh' build diff --git a/scripts/push-aur.sh b/scripts/push-aur.sh new file mode 100755 index 00000000..a958100e --- /dev/null +++ b/scripts/push-aur.sh @@ -0,0 +1,109 @@ +#!/bin/bash + +set -o errexit -o pipefail -o nounset + +# Commit changes to Git. +: "${GIT_COMMIT_PACKAGES:=false}" +# Push changes to remote. +: "${GIT_PUSH_PACKAGES:=false}" + +SCRIPT_DIR="$(realpath "$(dirname "$0")")" +SRC_DIR="$(realpath "$(dirname "${SCRIPT_DIR}")")" +TMP_DIR="$(mktemp -d -t medzik-aur-XXXX)" + +mkdir "${TMP_DIR}/aur" + +source "${SCRIPT_DIR}/lib/parse-conf.sh" + +echo '::group::Adding aur.archlinux.org to known hosts' +ssh-keyscan -v -t "rsa,dsa,ecdsa,ed25519" aur.archlinux.org >>~/.ssh/known_hosts +echo '::endgroup::' + +echo '::group::Importing private key' +echo "${SSH_PRIVATE_KEY}" >~/.ssh/aur +chmod -vR 600 ~/.ssh/aur* +ssh-keygen -vy -f ~/.ssh/aur >~/.ssh/aur.pub +echo '::endgroup::' + +echo '::group::Checksums of SSH keys' +sha512sum ~/.ssh/aur ~/.ssh/aur.pub +echo '::endgroup::' + +echo '::group::Configuring Git' +git config --global user.name "${COMMIT_USER}" +git config --global user.email "${COMMIT_EMAIL}" +echo '::endgroup::' + +push() { + local pkgdir="${1}" + local pkgname="$(basename ${pkgdir})" + + if [ ! -f "${pkgdir}/built.conf" ] + then + return 0 + fi + + if [ ! -f "${pkgdir}/PKGBUILD" ] + then + return 0 + fi + + if [ -f "${pkgdir}/built.conf" ] + then + eval "$(parse-conf ${pkgdir})" + + cd "${SRC_DIR}" + + if [ -n "${AUR_PUSH}" ] + then + echo '::group::Cloning AUR package into /tmp/local-repo' + git clone -v "https://aur.archlinux.org/${pkgname}.git" /tmp/local-repo + echo '::endgroup::' + + echo '::group::Copying files into /tmp/local-repo' + cp -r "${pkgdir}"/* /tmp/local-repo/ + rm -rf /tmp/local-repo//build.yml + echo '::endgroup::' + + echo '::group::Generating .SRCINFO' + cd /tmp/local-repo + makepkg --printsrcinfo >.SRCINFO + echo '::endgroup::' + + echo '::group::Committing files to the repository' + git add /tmp/local-repo + git commit -m "sync with built-aur" + echo '::endgroup::' + + echo '::group::Push package to AUR' + git push -v origin master + echo '::endgroup::' + return 0 + fi + fi +} + +if [ -n "${1}" ] +then + update-package "./packages/${1}" + update-package "./long-built/${1}" + exit 0 +fi + +for pkgdir in ./packages/* ./long-built/* +do + push "${pkgdir}" + + EXIT_CODE="${?}" + + if ! (( ${EXIT_CODE} )) + then + if [ "${GIT_PUSH_PACKAGES}" = "true" ] + then + git pull --rebase &> /dev/null + git push &> /dev/null + fi + else + echo "[!] Failed to update package '$(basename ${pkgdir})'" + fi +done