Check packages upstream, test hampackcheck and the conf files, add CI
`hampackcheck packages` (and `make check-packages`) checks that every package in packages.conf is in the repos or on the AUR and every Flatpak is on Flathub, and fails if any is missing or couldn't be checked. Names only provided by another package pass with a note. New tests cover hampackcheck's version comparisons and package check, and check compile.conf, binaries.conf, packages.conf and the desktop files for missing or misspelt fields and paths that don't exist. A Gitea workflow runs lint and tests on every push and pull request, and the package check on those and weekly. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
bb5c7900d5
commit
8023b04024
@@ -0,0 +1,38 @@
|
|||||||
|
# Lint and test every push and pull request, and check that every package in
|
||||||
|
# packages.conf can still be installed. Packages can be renamed or dropped
|
||||||
|
# upstream without any change here, so that check also runs once a week.
|
||||||
|
name: check
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
pull_request:
|
||||||
|
schedule:
|
||||||
|
- cron: "17 6 * * 1"
|
||||||
|
workflow_dispatch:
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
lint-and-test:
|
||||||
|
if: github.event_name != 'schedule'
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
container: archlinux:latest
|
||||||
|
steps:
|
||||||
|
# nodejs is for actions/checkout itself
|
||||||
|
- name: Install tools
|
||||||
|
run: pacman -Syu --noconfirm --needed bats shellcheck make git jq zip unzip curl which diffutils file nodejs
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
# As an ordinary user, as a developer runs them: root ignores file permissions
|
||||||
|
- name: make lint test
|
||||||
|
run: |
|
||||||
|
useradd -m tester
|
||||||
|
chown -R tester "$GITHUB_WORKSPACE"
|
||||||
|
su tester -c "cd '$GITHUB_WORKSPACE' && make check"
|
||||||
|
|
||||||
|
packages:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
container: archlinux:latest
|
||||||
|
steps:
|
||||||
|
- name: Install tools
|
||||||
|
run: pacman -Syu --noconfirm --needed make git jq curl nodejs
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
- name: make check-packages
|
||||||
|
run: make check-packages
|
||||||
@@ -1,12 +1,14 @@
|
|||||||
# HamPack development tasks
|
# HamPack development tasks
|
||||||
# make lint - shellcheck every script
|
# make lint - shellcheck every script
|
||||||
# make test - run the bats tests in tests/
|
# make test - run the bats tests in tests/
|
||||||
|
# make check-packages - check every package and Flatpak in packages.conf can
|
||||||
|
# still be installed (needs the network; run `pacman -Sy` first)
|
||||||
# make hooks - run `make lint test` before each commit
|
# make hooks - run `make lint test` before each commit
|
||||||
|
|
||||||
SCRIPTS := install.sh update.sh lib.sh install-binaries.sh install-compiled.sh \
|
SCRIPTS := install.sh update.sh lib.sh install-binaries.sh install-compiled.sh \
|
||||||
install-flatpaks.sh install-windows-apps.sh patch-potacat.sh hampackcheck hampackremove
|
install-flatpaks.sh install-windows-apps.sh patch-potacat.sh hampackcheck hampackremove
|
||||||
|
|
||||||
.PHONY: check lint test hooks
|
.PHONY: check lint test check-packages hooks
|
||||||
|
|
||||||
check: lint test
|
check: lint test
|
||||||
|
|
||||||
@@ -16,5 +18,8 @@ lint:
|
|||||||
test:
|
test:
|
||||||
bats tests/
|
bats tests/
|
||||||
|
|
||||||
|
check-packages:
|
||||||
|
./hampackcheck packages
|
||||||
|
|
||||||
hooks:
|
hooks:
|
||||||
git config core.hooksPath .githooks
|
git config core.hooksPath .githooks
|
||||||
|
|||||||
@@ -76,8 +76,11 @@ There's no reason why someone couldn't collaborate on HamPack and "port" it to o
|
|||||||
HamPack is a set of Bash scripts. `install.sh` runs once, from `sibling add`; `update.sh` runs on every `update` and does the actual installing, so every step must work both on a fresh machine and on one that already has everything. Shared functions are in `lib.sh`.
|
HamPack is a set of Bash scripts. `install.sh` runs once, from `sibling add`; `update.sh` runs on every `update` and does the actual installing, so every step must work both on a fresh machine and on one that already has everything. Shared functions are in `lib.sh`.
|
||||||
|
|
||||||
- `make lint` runs shellcheck on every script
|
- `make lint` runs shellcheck on every script
|
||||||
- `make test` runs the bats tests in `tests/`, which stub out sudo, pacman, Flatpak and systemd, so they're safe to run
|
- `make test` runs the bats tests in `tests/`, which stub out sudo, pacman, Flatpak and systemd, so they're safe to run. They also check the conf files for missing or misspelt fields
|
||||||
- `make hooks` runs both before each commit
|
- `make check-packages` checks that every package in `packages.conf` is in the Arch repos or the AUR, and every Flatpak is on Flathub (run `sudo pacman -Sy` first). It catches packages that were renamed or dropped upstream, but not a typo that happens to be another package's name
|
||||||
|
- `make hooks` runs `make lint test` before each commit
|
||||||
|
|
||||||
|
Gitea runs `make lint test` on every push and pull request, and `make check-packages` on those and once a week, since packages can disappear upstream without any change here (`.gitea/workflows/check.yml`).
|
||||||
|
|
||||||
To add an application, add a section to `binaries.conf` or `compile.conf`; the comments at the top of each describe the fields.
|
To add an application, add a section to `binaries.conf` or `compile.conf`; the comments at the top of each describe the fields.
|
||||||
|
|
||||||
|
|||||||
+86
-9
@@ -1,12 +1,19 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
#
|
#
|
||||||
# Purpose: Check for available version updates in binaries.conf and compile.conf
|
# Purpose: Check for available version updates in binaries.conf and compile.conf,
|
||||||
|
# and that everything in packages.conf can still be installed
|
||||||
# (a tool for HamPack maintainers; it changes nothing)
|
# (a tool for HamPack maintainers; it changes nothing)
|
||||||
|
#
|
||||||
|
# Usage: hampackcheck [versions|packages] (both, if neither is given)
|
||||||
|
# Exits 1 if a package or Flatpak can't be found, or couldn't be checked.
|
||||||
|
|
||||||
source "$(dirname "$(realpath "$0")")/lib.sh"
|
source "$(dirname "$(realpath "$0")")/lib.sh"
|
||||||
|
|
||||||
BINARIES_CONF="${HAMPACK_BINARIES_CONF:-$HAMPACK_DIR/binaries.conf}"
|
BINARIES_CONF="${HAMPACK_BINARIES_CONF:-$HAMPACK_DIR/binaries.conf}"
|
||||||
COMPILE_CONF="${HAMPACK_COMPILE_CONF:-$HAMPACK_DIR/compile.conf}"
|
COMPILE_CONF="${HAMPACK_COMPILE_CONF:-$HAMPACK_DIR/compile.conf}"
|
||||||
|
PACKAGES_CONF="${HAMPACK_PACKAGES_CONF:-$HAMPACK_DIR/packages.conf}"
|
||||||
|
AUR_RPC="https://aur.archlinux.org/rpc/v5/info"
|
||||||
|
FLATHUB_API="https://flathub.org/api/v2/appstream"
|
||||||
|
|
||||||
# Fetch latest release tag via GitHub API, stripping leading "v"
|
# Fetch latest release tag via GitHub API, stripping leading "v"
|
||||||
github_latest() {
|
github_latest() {
|
||||||
@@ -96,18 +103,88 @@ check_compiled() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Check that each package in packages.conf is in pacman's sync databases (as
|
||||||
|
# a package or a group) or on the AUR, and each Flatpak is on Flathub. Repo
|
||||||
|
# packages are looked up locally, so run `pacman -Sy` first for fresh results.
|
||||||
|
# A name that's only provided by another package still installs, but is
|
||||||
|
# reported so packages.conf can use the real name.
|
||||||
|
# Returns 1 if anything is missing or couldn't be checked.
|
||||||
|
check_packages() {
|
||||||
|
local packages flatpak_ids p provider not_in_repos=() aur_names code status=0
|
||||||
|
# grep drops the blank line printf makes of an empty list
|
||||||
|
mapfile -t packages < <(source "$PACKAGES_CONF"; printf '%s\n' "${UTILITIES[@]}" "${APPLICATIONS[@]}" | grep .)
|
||||||
|
mapfile -t flatpak_ids < <(source "$PACKAGES_CONF"; printf '%s\n' "${FLATPAKS[@]}" | grep .)
|
||||||
|
|
||||||
|
for p in "${packages[@]}"; do
|
||||||
|
if pacman -Si "$p" > /dev/null 2>&1 || pacman -Sg "$p" > /dev/null 2>&1; then
|
||||||
|
continue
|
||||||
|
elif provider="$(pacman -Sddp --print-format %n "$p" 2> /dev/null)" && [ -n "$provider" ]; then
|
||||||
|
echo " $p is provided by $provider; packages.conf could name that instead"
|
||||||
|
else
|
||||||
|
not_in_repos+=("$p")
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
echo " ${#packages[@]} packages, $(( ${#packages[@]} - ${#not_in_repos[@]} )) in the repos"
|
||||||
|
|
||||||
|
if (( ${#not_in_repos[@]} > 0 )); then
|
||||||
|
local args=()
|
||||||
|
for p in "${not_in_repos[@]}"; do args+=(--data-urlencode "arg[]=$p"); done
|
||||||
|
if ! aur_names="$(set -o pipefail; curl -sfG "$AUR_RPC" "${args[@]}" | jq -r '.results[].Name')"; then
|
||||||
|
echo " The AUR couldn't be reached, so these weren't checked: ${not_in_repos[*]}"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
for p in "${not_in_repos[@]}"; do
|
||||||
|
if grep -qxF "$p" <<< "$aur_names"; then
|
||||||
|
echo " $p is on the AUR"
|
||||||
|
else
|
||||||
|
echo " $p is in neither the repos nor the AUR ** MISSING **"
|
||||||
|
status=1
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
|
||||||
|
for p in "${flatpak_ids[@]}"; do
|
||||||
|
code="$(curl -s -o /dev/null -w '%{http_code}' "$FLATHUB_API/$p")"
|
||||||
|
case "$code" in
|
||||||
|
200) echo " $p is on Flathub" ;;
|
||||||
|
404) echo " $p is not on Flathub ** MISSING **"; status=1 ;;
|
||||||
|
*) echo " $p couldn't be checked: Flathub answered ${code:-nothing}"; status=1 ;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
return $status
|
||||||
|
}
|
||||||
|
|
||||||
# --- Main ---
|
# --- Main ---
|
||||||
|
|
||||||
for conf in "$BINARIES_CONF" "$COMPILE_CONF"; do
|
what="${1:-all}"
|
||||||
|
case "$what" in
|
||||||
|
all|versions|packages) ;;
|
||||||
|
*) echo "Usage: $(basename "$0") [versions|packages]"; exit 2 ;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
if [ "$what" != packages ]; then
|
||||||
|
for conf in "$BINARIES_CONF" "$COMPILE_CONF"; do
|
||||||
if [ ! -f "$conf" ]; then
|
if [ ! -f "$conf" ]; then
|
||||||
echo "Error: $conf not found."
|
echo "Error: $conf not found."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
echo "Checking HamPack application versions..."
|
echo "Checking HamPack application versions..."
|
||||||
echo "=== binaries.conf ==="
|
echo "=== binaries.conf ==="
|
||||||
parse_conf "$BINARIES_CONF" check_binary
|
parse_conf "$BINARIES_CONF" check_binary
|
||||||
echo ""
|
echo ""
|
||||||
echo "=== compile.conf ==="
|
echo "=== compile.conf ==="
|
||||||
parse_conf "$COMPILE_CONF" check_compiled
|
parse_conf "$COMPILE_CONF" check_compiled
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "$what" != versions ]; then
|
||||||
|
if [ ! -f "$PACKAGES_CONF" ]; then
|
||||||
|
echo "Error: $PACKAGES_CONF not found."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
[ "$what" = packages ] || echo ""
|
||||||
|
echo "=== packages.conf ==="
|
||||||
|
check_packages || exit 1
|
||||||
|
fi
|
||||||
|
|||||||
+143
@@ -0,0 +1,143 @@
|
|||||||
|
#!/usr/bin/env bats
|
||||||
|
|
||||||
|
# Checks of HamPack's own config files, so a typo in one fails here rather than
|
||||||
|
# halfway through someone's update. Whether the packages in packages.conf
|
||||||
|
# exist upstream needs the network: `./hampackcheck packages` checks that.
|
||||||
|
|
||||||
|
load helpers
|
||||||
|
|
||||||
|
setup() {
|
||||||
|
setup_fake_home
|
||||||
|
source "$REPO/lib.sh"
|
||||||
|
PROBLEMS=()
|
||||||
|
}
|
||||||
|
|
||||||
|
# Report each problem; fail if there are any
|
||||||
|
no_problems() {
|
||||||
|
printf '%s\n' "${PROBLEMS[@]}"
|
||||||
|
[ ${#PROBLEMS[@]} -eq 0 ]
|
||||||
|
}
|
||||||
|
|
||||||
|
problem() { PROBLEMS+=("[${CONF[_name]}] $*"); }
|
||||||
|
|
||||||
|
# Fields with names not in the list given
|
||||||
|
check_keys() {
|
||||||
|
local key
|
||||||
|
for key in "${!CONF[@]}"; do
|
||||||
|
[ "$key" = _name ] || [[ " $* " == *" $key "* ]] || problem "unknown field $key="
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
check_required() {
|
||||||
|
local key
|
||||||
|
for key; do
|
||||||
|
[ -n "${CONF[$key]}" ] || problem "needs $key="
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
# A path under $HAMPACK_DIR must exist in the repo
|
||||||
|
check_repo_path() {
|
||||||
|
local value="${CONF[$1]}"
|
||||||
|
if [[ "$value" == '$HAMPACK_DIR/'* ]] && [ ! -e "$(expand_vars "$value")" ]; then
|
||||||
|
problem "$1=$value doesn't exist"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
check_compiled() {
|
||||||
|
check_keys name version git ref wget install steps gui desktop
|
||||||
|
check_required version install steps
|
||||||
|
if { [ -n "${CONF[git]}" ] && [ -n "${CONF[wget]}" ]; } || { [ -z "${CONF[git]}" ] && [ -z "${CONF[wget]}" ]; }; then
|
||||||
|
problem "needs exactly one of git= and wget="
|
||||||
|
fi
|
||||||
|
if [ -n "${CONF[ref]}" ]; then
|
||||||
|
[ -n "${CONF[git]}" ] || problem "ref= needs git="
|
||||||
|
[[ "${CONF[ref]}" =~ ^[0-9a-f]{40}$ ]] || problem "ref= should be a full commit hash"
|
||||||
|
fi
|
||||||
|
[ -z "${CONF[gui]}" ] || [ "${CONF[gui]}" = true ] || problem "gui= should be true or left out"
|
||||||
|
check_repo_path desktop
|
||||||
|
[[ "${CONF[install]}" == '$HOME/'* ]] || problem "install= should be under \$HOME"
|
||||||
|
}
|
||||||
|
|
||||||
|
check_binary() {
|
||||||
|
check_keys version url sha256 install exec gui comment icon categories
|
||||||
|
check_required version url sha256 install
|
||||||
|
[ -z "${CONF[sha256]}" ] || [[ "${CONF[sha256]}" =~ ^[0-9a-f]{64}$ ]] || problem "sha256= isn't a SHA-256"
|
||||||
|
[[ "${CONF[url]}" == https://* ]] || problem "url= should be https://"
|
||||||
|
[ -z "${CONF[gui]}" ] || [ "${CONF[gui]}" = true ] || [ "${CONF[gui]}" = false ] || problem "gui= should be true or false"
|
||||||
|
check_repo_path icon
|
||||||
|
[[ "${CONF[install]}" == '$HOME/'* ]] || problem "install= should be under \$HOME"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Section names must be unique: the version record is keyed by them
|
||||||
|
check_unique_sections() {
|
||||||
|
local dup
|
||||||
|
dup="$(sed -n 's/^\[\(.*\)\]$/\1/p' "$1" | sort | uniq -d)"
|
||||||
|
[ -z "$dup" ] || PROBLEMS+=("$(basename "$1") lists $dup more than once")
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "compile.conf: every app has the fields it needs and no unknown ones" {
|
||||||
|
parse_conf "$REPO/compile.conf" check_compiled
|
||||||
|
check_unique_sections "$REPO/compile.conf"
|
||||||
|
no_problems
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "binaries.conf: every binary has a url, a SHA-256 and the fields it needs" {
|
||||||
|
parse_conf "$REPO/binaries.conf" check_binary
|
||||||
|
check_unique_sections "$REPO/binaries.conf"
|
||||||
|
no_problems
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "the conf checks catch typos and missing fields" {
|
||||||
|
local conf="$BATS_TEST_TMPDIR/compile.conf"
|
||||||
|
cat > "$conf" << 'EOF'
|
||||||
|
[ok]
|
||||||
|
version=1
|
||||||
|
git=https://example.com/ok
|
||||||
|
install=$HOME/.local/bin/ok
|
||||||
|
steps=make
|
||||||
|
[broken]
|
||||||
|
verison=1
|
||||||
|
git=https://example.com/a
|
||||||
|
wget=https://example.com/a.zip
|
||||||
|
ref=main
|
||||||
|
install=/usr/bin/broken
|
||||||
|
desktop=$HAMPACK_DIR/desktop/nope.desktop
|
||||||
|
steps=make
|
||||||
|
EOF
|
||||||
|
parse_conf "$conf" check_compiled
|
||||||
|
run no_problems
|
||||||
|
[ "$status" -eq 1 ]
|
||||||
|
[[ "$output" != *"[ok]"* ]]
|
||||||
|
[[ "$output" == *"[broken] unknown field verison="* ]]
|
||||||
|
[[ "$output" == *"[broken] needs version="* ]]
|
||||||
|
[[ "$output" == *"[broken] needs exactly one of git= and wget="* ]]
|
||||||
|
[[ "$output" == *"[broken] ref= should be a full commit hash"* ]]
|
||||||
|
[[ "$output" == *"[broken] desktop=\$HAMPACK_DIR/desktop/nope.desktop doesn't exist"* ]]
|
||||||
|
[[ "$output" == *"[broken] install= should be under \$HOME"* ]]
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "packages.conf: names are valid, listed once, and the Flatpaks look like app IDs" {
|
||||||
|
local p
|
||||||
|
while IFS= read -r p; do
|
||||||
|
[[ "$p" =~ ^[a-z0-9@_+][a-z0-9@._+-]*$ ]] || PROBLEMS+=("bad package name: $p")
|
||||||
|
done < <(all_hampack_packages)
|
||||||
|
while IFS= read -r p; do
|
||||||
|
[[ "$p" =~ ^[A-Za-z0-9_-]+(\.[A-Za-z0-9_-]+){2,}$ ]] || PROBLEMS+=("bad Flatpak ID: $p")
|
||||||
|
done < <(all_hampack_flatpaks)
|
||||||
|
p="$( { all_hampack_packages; all_hampack_flatpaks; } | sort | uniq -d)"
|
||||||
|
[ -z "$p" ] || PROBLEMS+=("listed more than once: $p")
|
||||||
|
no_problems
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "desktop files: each has a Name= and an Exec=, and its icon is in the repo" {
|
||||||
|
local f icon
|
||||||
|
for f in "$REPO"/desktop/*.desktop; do
|
||||||
|
grep -q "^Exec=" "$f" || PROBLEMS+=("$(basename "$f") has no Exec=")
|
||||||
|
grep -q "^Name=" "$f" || PROBLEMS+=("$(basename "$f") has no Name=")
|
||||||
|
icon="$(sed -n 's/^Icon=//p' "$f")"
|
||||||
|
if [[ "$icon" == '$HAMPACK_DIR/'* ]] && [ ! -e "$(expand_vars "$icon")" ]; then
|
||||||
|
PROBLEMS+=("$(basename "$f"): $icon doesn't exist")
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
no_problems
|
||||||
|
}
|
||||||
@@ -0,0 +1,218 @@
|
|||||||
|
#!/usr/bin/env bats
|
||||||
|
|
||||||
|
load helpers
|
||||||
|
|
||||||
|
# curl, git and pacman are stubbed: GitHub releases, tags, HEADs, Last-Modified
|
||||||
|
# dates, the AUR and Flathub all answer from files in $FAKE_NET
|
||||||
|
setup() {
|
||||||
|
setup_fake_home
|
||||||
|
export FAKE_NET="$BATS_TEST_TMPDIR/net"
|
||||||
|
mkdir -p "$FAKE_NET"
|
||||||
|
export HAMPACK_BINARIES_CONF="$BATS_TEST_TMPDIR/binaries.conf"
|
||||||
|
export HAMPACK_COMPILE_CONF="$BATS_TEST_TMPDIR/compile.conf"
|
||||||
|
export HAMPACK_PACKAGES_CONF="$BATS_TEST_TMPDIR/packages.conf"
|
||||||
|
: > "$HAMPACK_BINARIES_CONF"
|
||||||
|
: > "$HAMPACK_COMPILE_CONF"
|
||||||
|
|
||||||
|
stub curl '
|
||||||
|
url=""; for a in "$@"; do case "$a" in https://*) url="$a" ;; esac; done
|
||||||
|
case "$url" in
|
||||||
|
https://api.github.com/repos/*/releases/latest)
|
||||||
|
f="$FAKE_NET/release-$(echo "$url" | cut -d/ -f5-6 | tr / _)"
|
||||||
|
[ -f "$f" ] || exit 22
|
||||||
|
echo "{\"tag_name\": \"$(cat "$f")\"}" ;;
|
||||||
|
https://aur.archlinux.org/*)
|
||||||
|
[ -f "$FAKE_NET/aur-down" ] && exit 7
|
||||||
|
printf "{\"results\":["; sep=""
|
||||||
|
for a in "$@"; do
|
||||||
|
case "$a" in "arg[]="*)
|
||||||
|
p="${a#arg[]=}"
|
||||||
|
grep -qxF "$p" "$FAKE_NET/aur" 2>/dev/null && { printf "%s{\"Name\":\"%s\"}" "$sep" "$p"; sep=,; } ;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
echo "]}" ;;
|
||||||
|
https://flathub.org/*)
|
||||||
|
grep -qxF "${url##*/}" "$FAKE_NET/flathub" 2>/dev/null && echo 200 || echo 404 ;;
|
||||||
|
*)
|
||||||
|
f="$FAKE_NET/modified-${url##*/}"
|
||||||
|
[ -f "$f" ] || exit 22
|
||||||
|
printf "HTTP/1.1 200 OK\r\nLast-Modified: %s\r\n" "$(cat "$f")" ;;
|
||||||
|
esac'
|
||||||
|
|
||||||
|
stub git '
|
||||||
|
[ "$1" = ls-remote ] || exit 1
|
||||||
|
if [ "$2" = --tags ]; then cat "$FAKE_NET/tags-${4##*/}" 2>/dev/null
|
||||||
|
else f="$FAKE_NET/head-${2##*/}"; [ -f "$f" ] && printf "%s\tHEAD\n" "$(cat "$f")"
|
||||||
|
fi; exit 0'
|
||||||
|
|
||||||
|
# Repo packages, groups, and names only provided by another package
|
||||||
|
stub pacman '
|
||||||
|
case "$1" in
|
||||||
|
-Si) grep -qxF "$2" "$FAKE_NET/repo" 2>/dev/null ;;
|
||||||
|
-Sg) grep -qxF "$2" "$FAKE_NET/groups" 2>/dev/null ;;
|
||||||
|
-Sddp) grep "^$4=" "$FAKE_NET/provides" 2>/dev/null | cut -d= -f2 | grep . ;;
|
||||||
|
*) exit 1 ;;
|
||||||
|
esac'
|
||||||
|
}
|
||||||
|
|
||||||
|
tags() { local repo="$1"; shift; printf 'abc\trefs/tags/%s\n' "$@" > "$FAKE_NET/tags-$repo"; }
|
||||||
|
|
||||||
|
packages_conf() {
|
||||||
|
printf 'UTILITIES=(\n%s\n)\nAPPLICATIONS=(\n%s\n)\nFLATPAKS=(\n%s\n)\n' "$1" "$2" "$3" > "$HAMPACK_PACKAGES_CONF"
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "hampackcheck: binaries are compared with their latest GitHub release" {
|
||||||
|
cat > "$HAMPACK_BINARIES_CONF" << 'EOF'
|
||||||
|
[old]
|
||||||
|
version=1.0
|
||||||
|
url=https://github.com/me/old/releases/download/v1.0/old
|
||||||
|
sha256=x
|
||||||
|
[current]
|
||||||
|
version=2.0
|
||||||
|
url=https://github.com/me/current/releases/download/v2.0/current
|
||||||
|
sha256=x
|
||||||
|
[offline]
|
||||||
|
version=1.0
|
||||||
|
url=https://github.com/me/offline/releases/download/1.0/offline
|
||||||
|
sha256=x
|
||||||
|
[elsewhere]
|
||||||
|
version=1.0
|
||||||
|
url=https://example.com/files/elsewhere
|
||||||
|
EOF
|
||||||
|
echo v1.1 > "$FAKE_NET/release-me_old"
|
||||||
|
echo v2.0 > "$FAKE_NET/release-me_current"
|
||||||
|
run "$REPO/hampackcheck" versions
|
||||||
|
[ "$status" -eq 0 ]
|
||||||
|
[[ "$output" =~ old\ +pinned=1.0\ +latest=1.1\ +\*\*\ UPDATE\ AVAILABLE ]]
|
||||||
|
[[ "$output" =~ current\ +up\ to\ date\ \(2.0\) ]]
|
||||||
|
[[ "$output" =~ offline\ +pinned=1.0\ +\(GitHub\ API\ unavailable\) ]]
|
||||||
|
[[ "$output" == *"manual check: https://example.com/files"* ]]
|
||||||
|
[[ "$output" == *"elsewhere has no sha256="* ]]
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "hampackcheck: a binary pinned to a commit is compared with upstream HEAD" {
|
||||||
|
cat > "$HAMPACK_BINARIES_CONF" << 'EOF'
|
||||||
|
[script]
|
||||||
|
version=aaaa
|
||||||
|
url=https://raw.githubusercontent.com/me/script/aaaa/script.py
|
||||||
|
sha256=x
|
||||||
|
EOF
|
||||||
|
echo bbbb > "$FAKE_NET/head-script"
|
||||||
|
run "$REPO/hampackcheck" versions
|
||||||
|
[[ "$output" =~ script\ +pinned=aaaa\ +latest=bbbb ]]
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "hampackcheck: built apps use the newest plain version tag, not pre-releases" {
|
||||||
|
cat > "$HAMPACK_COMPILE_CONF" << 'EOF'
|
||||||
|
[app]
|
||||||
|
version=1.9
|
||||||
|
git=https://example.com/app
|
||||||
|
EOF
|
||||||
|
tags app v1.9 v1.10 v2.0-beta1 nightly 1.2
|
||||||
|
run "$REPO/hampackcheck" versions
|
||||||
|
[[ "$output" =~ app\ +pinned=1.9\ +latest=1.10\ +\*\*\ UPDATE ]]
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "hampackcheck: a built app shows its name= rather than its section" {
|
||||||
|
printf '[app-improved]\nname=App\nversion=1.0\ngit=https://example.com/app\n' > "$HAMPACK_COMPILE_CONF"
|
||||||
|
tags app 1.0
|
||||||
|
run "$REPO/hampackcheck" versions
|
||||||
|
[[ "$output" =~ App\ +up\ to\ date ]]
|
||||||
|
[[ "$output" != *app-improved* ]]
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "hampackcheck: an untagged repo pinned with ref= is compared with HEAD" {
|
||||||
|
cat > "$HAMPACK_COMPILE_CONF" << 'EOF'
|
||||||
|
[same]
|
||||||
|
version=1.0
|
||||||
|
git=https://example.com/same
|
||||||
|
ref=1111111111
|
||||||
|
[moved]
|
||||||
|
version=1.0
|
||||||
|
git=https://example.com/moved
|
||||||
|
ref=1111111111
|
||||||
|
EOF
|
||||||
|
echo 1111111111 > "$FAKE_NET/head-same"
|
||||||
|
echo 2222222222 > "$FAKE_NET/head-moved"
|
||||||
|
run "$REPO/hampackcheck" versions
|
||||||
|
[[ "$output" =~ same\ +up\ to\ date ]]
|
||||||
|
[[ "$output" =~ moved\ +pinned=1.0\ +latest=HEAD\ 2222222222 ]]
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "hampackcheck: an archive versioned by date is compared with its Last-Modified date" {
|
||||||
|
cat > "$HAMPACK_COMPILE_CONF" << 'EOF'
|
||||||
|
[dated]
|
||||||
|
version=2026-01-01
|
||||||
|
wget=https://example.com/dated.zip
|
||||||
|
[numbered]
|
||||||
|
version=3.0
|
||||||
|
wget=https://example.com/numbered.zip
|
||||||
|
EOF
|
||||||
|
echo "Fri, 06 Mar 2026 12:00:00 GMT" > "$FAKE_NET/modified-dated.zip"
|
||||||
|
run "$REPO/hampackcheck" versions
|
||||||
|
[[ "$output" =~ dated\ +pinned=2026-01-01\ +latest=2026-03-06 ]]
|
||||||
|
[[ "$output" == *"manual check: https://example.com"* ]]
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "hampackcheck: versions alone doesn't check packages" {
|
||||||
|
run "$REPO/hampackcheck" versions
|
||||||
|
[ "$status" -eq 0 ]
|
||||||
|
[[ "$output" != *packages.conf* ]]
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "hampackcheck: packages in the repos, groups, the AUR and Flathub all pass" {
|
||||||
|
packages_conf "repo-pkg
|
||||||
|
a-group # with a comment" "aur-pkg" "org.example.App"
|
||||||
|
echo repo-pkg > "$FAKE_NET/repo"
|
||||||
|
echo a-group > "$FAKE_NET/groups"
|
||||||
|
echo aur-pkg > "$FAKE_NET/aur"
|
||||||
|
echo org.example.App > "$FAKE_NET/flathub"
|
||||||
|
run "$REPO/hampackcheck" packages
|
||||||
|
[ "$status" -eq 0 ]
|
||||||
|
[[ "$output" == *"3 packages, 2 in the repos"* ]]
|
||||||
|
[[ "$output" == *"aur-pkg is on the AUR"* ]]
|
||||||
|
[[ "$output" == *"org.example.App is on Flathub"* ]]
|
||||||
|
[[ "$output" != *MISSING* ]]
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "hampackcheck: a misspelt package or Flatpak fails the check" {
|
||||||
|
packages_conf "repo-pkg
|
||||||
|
repo-pgk" "aur-pkg" "org.example.Ap"
|
||||||
|
echo repo-pkg > "$FAKE_NET/repo"
|
||||||
|
echo aur-pkg > "$FAKE_NET/aur"
|
||||||
|
run "$REPO/hampackcheck" packages
|
||||||
|
[ "$status" -eq 1 ]
|
||||||
|
[[ "$output" == *"repo-pgk is in neither the repos nor the AUR ** MISSING **"* ]]
|
||||||
|
[[ "$output" == *"org.example.Ap is not on Flathub ** MISSING **"* ]]
|
||||||
|
[[ "$output" != *"repo-pkg is"* ]]
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "hampackcheck: a name only provided by another package passes, with a note" {
|
||||||
|
packages_conf "old-name" "" ""
|
||||||
|
echo "old-name=new-name" > "$FAKE_NET/provides"
|
||||||
|
run "$REPO/hampackcheck" packages
|
||||||
|
[ "$status" -eq 0 ]
|
||||||
|
[[ "$output" == *"old-name is provided by new-name"* ]]
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "hampackcheck: if the AUR can't be reached, the check fails rather than passing" {
|
||||||
|
packages_conf "aur-pkg" "" ""
|
||||||
|
touch "$FAKE_NET/aur-down"
|
||||||
|
run "$REPO/hampackcheck" packages
|
||||||
|
[ "$status" -eq 1 ]
|
||||||
|
[[ "$output" == *"The AUR couldn't be reached, so these weren't checked: aur-pkg"* ]]
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "hampackcheck: with everything in the repos, the AUR isn't asked" {
|
||||||
|
packages_conf "repo-pkg" "" ""
|
||||||
|
echo repo-pkg > "$FAKE_NET/repo"
|
||||||
|
touch "$FAKE_NET/aur-down"
|
||||||
|
run "$REPO/hampackcheck" packages
|
||||||
|
[ "$status" -eq 0 ]
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "hampackcheck: an unknown argument prints the usage" {
|
||||||
|
run "$REPO/hampackcheck" everything
|
||||||
|
[ "$status" -eq 2 ]
|
||||||
|
[[ "$output" == Usage:* ]]
|
||||||
|
}
|
||||||
@@ -81,8 +81,3 @@ EOF
|
|||||||
[ "$status" -eq 0 ]
|
[ "$status" -eq 0 ]
|
||||||
[ "$(cat "$HOME/.local/bin/tool")" = "v1" ]
|
[ "$(cat "$HOME/.local/bin/tool")" = "v1" ]
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "binaries.conf entries all have a sha256" {
|
|
||||||
run grep -c '^sha256=' "$REPO/binaries.conf"
|
|
||||||
[ "$output" -eq "$(grep -c '^\[' "$REPO/binaries.conf")" ]
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user