Files
eden/tools/cpm/check-updates.sh
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

137 lines
2.7 KiB
Bash
Raw Normal View History

#!/bin/sh -e
# SPDX-FileCopyrightText: 2025 crueter
# SPDX-License-Identifier: GPL-3.0-or-later
# shellcheck disable=SC1091
. tools/cpm/common.sh
RETURN=0
filter() {
2025-10-20 03:43:15 +02:00
TAGS=$(echo "$TAGS" | jq "[.[] | select(.name | test(\"$1\"; \"i\") | not)]")
}
2025-10-20 03:43:15 +02:00
usage() {
cat << EOF
Usage: $0 [uf] [PACKAGE]...
Check a specific package or packages for updates.
Options:
-u, --update Update the package if a new version is available.
This will also update the hash if provided.
-f, --force Forcefully update the package version (implies -u)
This is seldom useful, and should only be used in cases of
severe corruption.
This project has defined the following as valid cpmfiles:
EOF
for file in $CPMFILES; do
echo "- $file"
done
exit $RETURN
}
while true; do
case "$1" in
2025-11-04 07:05:52 +01:00
-f | --force)
UPDATE=true
FORCE=true
shift
continue
;;
-u | --update)
UPDATE=true
shift
continue
;;
-h) usage ;;
"$0") break ;;
"") break ;;
2025-10-20 03:43:15 +02:00
esac
PACKAGE="$1"
shift
export PACKAGE
# shellcheck disable=SC1091
. tools/cpm/package.sh
2025-11-04 07:05:52 +01:00
SKIP=$(value "skip_updates")
2025-11-04 07:05:52 +01:00
[ "$SKIP" = "true" ] && continue
2025-11-04 07:05:52 +01:00
[ "$REPO" = null ] && continue
[ "$GIT_HOST" != "github.com" ] && continue # TODO
if [ "$CI" = "true" ]; then
TAG="v$VERSION"
fi
2025-11-04 07:05:52 +01:00
[ "$TAG" = null ] && continue
2025-11-04 07:05:52 +01:00
echo "-- Package $PACKAGE"
# TODO(crueter): Support for Forgejo updates w/ forgejo_token
2025-11-04 07:05:52 +01:00
# Use gh-cli to avoid ratelimits lmao
TAGS=$(gh api --method GET "/repos/$REPO/tags")
2025-11-04 07:05:52 +01:00
# filter out some commonly known annoyances
# TODO add more
2025-11-04 07:05:52 +01:00
filter vulkan-sdk # vulkan
filter yotta # mbedtls
2025-11-04 07:05:52 +01:00
# ignore betas/alphas (remove if needed)
filter alpha
filter beta
filter rc
# Add package-specific overrides here, e.g. here for fmt:
2025-11-04 07:05:52 +01:00
[ "$PACKAGE" = fmt ] && filter v0.11
2025-11-04 07:05:52 +01:00
LATEST=$(echo "$TAGS" | jq -r '.[0].name')
2025-11-04 07:05:52 +01:00
[ "$LATEST" = "$TAG" ] && [ "$FORCE" != "true" ] && echo "-- * Up-to-date" && continue
RETURN=1
2025-11-04 07:05:52 +01:00
if [ "$HAS_REPLACE" = "true" ]; then
# this just extracts the tag prefix
VERSION_PREFIX=$(echo "$ORIGINAL_TAG" | cut -d"%" -f1)
2025-11-04 07:05:52 +01:00
# then we strip out the prefix from the new tag, and make that our new git_version
if [ -z "$VERSION_PREFIX" ]; then
NEW_GIT_VERSION="$LATEST"
else
NEW_GIT_VERSION=$(echo "$LATEST" | sed "s/$VERSION_PREFIX//g")
fi
fi
2025-11-04 07:05:52 +01:00
echo "-- * Version $LATEST available, current is $TAG"
2025-11-04 07:05:52 +01:00
HASH=$(tools/cpm/hash.sh "$REPO" "$LATEST")
2025-11-04 07:05:52 +01:00
echo "-- * New hash: $HASH"
2025-11-04 07:05:52 +01:00
if [ "$UPDATE" = "true" ]; then
RETURN=0
2025-11-04 07:05:52 +01:00
if [ "$HAS_REPLACE" = "true" ]; then
NEW_JSON=$(echo "$JSON" | jq ".hash = \"$HASH\" | .git_version = \"$NEW_GIT_VERSION\"")
else
NEW_JSON=$(echo "$JSON" | jq ".hash = \"$HASH\" | .tag = \"$LATEST\"")
fi
export NEW_JSON
tools/cpm/replace.sh
2025-11-04 07:05:52 +01:00
fi
done
2025-11-04 07:05:52 +01:00
exit $RETURN