From 171c48e7fa74a8cbde1b7c75f89a4d04a8f1a6e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20W=C3=B3jcik?= Date: Sat, 22 May 2021 00:14:56 +0200 Subject: [PATCH 1/3] workflows: fetch xbps for lint step --- .github/workflows/build.yaml | 1 + common/travis/fetch-xbps.sh | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+) create mode 100755 common/travis/fetch-xbps.sh diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index eb96a151c599..5ca5de2244d4 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -19,6 +19,7 @@ jobs: fetch-depth: 200 - run: common/travis/fetch_upstream.sh - run: common/travis/changed_templates.sh + - run: common/travis/fetch-xbps.sh - run: common/travis/fetch-xtools.sh - run: common/travis/xlint.sh # GitHub Action create a merge commit, ignore it diff --git a/common/travis/fetch-xbps.sh b/common/travis/fetch-xbps.sh new file mode 100755 index 000000000000..5a4e458cf565 --- /dev/null +++ b/common/travis/fetch-xbps.sh @@ -0,0 +1,22 @@ +#!/bin/sh +# +# fetch-xbps.sh + +command -v xbps-uhelper >/dev/null && exit +TAR=tar +command -v bsdtar >/dev/null && TAR=bsdtar +ARCH=$(uname -m)-musl +VERSION=0.59_5 +URL="https://alpha.de.repo.voidlinux.org/static/xbps-static-static-${VERSION}.${ARCH}.tar.xz" +FILE=${URL##*/} + +mkdir -p /tmp/bin + +/bin/echo -e '\x1b[32mInstalling xbps...\x1b[0m' +if command -v wget >/dev/null; then + wget -q -O "$FILE" "$URL" || exit 1 +else + curl -s -o "$FILE" "$URL" || exit 1 +fi + +$TAR xf "$FILE" -C /tmp/bin --strip-components=3 ./usr/bin || exit 1 From 5979b462c414c6b9ec7a9d5f4df7c5b6cd8f48f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20W=C3=B3jcik?= Date: Mon, 24 May 2021 22:13:35 +0200 Subject: [PATCH 2/3] common/changed_templates.sh: store merge-base in file --- common/travis/changed_templates.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/common/travis/changed_templates.sh b/common/travis/changed_templates.sh index 6b27ad8227fe..d36ac8c52a99 100755 --- a/common/travis/changed_templates.sh +++ b/common/travis/changed_templates.sh @@ -8,9 +8,11 @@ elif command -v git >/dev/null 2>&1; then GIT_CMD=$(command -v git) fi +printf '%s ' "$(git merge-base FETCH_HEAD HEAD)" HEAD > /tmp/revisions + /bin/echo -e '\x1b[32mChanged packages:\x1b[0m' $GIT_CMD diff-tree -r --no-renames --name-only --diff-filter=AM \ - "$(git merge-base FETCH_HEAD HEAD)" HEAD \ + $(cat /tmp/revisions) \ -- 'srcpkgs/*/template' | cut -d/ -f 2 | tee /tmp/templates | From 508921bf8cd4bb217de0f2e8fa2c447a3474bb03 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20W=C3=B3jcik?= Date: Mon, 24 May 2021 22:18:54 +0200 Subject: [PATCH 3/3] common: add lint-version-change --- common/scripts/lint-version-change | 90 ++++++++++++++++++++++++++++++ common/travis/xlint.sh | 2 + 2 files changed, 92 insertions(+) create mode 100755 common/scripts/lint-version-change diff --git a/common/scripts/lint-version-change b/common/scripts/lint-version-change new file mode 100755 index 000000000000..5e9687799384 --- /dev/null +++ b/common/scripts/lint-version-change @@ -0,0 +1,90 @@ +#!/bin/sh + +# when $3 is empty, template is read from working directory +template="$1" base_rev="$2" tip_rev="$3" +status=0 + +die() { + printf '%s\n' "$*" >&2 + exit 1 +} + +if ! [ "$base_rev" ]; then + die "usage: $0 TEMPLATE BASE-REVISION [TIP-REVISION]" +fi + +if command -v chroot-git >/dev/null 2>&1; then + GIT_CMD=$(command -v chroot-git) +elif command -v git >/dev/null 2>&1; then + GIT_CMD=$(command -v git) +else + die "neither chroot-git nor git could be found" +fi + +scan() { + rx="$1" msg="$2" + template_path=$template + if [ "$tip_rev" ]; then + template_path="${tip_rev}:${template}" + maybe_git="$GIT_CMD" + revspec="[^:]*:" + fi + $maybe_git grep -P -Hn -e "$rx" "$template_path" | + grep -v -P -e "[^:]*:[^:]*:\s*#" | + sed "s/^${revspec}\([^:]*:[^:]*:\)\(.*\)/\1 $msg/" +} + +show_template() { + rev="$1" + if [ "$rev" ]; then + $GIT_CMD cat-file blob "${rev}:${template}" 2>/dev/null + else + cat "${template}" 2>/dev/null + fi +} + +show_template_var() { + rev="$1" var="$2" + show_template "$rev" | grep -Po '^'${var}'=\K.*' +} + +revision_reset() { + [ "${revision}" = 1 ] && return + if [ "$prev_version" ]; then + case "$prev_reverts" in + *"$version"_*) return + esac + action=update + else + action=creation + fi + scan "^revision=" "revision should be set to 1 on ${action}" + status=1 +} + +reverts_on_downgrade() { + [ "$version" ] || return + case "$reverts" in + *"$prev_version"_*) ;; + *) + scan "^version=" "missing reverts= for downgrade $prev_version to $version" + status=1 + esac +} + +version_change() { + version="$(show_template_var "$tip_rev" version)" + revision="$(show_template_var "$tip_rev" revision)" + reverts="$(show_template_var "$tip_rev" reverts)" + prev_version="$(show_template_var "$base_rev" version)" + prev_reverts="$(show_template_var "$base_rev" reverts)" + xbps-uhelper cmpver "$version" "$prev_version" + case "$?" in + 1) revision_reset;; + -1|255) reverts_on_downgrade;; + esac +} + +version_change + +exit $status diff --git a/common/travis/xlint.sh b/common/travis/xlint.sh index 753d4a1fa51f..fc15d20a3fcf 100755 --- a/common/travis/xlint.sh +++ b/common/travis/xlint.sh @@ -5,8 +5,10 @@ [ "$XLINT" ] || exit 0 EXITCODE=0 +read base tip < /tmp/revisions for t in $(awk '{ print "srcpkgs/" $0 "/template" }' /tmp/templates); do /bin/echo -e "\x1b[32mLinting $t...\x1b[0m" xlint "$t" || EXITCODE=$? + common/scripts/lint-version-change "$t" $base $tip || EXITCODE=$? done exit $EXITCODE