Validate Latest Release URLs #61
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: Check and Update Badges | |
| on: | |
| workflow_dispatch: # Allows manual trigger | |
| jobs: | |
| check-badges: | |
| runs-on: ubuntu-22.04 | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v3 | |
| with: | |
| fetch-depth: 0 | |
| - name: Switch to gh-pages branch | |
| run: | | |
| git checkout gh-pages | |
| echo "::notice::Switched to gh-pages branch." | |
| - name: Set up Node.js | |
| uses: actions/setup-node@v3 | |
| with: | |
| node-version: '18' | |
| - name: Install dependencies | |
| run: | | |
| npm install axios fast-deep-equal | |
| echo "::notice::Dependencies installed." | |
| - name: Check and update only latest release URLs | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| set -e | |
| node check-badges.js || { echo "Badge check failed!"; exit 1; } | |
| echo "::notice::Badge check script completed." | |
| - name: Clean up untracked files | |
| run: | | |
| rm -rf node_modules package-lock.json package.json | |
| echo "::notice::Cleaned up untracked files." | |
| - name: Check for changes in badges.json | |
| id: check_changes | |
| run: | | |
| git add badges.json | |
| if git diff --cached --quiet; then | |
| echo "::notice::No changes detected in badges.json." | |
| echo "skip=true" >> $GITHUB_ENV | |
| else | |
| echo "::notice::Changes detected in badges.json." | |
| fi | |
| - name: Commit changes and create a new branch | |
| if: env.skip != 'true' | |
| id: set-branch-name | |
| run: | | |
| git config --local user.name "GitHub Actions Bot" | |
| git config --local user.email "[email protected]" | |
| BRANCH_NAME="update-badges-${{ github.run_id }}" | |
| echo "BRANCH_NAME=$BRANCH_NAME" >> $GITHUB_ENV | |
| TOTAL_PLUGINS=$(jq -r '.totalPlugins.message' badges.json) | |
| git checkout -b $BRANCH_NAME | |
| git commit -m "Update badges.json with latest release URLs (Total Plugins: $TOTAL_PLUGINS)" | |
| git push origin HEAD | |
| echo "::notice::Changes committed and branch pushed." | |
| - name: Create issue content file | |
| run: | | |
| echo "**PR Needed: Update Badges**" > issue-content.md | |
| echo "" >> issue-content.md | |
| echo "A new branch has been created: **${{ env.BRANCH_NAME }}**." >> issue-content.md | |
| echo "" >> issue-content.md | |
| echo "Please review the changes and open a pull request from this branch." >> issue-content.md | |
| echo "" >> issue-content.md | |
| echo "**Compare Changes:** [View on GitHub](https://github.com/${{ github.repository }}/compare/gh-pages...${{ env.BRANCH_NAME }})" >> issue-content.md | |
| - name: Create GitHub Issue for PR Notification | |
| if: env.skip != 'true' | |
| uses: peter-evans/create-issue-from-file@v4 | |
| with: | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| title: "PR Needed: Update Badges" | |
| content-filepath: issue-content.md | |
| labels: "automated notification" | |
| repository: ${{ github.repository }} |