Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLevente Polyak <anthraxx@archlinux.org>2023-01-12 19:15:14 +0100
committerLevente Polyak <anthraxx@archlinux.org>2023-05-20 00:08:11 +0200
commitcddba60958d7aba15dac06acfc697b81e31581a1 (patch)
treedec9e1d920f8ab3a3b19e52fdc5c7a4458fe7258 /src
parentf1673c60adff196d9b1c7c97797c5775b3bdb56a (diff)
archrelease: add checks for valid remote and up-to-date branch ref
It's safest to probe for the validity of the remote origin and abort early otherwise. This also allows to print some hints how to create or configure new repositories at appropriate times. Additionally fetch remote changes and check the local branch contains the remote branch ref, otherwise abort and print a hint how to pull and update the branch. This should add all check needed for the average failure case that may lead to a weird state or creation of a local tag that may not be pushable. Signed-off-by: Levente Polyak <anthraxx@archlinux.org>
Diffstat (limited to 'src')
-rw-r--r--src/archrelease.in32
1 files changed, 29 insertions, 3 deletions
diff --git a/src/archrelease.in b/src/archrelease.in
index b89dad2..c3776e7 100644
--- a/src/archrelease.in
+++ b/src/archrelease.in
@@ -8,6 +8,8 @@ source "${_DEVTOOLS_LIBRARY_DIR}"/lib/common.sh
# shellcheck source=src/lib/valid-tags.sh
source "${_DEVTOOLS_LIBRARY_DIR}"/lib/valid-tags.sh
+set -e
+
# parse command line options
FORCE=
@@ -38,13 +40,36 @@ if [[ ! -f PKGBUILD ]]; then
die 'archrelease: PKGBUILD not found'
fi
+# shellcheck source=contrib/makepkg/PKGBUILD.proto
. ./PKGBUILD
pkgbase=${pkgbase:-$pkgname}
pkgver=$(get_full_version "$pkgbase")
gittag=$(get_tag_from_pkgver "$pkgver")
-if git rev-parse "$gittag" >/dev/null 2>&1; then
- die "archrelease: the tag $gittag for version $pkgver already exists in the repository!"
+# Check if releasing from a branch
+if ! branchname=$(git symbolic-ref --short HEAD); then
+ die 'not on any branch'
+fi
+if [[ "${branchname}" != main ]]; then
+ die 'must be run from the main branch'
+fi
+
+# Check if remote origin is setup properly
+if ! giturl=$(git remote get-url origin) || [[ ${giturl} != *${GIT_PACKAGING_URL_SSH}* ]]; then
+ die "remote origin is not configured, run 'pkgctl repo configure'"
+fi
+if ! git ls-remote origin >/dev/null; then
+ die "configured remote origin may not exist, run 'pkgctl repo create ${pkgbase}' to create it"
+fi
+
+msg 'Fetching remote changes'
+git fetch --prune --prune-tags origin || die 'failed to fetch remote changes'
+
+# Check if local branch is up to date and contains the latest origin commit
+if remoteref=$(git rev-parse "origin/${branchname}" 2>/dev/null); then
+ if [[ $(git branch "${branchname}" --contains "${remoteref}" --format '%(refname:short)') != "${branchname}" ]]; then
+ die "local branch is out of date, run 'git pull --rebase'"
+ fi
fi
# If the tag exists we check if it's properly signed and that it
@@ -55,10 +80,11 @@ if git tag --verify "$gittag" &> /dev/null; then
if [[ "$cwd_checksum" != "$tag_checksum" ]]; then
die "tagged PKGBUILD is not the same as the working dir PKGBUILD"
fi
+ git push --tags --set-upstream origin main || abort
exit 0
fi
stat_busy "Releasing package"
git tag --sign --message="Package release ${pkgver}" "$gittag" || abort
-git push --tags main || abort
+git push --tags --set-upstream origin main || abort
stat_done