Skip to content

Instantly share code, notes, and snippets.

@VeckoTheGecko
Last active August 27, 2023 03:00
Show Gist options
  • Save VeckoTheGecko/7b6bb062135e59fbc9c5703c48435f5f to your computer and use it in GitHub Desktop.
Save VeckoTheGecko/7b6bb062135e59fbc9c5703c48435f5f to your computer and use it in GitHub Desktop.
Easy URL checking GitHub Action
name: Check URL Status
on:
workflow_dispatch:
schedule:
- cron: 0 0 * * 0
env:
LINK_TRACKING_ISSUE_NUMBER: 322
permissions:
issues: write
jobs:
check-urls:
if: ${{ !github.event.repository.fork }}
env:
LYCHEE_REPORT_FILE: ./lychee/out.md
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Link Checker
id: lychee
uses: lycheeverse/lychee-action@v1.8.0
- name: Read Lychee report
if: env.lychee_exit_code != 0
id: readReport
run: |
EOF=$(dd if=/dev/urandom bs=15 count=1 status=none | base64)
echo "FILE_CONTENT<<$EOF" >> $GITHUB_OUTPUT
echo "$(cat ${{ env.LYCHEE_REPORT_FILE }})" >> $GITHUB_OUTPUT
echo "$EOF" >> $GITHUB_OUTPUT
- run: echo "${{ steps.readReport.outputs.FILE_CONTENT }}"
- name: Update link tracking issue (update invalid links)
if: env.lychee_exit_code != 0
uses: actions-cool/issues-helper@v3
with:
actions: "update-issue"
token: ${{ secrets.GITHUB_TOKEN }}
issue-number: ${{ env.LINK_TRACKING_ISSUE_NUMBER }}
state: "open"
body: ${{ steps.readReport.outputs.FILE_CONTENT }}
update-mode: "replace"
- name: Update link tracking issue (no invalid links)
if: env.lychee_exit_code == 0
uses: actions-cool/issues-helper@v3
with:
actions: "update-issue"
token: ${{ secrets.GITHUB_TOKEN }}
issue-number: ${{ env.link_tracking_issue_number }}
state: "closed"
body: "No invalid links found! 🤖"
update-mode: "replace"
- name: Upload artifact
uses: actions/upload-artifact@v3
with:
name: lychee-report
path: ${{ env.LYCHEE_REPORT_FILE }}
@VeckoTheGecko
Copy link
Author

This GitHub Action workflow checks the statuses of URLs within a repository, generating a report, and updating an issue with report results (by updating the issue body). This allows for the automated testing an monitoring of links in a non-intrusive way (i.e. without failing CI) with good oversight.

Steps:

  • Copy/paste workflow
  • Create an issue in your repo
  • Update LINK_TRACKING_ISSUE_NUMBER with issue number
  • Update workflow triggers to your liking

Other notes:

  • Mileage may vary on forks (a permission error with actions-cool/issues-helper, something about security [1])
  • Update versions of workflow actions before using

Screenshot of updated issue:

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment