diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..9917ee9 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,13 @@ +FROM archlinux/base + +RUN pacman -Sy && \ + pacman -Sy --noconfirm --needed openssh sudo \ + git fakeroot binutils gcc awk binutils xz \ + libarchive bzip2 coreutils file findutils \ + gettext grep gzip sed ncurses util-linux + +COPY entrypoint.sh /entrypoint.sh +COPY build.sh /build.sh +COPY ssh_config /ssh_config + +ENTRYPOINT ["/entrypoint.sh"] diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 0000000..cbdf9a8 --- /dev/null +++ b/LICENSE.md @@ -0,0 +1,21 @@ +# The MIT License + +Copyright (c) 2020 Hoàng Văn Khải + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..587f655 --- /dev/null +++ b/README.md @@ -0,0 +1,63 @@ +# Publish AUR packages + +GitHub Actions to publish AUR package. + +## Inputs + +### `pkgname` + +**Required** AUR package name. + +### `pkgbuild` + +**Required** Path to PKGBUILD file. + +### `commit_username` + +**Required** The username to use when creating the new commit. + +### `commit_email` + +**Required** The email to use when creating the new commit. + +### `ssh_private_key` + +**Required** Your private key with access to AUR package. + +### `commit_message` + +**Optional** Commit message to use when creating the new commit. + +### `ssh_keyscan_types` + +**Optional** Comma-separated list of types to use when adding aur.archlinux.org to known hosts. + +## Example usage + +```yaml +name: aur-publish + +on: + push: + tags: + - '*' + +jobs: + aur-publish: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + + - name: Publish AUR package + uses: KSXGitHub/github-actions-deploy-aur@master + with: + pkgname: my-awesome-package + pkgbuild: ./PKGBUILD + commit_username: ${{ secrets.AUR_USERNAME }} + commit_email: ${{ secrets.AUR_EMAIL }} + ssh_private_key: ${{ secrets.AUR_SSH_PRIVATE_KEY }} + commit_message: Update AUR package + ssh_keyscan_types: rsa,dsa,ecdsa,ed25519 +``` + +**Tip:** To create secrets (such as `secrets.AUR_USERNAME`, `secrets.AUR_EMAIL`, and `secrets.AUR_SSH_PRIVATE_KEY` above), go to `$YOUR_GITHUB_REPO_URL/settings/secrets`. [Read this for more information](https://help.github.com/en/actions/configuring-and-managing-workflows/creating-and-storing-encrypted-secrets). diff --git a/action.yml b/action.yml new file mode 100644 index 0000000..4cf67a6 --- /dev/null +++ b/action.yml @@ -0,0 +1,34 @@ +# action.yml +name: 'Publish AUR package' +description: 'Publish an AUR package' +author: KSXGitHub +branding: + color: blue + icon: package +inputs: + pkgname: + description: 'AUR package name' + required: true + pkgbuild: + description: 'Path to PKGBUILD file' + required: true + commit_username: + description: 'The username to use when creating the new commit' + required: true + commit_email: + description: 'The email to use when creating the new commit' + required: true + ssh_private_key: + description: 'Your private key with access to AUR package.' + required: true + commit_message: + description: 'Commit message to use when creating the new commit' + required: false + default: 'Update PKGBUILD and .SRCINFO with GitHub Actions' + ssh_keyscan_types: + description: 'Comma-separated list of types to use when adding aur.archlinux.org to known hosts' + required: false + default: 'rsa,dsa,ecdsa,ed25519' +runs: + using: 'docker' + image: 'Dockerfile' diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..5197654 --- /dev/null +++ b/build.sh @@ -0,0 +1,44 @@ +#!/bin/bash +# shellcheck disable=SC2024 + +set -o errexit -o pipefail -o nounset + +pkgname=$INPUT_PKGNAME +commit_username=$INPUT_COMMIT_USERNAME +commit_email=$INPUT_COMMIT_EMAIL +ssh_private_key=$INPUT_SSH_PRIVATE_KEY +commit_message=$INPUT_COMMIT_MESSAGE +ssh_keyscan_types=$INPUT_SSH_KEYSCAN_TYPES + +export HOME=/home/builder + +echo 'Adding aur.archlinux.org to known hosts...' +ssh-keyscan -v -t "$ssh_keyscan_types" aur.archlinux.org >> ~/.ssh/known_hosts + +echo 'Importing private key...' +echo "$ssh_private_key" > ~/.ssh/aur +chmod -vR 600 ~/.ssh/aur* +ssh-keygen -vy -f ~/.ssh/aur > ~/.ssh/aur.pub + +echo 'Checksums of SSH keys...' +sha512sum ~/.ssh/aur ~/.ssh/aur.pub + +echo 'Configuring git...' +git config --global user.name "$commit_username" +git config --global user.email "$commit_email" + +echo 'Cloning AUR package into /tmp/local-repo...' +git clone -v "https://aur.archlinux.org/${pkgname}.git" /tmp/local-repo +cd /tmp/local-repo + +echo 'Copying PKGBUILD...' +cp -v /PKGBUILD ./ + +echo "Updating .SRCINFO" +makepkg --printsrcinfo > .SRCINFO + +echo "Publishing..." +git remote add aur "ssh://aur@aur.archlinux.org/${pkgname}.git" +git add -fv PKGBUILD .SRCINFO +git commit --allow-empty -m "$commit_message" +git push -fv aur master diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100755 index 0000000..1e88822 --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,22 @@ +#!/bin/bash + +set -o errexit -o pipefail -o nounset + +pkgbuild=$INPUT_PKGBUILD + +echo 'Creating builder user...' +useradd --create-home --shell /bin/bash builder +passwd --delete builder + +echo 'Initializing ssh directory...' +mkdir -pv /home/builder/.ssh +touch /home/builder/.ssh/known_hosts +cp -v /ssh_config /home/builder/.ssh/config +chown -vR builder:builder /home/builder +chmod -vR 600 /home/builder/.ssh/* + +echo 'Copying PKGBUILD...' +cp -r "$pkgbuild" /PKGBUILD + +echo 'Running build.sh...' +exec runuser builder --command 'bash -l -c /build.sh' diff --git a/renovate.json b/renovate.json new file mode 100644 index 0000000..f45d8f1 --- /dev/null +++ b/renovate.json @@ -0,0 +1,5 @@ +{ + "extends": [ + "config:base" + ] +} diff --git a/ssh_config b/ssh_config new file mode 100644 index 0000000..a4c0f45 --- /dev/null +++ b/ssh_config @@ -0,0 +1,3 @@ +Host aur.archlinux.org + IdentityFile ~/.ssh/aur + User aur