Skip to content

Validate Latest Release URLs #42

Validate Latest Release URLs

Validate Latest Release URLs #42

Workflow file for this run

name: Check and Create PR for Badges
on:
schedule:
- cron: '0 0 * * *' # Runs daily at midnight UTC
workflow_dispatch: # Allows manual trigger
jobs:
check-badges:
runs-on: ubuntu-22.04
outputs:
branch_name: ${{ steps.set-branch-name.outputs.branch_name }}
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
echo "::notice::Dependencies installed."
- name: Check and update only latest release URLs
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
node check-badges.js
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
echo "$BRANCH_NAME" > branch-name.txt
git checkout -b $BRANCH_NAME
git commit -m "Update badges.json with latest release URLs"
git push origin HEAD
echo "::set-output name=branch_name::$BRANCH_NAME"
echo "::notice::Changes committed and branch pushed."
- name: Upload branch name artifact
if: env.skip != 'true'
uses: actions/upload-artifact@v4
with:
name: branch-name
path: branch-name.txt
create-pr:
runs-on: ubuntu-22.04
needs: check-badges
if: needs.check-badges.outputs.branch_name != ''
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Download branch name artifact
uses: actions/download-artifact@v4
with:
name: branch-name
- name: Load branch name
run: |
BRANCH_NAME=$(cat branch-name.txt)
echo "Loaded branch name: $BRANCH_NAME"
echo "BRANCH_NAME=$BRANCH_NAME" >> $GITHUB_ENV
- name: Create Pull Request
uses: peter-evans/create-pull-request@v5
with:
token: ${{ secrets.GITHUB_TOKEN }}
base: gh-pages
branch: ${{ env.BRANCH_NAME }}
title: "Update badges.json"
body: |
This pull request updates `badges.json` with the latest release URLs.
Please review and merge if everything looks correct.
labels: "automated update"
assignees: "Garlicrot"