Validate Latest Release URLs #88
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 | |
| id: check-releases | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Use GitHub Actions built-in token | |
| run: | | |
| BADGES_FILE="../badges.json" | |
| OUTDATED_PLUGINS=0 | |
| REPORT="### 📢 Outdated Plugin Report\n\n@GarlicRot, some plugins have outdated release URLs!\n\n" | |
| 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 (with authentication) | |
| RESPONSE=$(curl -s -H "Authorization: token $GITHUB_TOKEN" -H "Accept: application/vnd.github.v3+json" $API_URL) | |
| # Ensure the API response is valid | |
| if [[ "$RESPONSE" == "null" || -z "$RESPONSE" ]]; then | |
| echo "⚠️ GitHub API returned null response for $OWNER/$REPO. Skipping..." | |
| continue | |
| fi | |
| # Check if the repository has any releases | |
| RELEASE_CHECK=$(echo "$RESPONSE" | jq -r 'if .tag_name then "exists" else "no_release" end') | |
| if [[ "$RELEASE_CHECK" == "no_release" ]]; then | |
| echo "⚠️ No releases found for $OWNER/$REPO. Skipping..." | |
| continue | |
| fi | |
| # Ensure assets exist before trying to extract them | |
| ASSETS_EXIST=$(echo "$RESPONSE" | jq -r 'if .assets then "exists" else "no_assets" end') | |
| if [[ "$ASSETS_EXIST" == "no_assets" ]]; then | |
| echo "⚠️ No assets found in the latest release for $OWNER/$REPO. Skipping..." | |
| continue | |
| fi | |
| # Extract the first .jar file URL | |
| LATEST_RELEASE=$(echo "$RESPONSE" | jq -r '[.assets[] | select(.name | endswith(".jar"))][0].browser_download_url') | |
| # Skip if no JAR file is found | |
| if [[ "$LATEST_RELEASE" == "null" || -z "$LATEST_RELEASE" ]]; then | |
| echo "⚠️ No JAR file found for $OWNER/$REPO. Skipping..." | |
| continue | |
| fi | |
| # Compare stored latest release URL with actual one | |
| if [[ "$LATEST_STORED" != "$LATEST_RELEASE" ]]; then | |
| echo "::error file=badges.json,title=Outdated Plugin::$OWNER/$REPO is outdated." | |
| REPORT+="🚨 **$OWNER/$REPO**\n" | |
| REPORT+="🔹 **Stored:** [$LATEST_STORED]($LATEST_STORED)\n" | |
| REPORT+="🔹 **Latest:** [$LATEST_RELEASE]($LATEST_RELEASE)\n\n" | |
| echo "-----------------------------------" | |
| OUTDATED_PLUGINS=1 | |
| fi | |
| done | |
| done | |
| echo "$REPORT" > outdated_plugins_report.md | |
| # Explicitly set the `outdated` environment variable | |
| if [[ $OUTDATED_PLUGINS -eq 1 ]]; then | |
| echo "outdated=1" >> $GITHUB_ENV | |
| else | |
| echo "outdated=0" >> $GITHUB_ENV | |
| fi | |
| - name: Debug `outdated` Variable | |
| run: echo "outdated=$outdated" | |
| - name: Debug Report Content | |
| run: cat outdated_plugins_report.md | |
| - name: Create GitHub Issue Notification | |
| if: env.outdated == '1' | |
| uses: peter-evans/create-issue-from-file@v4 | |
| with: | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| title: "🚨 Outdated Plugin Report" | |
| content-filepath: outdated_plugins_report.md | |
| labels: bug |