Skip to content

Commit

Permalink
Merge pull request #37 from Annertech/35-reduce-calls-to-github-publi…
Browse files Browse the repository at this point in the history
…c-api

Update check-annertech-ddev
  • Loading branch information
3mkay authored Feb 11, 2025
2 parents 743a7b3 + 756cf14 commit 15648dc
Showing 1 changed file with 33 additions and 1 deletion.
34 changes: 33 additions & 1 deletion commands/web/check-annertech-ddev
Original file line number Diff line number Diff line change
Expand Up @@ -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/annertech-ddev-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"
Expand Down

0 comments on commit 15648dc

Please sign in to comment.