Validate Latest Release URLs #79
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Validate Latest Release URLs | |
| on: | |
| workflow_dispatch: # Allows manual triggering | |
| jobs: | |
| check-badges: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout Repository | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 # Ensures full branch history | |
| - name: Fetch badges.json from gh-pages | |
| run: | | |
| git fetch --all | |
| git checkout --track origin/gh-pages || git checkout gh-pages | |
| cp badges.json ../badges.json # Move file to main working directory | |
| - name: Install jq | |
| run: sudo apt-get install jq | |
| - name: Check Latest Release URLs | |
| run: | | |
| BADGES_FILE="../badges.json" | |
| OUTDATED_PLUGINS=0 | |
| echo "🔍 Checking latest releases for themes and plugins..." | |
| for SECTION in "themes" "plugins"; do | |
| cat $BADGES_FILE | jq -c --arg section "$SECTION" '.[$section][]' | while read entry; do | |
| NAME=$(echo $entry | jq -r '.name') | |
| REPO_URL=$(echo $entry | jq -r '.url') | |
| LATEST_STORED=$(echo $entry | jq -r '.latestReleaseUrl') | |
| OWNER=$(echo $REPO_URL | awk -F '/' '{print $(NF-1)}') | |
| REPO=$(echo $REPO_URL | awk -F '/' '{print $NF}') | |
| API_URL="https://api.github.com/repos/$OWNER/$REPO/releases/latest" | |
| echo "Checking: $OWNER/$REPO" | |
| # Fetch latest release info | |
| RESPONSE=$(curl -s -H "Accept: application/vnd.github.v3+json" $API_URL) | |
| # Handle invalid API response | |
| if [[ "$RESPONSE" == "null" || -z "$RESPONSE" ]]; then | |
| echo "::warning file=badges.json,title=GitHub API Error::Failed to fetch release data for $OWNER/$REPO." | |
| continue | |
| fi | |
| # Check if the release has assets | |
| ASSETS_EXIST=$(echo "$RESPONSE" | jq -r '.assets | length') | |
| if [[ "$ASSETS_EXIST" == "null" || "$ASSETS_EXIST" -eq 0 ]]; then | |
| echo "::warning file=badges.json,title=No JAR File Found::$OWNER/$REPO has no assets in the latest release." | |
| continue | |
| fi | |
| # Extract the first .jar file URL | |
| LATEST_RELEASE=$(echo "$RESPONSE" | jq -r '[.assets[] | select(.name | endswith(".jar"))][0].browser_download_url') | |
| # Validate extracted URL | |
| if [[ "$LATEST_RELEASE" == "null" || -z "$LATEST_RELEASE" ]]; then | |
| echo "::warning file=badges.json,title=No JAR File Found::$OWNER/$REPO does not have a .jar file in its latest release." | |
| continue | |
| fi | |
| # Compare stored latest release URL with actual one | |
| if [[ "$LATEST_STORED" != "$LATEST_RELEASE" ]]; then | |
| echo "::error file=badges.json,title=Outdated Release::$OWNER/$REPO" | |
| echo "::error file=badges.json,title=Stored URL::$LATEST_STORED" | |
| echo "::error file=badges.json,title=Latest JAR URL::$LATEST_RELEASE" | |
| echo "-----------------------------------" | |
| OUTDATED_PLUGINS=1 | |
| fi | |
| done | |
| done | |
| if [[ $OUTDATED_PLUGINS -eq 1 ]]; then | |
| echo "::error:: Some plugins/themes have outdated release URLs! Check annotations for details." | |
| exit 1 | |
| fi |