From 551ee5fff14f05a98516dbf39fcbd61f6ecbe4ca Mon Sep 17 00:00:00 2001 From: kha7iq Date: Mon, 12 Jul 2021 03:49:21 +0800 Subject: [PATCH] chore: add support for publishing to aur --- .github/aur/pingme-bin/.SRCINFO.template | 23 +++++++++ .github/aur/pingme-bin/PKGBUILD.template | 34 +++++++++++++ .github/aur/pingme-bin/publish.sh | 65 ++++++++++++++++++++++++ .github/workflows/build.yml | 1 + .goreleaser.yaml | 7 +++ 5 files changed, 130 insertions(+) create mode 100644 .github/aur/pingme-bin/.SRCINFO.template create mode 100644 .github/aur/pingme-bin/PKGBUILD.template create mode 100755 .github/aur/pingme-bin/publish.sh diff --git a/.github/aur/pingme-bin/.SRCINFO.template b/.github/aur/pingme-bin/.SRCINFO.template new file mode 100644 index 0000000..d6d5116 --- /dev/null +++ b/.github/aur/pingme-bin/.SRCINFO.template @@ -0,0 +1,23 @@ +pkgbase = pingme-bin + pkgdesc = PingMe is a CLI tool which provides the ability to send messages or alerts to multiple messaging platforms & email (official binary) + pkgver = ${PKGVER} + pkgrel = ${PKGREL} + url = https://pingme.lmno.pk + arch = i686 + arch = x86_64 + arch = aarch64 + license = MIT + optdepends = nfpm: deb and rpm packager + provides = ${_PKGNAME} + conflicts = ${_PKGNAME} + + source_x86_64 = ${_PKGNAME}_${PKGVER}_linux_x86_64.tar.gz::https://github.com/kha7iq/${_PKGNAME}/releases/download/v${PKGVER}/${_PKGNAME}_linux_x86_64.tar.gz") + sha256sums_x86_64 = (${SHA256SUM_X86}) + + source_i686 = ${_PKGNAME}_${PKGVER}_linux_i386.tar.gz::https://github.com/kha7iq/${_PKGNAME}/releases/download/v${PKGVER}/${_PKGNAME}_linux_i386.tar.gz") + sha256sums_i686 = (${SHA256SUM_i686}) + + source_aarch64 = ${_PKGNAME}_${PKGVER}_linux_arm64.tar.gz::https://github.com/kha7iq/${_PKGNAME}/releases/download/v${PKGVER}/${_PKGNAME}_linux_arm64.tar.gz") + sha256sums_aarch64 = (${SHA256SUM_AARCH64}) + +pkgname = pingme-bin diff --git a/.github/aur/pingme-bin/PKGBUILD.template b/.github/aur/pingme-bin/PKGBUILD.template new file mode 100644 index 0000000..ea9ba52 --- /dev/null +++ b/.github/aur/pingme-bin/PKGBUILD.template @@ -0,0 +1,34 @@ +# Maintainer: Abdul Khaliq + +pkgname='pingme-bin' +_pkgname="${pkgname%-bin}" +pkgver=${PKGVER} +pkgrel=${PKGREL} +pkgdesc="PingMe is a CLI tool which provides the ability to send messages or alerts to multiple messaging platforms & email. (official binary)" +url='https://pingme.lmno.pk' +arch=("i686" "x86_64" "aarch64") +license=("MIT") +provides=("${_pkgname}") +conflicts=("${_pkgname}") + +depends=() +makedepends=() +optdepends=('nfpm: deb and rpm packager') + +_basedownloadurl="https://github.com/kha7iq/${_pkgname}/releases/download/v${pkgver}" + +source_x86_64=("${_pkgname}_${pkgver}_linux_x86_64.tar.gz::${_basedownloadurl}/${_pkgname}_linux_x86_64.tar.gz") +sha256sums_x86_64=(${SHA256SUM_X86}) + +source_i686=("${_pkgname}_${pkgver}_linux_i386.tar.gz::${_basedownloadurl}/${_pkgname}_linux_i386.tar.gz") +sha256sums_i686=(${SHA256SUM_i686}) + +source_aarch64=("${_pkgname}_${pkgver}_linux_arm64.tar.gz::${_basedownloadurl}/${_pkgname}_linux_arm64.tar.gz") +sha256sums_aarch64=(${SHA256SUM_AARCH64}) + +package() { + # Bin + rm -f "${pkgdir}/usr/bin/${_pkgname}" + install -Dm755 "${srcdir}/${_pkgname}" "${pkgdir}/usr/bin/${_pkgname}" + +} diff --git a/.github/aur/pingme-bin/publish.sh b/.github/aur/pingme-bin/publish.sh new file mode 100755 index 0000000..58e0dc3 --- /dev/null +++ b/.github/aur/pingme-bin/publish.sh @@ -0,0 +1,65 @@ +#!/usr/bin/env bash + + +set -e + +WD=$(cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd) +PKGNAME=$(basename $WD) + +export _PKGNAME="${PKGNAME%-bin}" +ROOT=${WD%/.github/aur/$PKGNAME} + +LOCKFILE=/tmp/aur-$PKGNAME.lock +exec 100>$LOCKFILE || exit 0 +flock -n 100 || exit 0 +trap "rm -f $LOCKFILE" EXIT + +export VERSION=$1 +echo "Publishing to AUR as version ${VERSION}" + +cd $WD + +export GIT_SSH_COMMAND="ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no" + +if [ -z "$AUR_SSH_PRIVATE_KEY" ] +then + echo "\$AUR_SSH_PRIVATE_KEY is not set" +else + eval $(ssh-agent -s) + ssh-add <(echo "$AUR_SSH_PRIVATE_KEY") +fi + +GITDIR=$(mktemp -d /tmp/aur-$PKGNAME-XXX) +trap "rm -rf $GITDIR" EXIT +git clone aur@aur.archlinux.org:$PKGNAME $GITDIR 2>&1 + +CURRENT_PKGVER=$(cat $GITDIR/.SRCINFO | grep pkgver | awk '{ print $3 }') +CURRENT_PKGREL=$(cat $GITDIR/.SRCINFO | grep pkgrel | awk '{ print $3 }') + +export PKGVER=${VERSION/-/} + +if [[ "${CURRENT_PKGVER}" == "${PKGVER}" ]]; then + export PKGREL=$((CURRENT_PKGREL+1)) +else + export PKGREL=1 +fi + +export SHA256SUM_X86=$(curl -sL https://github.com/kha7iq/${_PKGNAME}/releases/download/v${PKGVER}/${_PKGNAME}_linux_x86_64.tar.gz | sha256sum | awk '{ print $1 }') + +export SHA256SUM_i686=$(curl -sL https://github.com/kha7iq/${_PKGNAME}/releases/download/v${PKGVER}/${_PKGNAME}_linux_i386.tar.gz | sha256sum | awk '{ print $1 }') + +export SHA256SUM_AARCH64=$(curl -sL https://github.com/kha7iq/$_PKGNAME/releases/download/v${PKGVER}/${_PKGNAME}_linux_arm64.tar.gz | sha256sum | awk '{ print $1 }') + +envsubst '$PKGVER $PKGREL $_PKGNAME $SHA256SUM_X86 $SHA256SUM_i686 $SHA256SUM_AARCH64' < .SRCINFO.template > $GITDIR/.SRCINFO +envsubst '$PKGVER $PKGREL $SHA256SUM_X86 $SHA256SUM_i686 $SHA256SUM_AARCH64' < PKGBUILD.template > $GITDIR/PKGBUILD + +cd $GITDIR +git config user.name "GoReleaser" +git config user.email "a.khaliq@outlook.my" +git add -A +if [ -z "$(git status --porcelain)" ]; then + echo "No changes." +else + git commit -m "Updated to version v${PKGVER} release ${PKGREL}" + git push origin master +fi diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 41060a1..467af60 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -60,6 +60,7 @@ jobs: args: release --rm-dist env: GITHUB_TOKEN: ${{ secrets.RELEASE_TOKEN }} + AUR_SSH_PRIVATE_KEY: ${{ secrets.AUR_SSH_PRIVATE_KEY }} - name: Notify on failure diff --git a/.goreleaser.yaml b/.goreleaser.yaml index d9e6e32..146abf3 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -100,3 +100,10 @@ dockers: - "--label=org.opencontainers.image.version={{.Version}}" - "--label=org.opencontainers.image.source={{.GitURL}}" - "--platform=linux/amd64" + +publishers: + - name: aur-pingme + env: + - AUR_SSH_PRIVATE_KEY={{ .Env.AUR_SSH_PRIVATE_KEY }} + cmd: | + .github/aur/pingme-bin/publish.sh {{ .Version }}