From af7215241a546d540b5abd47c424a826dd0b7c33 Mon Sep 17 00:00:00 2001 From: kha7iq Date: Wed, 14 Jul 2021 15:47:33 +0800 Subject: [PATCH] feat: add auto-release for aur with sources --- .github/aur/pingme/.SRCINFO.template | 13 +++++++ .github/aur/pingme/PKGBUILD.template | 27 +++++++++++++ .github/aur/pingme/publish.sh | 58 ++++++++++++++++++++++++++++ .goreleaser.yaml | 8 +++- 4 files changed, 105 insertions(+), 1 deletion(-) create mode 100644 .github/aur/pingme/.SRCINFO.template create mode 100644 .github/aur/pingme/PKGBUILD.template create mode 100755 .github/aur/pingme/publish.sh diff --git a/.github/aur/pingme/.SRCINFO.template b/.github/aur/pingme/.SRCINFO.template new file mode 100644 index 0000000..0e46bfa --- /dev/null +++ b/.github/aur/pingme/.SRCINFO.template @@ -0,0 +1,13 @@ +pkgbase = subvars + pkgdesc = Substitute environment variables from command line for template driven configuration files + pkgver = ${PKGVER} + pkgrel = ${PKGREL} + url = https://pingme.lmno.pk + arch = i686 + arch = x86_64 + arch = aarch64 + license = MIT + makedepends = go + source = pingme-${PKGVER}.tar.gz::https://github.com/kha7iq/pingme/archive/v{PKGVER}.tar.gz + +pkgname = pingme diff --git a/.github/aur/pingme/PKGBUILD.template b/.github/aur/pingme/PKGBUILD.template new file mode 100644 index 0000000..4dc90be --- /dev/null +++ b/.github/aur/pingme/PKGBUILD.template @@ -0,0 +1,27 @@ +# Maintainer: André Kugland + +pkgname=pingme +pkgver=${PKGVER} +pkgrel=${PKGREL} +pkgdesc="Substitute environment variables from command line for template driven configuration files." +url='https://pingme.lmno.pk' +arch=("i686" "x86_64" "aarch64") +license=("MIT") +makedepends=('go>=1.16') +source=( + "${pkgname}-${pkgver}.tar.gz::https://github.com/kha7iq/pingme/archive/v${pkgver}.tar.gz" +) +sha256sums=( + ${SHA256SUM} +) + +build() { + cd "${pkgname}-${pkgver}" + export CGO_LDFLAGS="$LDFLAGS" + go build -ldflags "-linkmode=external -s -w -X main.version=${pkgver}" -o ${pkgname} . +} + +package() { + cd "${pkgname}-${pkgver}" + install -Dm755 ${pkgname} "${pkgdir}/usr/bin/${pkgname}" +} diff --git a/.github/aur/pingme/publish.sh b/.github/aur/pingme/publish.sh new file mode 100755 index 0000000..8e83207 --- /dev/null +++ b/.github/aur/pingme/publish.sh @@ -0,0 +1,58 @@ +#!/usr/bin/env bash + +set -e + +WD=$(cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd) +PKGNAME=$(basename $WD) +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=$(curl -sL https://github.com/kha7iq/subvars/archive/v$PKGVER.tar.gz | sha256sum | awk '{ print $1 }') + +envsubst '$PKGVER $PKGREL $SHA256SUM' < .SRCINFO.template > $GITDIR/.SRCINFO +envsubst '$PKGVER $PKGREL $SHA256SUM' < 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/.goreleaser.yaml b/.goreleaser.yaml index 146abf3..f83380f 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -102,8 +102,14 @@ dockers: - "--platform=linux/amd64" publishers: - - name: aur-pingme + - name: aur pingme binary env: - AUR_SSH_PRIVATE_KEY={{ .Env.AUR_SSH_PRIVATE_KEY }} cmd: | .github/aur/pingme-bin/publish.sh {{ .Version }} + + - name: aur pingme sources + env: + - AUR_SSH_PRIVATE_KEY={{ .Env.AUR_SSH_PRIVATE_KEY }} + cmd: | + .github/aur/pingme/publish.sh {{ .Version }}