From 5eaec0dae6a0db244164fb1df93eab729a10482e Mon Sep 17 00:00:00 2001 From: Mike King <2684049+3mkay@users.noreply.github.com> Date: Mon, 10 Feb 2025 13:38:48 +0000 Subject: [PATCH 1/2] Update check-annertech-ddev Add creation, checking and updating of a tmp file which has the version number in it. --- commands/web/check-annertech-ddev | 34 ++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/commands/web/check-annertech-ddev b/commands/web/check-annertech-ddev index c4b850d..ecc700d 100755 --- a/commands/web/check-annertech-ddev +++ b/commands/web/check-annertech-ddev @@ -11,8 +11,40 @@ YELLOW='\033[0;33m' NC='\033[0m' # No Color STARS='****************************************' +# Get the current Addon version ADDONVER=$(grep -oP '(?<=version: ")[^"]+' .ddev/addon-metadata/annertech-ddev/manifest.yaml) -LATESTVER=$(curl -sL https://api.github.com/repos/annertech/annertech-ddev/releases/latest | jq -r ".tag_name") + +# Define the path to store the version file +VERSION_FILE="/tmp/addon-version.txt" + +# Function to get the latest tag from GitHub API using curl and jq +get_latest_tag() { + # Use -s for silent mode, L for follow redirects, and output in JSON format + # Extract the tag_name field using jq and convert it to a raw string (without quotes) + curl -sL https://api.github.com/repos/annertech/annertech-ddev/releases/latest | \ + jq -r ".tag_name" +} + +# Check if version file exists +if [ ! -f "$VERSION_FILE" ]; then + echo "Version file does not exist. Creating..." + # Get latest tag and save it to the version file + get_latest_tag > "$VERSION_FILE" +else + # Calculate how long ago the version file was modified in seconds + age=$(( $(date +%s) - $(stat -c %Y "$VERSION_FILE") )) + + if [ $age -gt 86400 ]; then + echo "Version file is older than 24 hours. Updating..." + # Get latest tag and save it to the version file + get_latest_tag > "$VERSION_FILE" + else + echo "Version file exists and is less than 24 hours old." + fi +fi + +LATESTVER=$(cat ${VERSION_FILE}) + printf "%b\n" "${YELLOW}${STARS}" printf "Checking Annertech DDEV addon\n" From 756cf1441f94ba74e806516a0ef96f585326c646 Mon Sep 17 00:00:00 2001 From: Mike King <2684049+3mkay@users.noreply.github.com> Date: Tue, 11 Feb 2025 08:39:25 +0000 Subject: [PATCH 2/2] Update commands/web/check-annertech-ddev Co-authored-by: Bill Seremetis --- commands/web/check-annertech-ddev | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/commands/web/check-annertech-ddev b/commands/web/check-annertech-ddev index ecc700d..c22503d 100755 --- a/commands/web/check-annertech-ddev +++ b/commands/web/check-annertech-ddev @@ -15,7 +15,7 @@ STARS='****************************************' ADDONVER=$(grep -oP '(?<=version: ")[^"]+' .ddev/addon-metadata/annertech-ddev/manifest.yaml) # Define the path to store the version file -VERSION_FILE="/tmp/addon-version.txt" +VERSION_FILE="/tmp/annertech-ddev-addon-version.txt" # Function to get the latest tag from GitHub API using curl and jq get_latest_tag() {