Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/src/archrelease.in
blob: 818b0caa17bc8efd4c8a16591671fc4374e2459b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#!/bin/bash
#
# SPDX-License-Identifier: GPL-3.0-or-later

_DEVTOOLS_LIBRARY_DIR=${_DEVTOOLS_LIBRARY_DIR:-@pkgdatadir@}
# shellcheck source=src/lib/common.sh
source "${_DEVTOOLS_LIBRARY_DIR}"/lib/common.sh
# shellcheck source=src/lib/valid-tags.sh
source "${_DEVTOOLS_LIBRARY_DIR}"/lib/valid-tags.sh

set -e


# Deprecation warning
if [[ -z $_DEVTOOLS_COMMAND ]]; then
	warning "${0##*/} is deprecated and will be removed. Use 'pkgctl release' instead"
fi

# parse command line options
FORCE=
while getopts ':f' flag; do
	case $flag in
		f) FORCE=1 ;;
		:) die "Option requires an argument -- '%s'" "$OPTARG" ;;
		\?) die "Invalid option -- '%s'" "$OPTARG" ;;
	esac
done
shift $(( OPTIND - 1 ))

if ! (( $# )); then
	echo 'Usage: archrelease [-f] <repo>...'
	exit 1
fi

# validate repo is really repo-arch
if [[ -z $FORCE ]]; then
	for tag in "$@"; do
		if ! in_array "$tag" "${_tags[@]}"; then
			die "archrelease: Invalid tag: '%s' (use -f to force release)" "$tag"
		fi
	done
fi

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")

# 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
# matches the working directory PKGBUILD.
if git tag --verify "$gittag" &> /dev/null; then
	cwd_checksum=$(sha256sum PKGBUILD|cut -d' ' -f1)
	tag_checksum=$(git show "${gittag}:PKGBUILD" | sha256sum |cut -d' ' -f1)
	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

msg "Releasing package"
git tag --sign --message="Package release ${pkgver}" "$gittag" || abort
git push --tags --set-upstream origin main || abort