Skip to content

External Link Check #106

External Link Check

External Link Check #106

# This link checks Microcks website links in Markdown HTML files once per day
# from: https://github.com/lycheeverse/lychee-action
# link checker used is 'lychee': https://github.com/lycheeverse/lychee
name: External Link Check
on:
# This event will only trigger a workflow run if the workflow file is on the default branch.
# ucomment the following line if you want to run the workflow manually
workflow_dispatch:
# Run once a week on Sunday at 00h42 UTC (0:42 AM UTC aka 1:42 AM CEST with daylight saving time)
schedule:
- cron: "42 0 * * 0"
jobs:
linkChecker:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
# Link Checker run with lychee action
- name: Link Checker
id: lychee
uses: lycheeverse/lychee-action@a8c4c7cb88f0c7386610c35eb25108e448569cb0 # v2.7.0
with:
args: --no-progress --insecure --user-agent 'curl/8.4.0' --scheme https --scheme http --header "accept=*/*" https://microcks.io/
# Use markdown as output format
format: markdown
token: ${{ secrets.CUSTOM_TOKEN }}
# Don't fail action on broken links
fail: false
# Check if report contains regex errors or broken links
- name: Check for Errors
id: check_errors
run: |
if grep -q "Errors in" ./lychee/out.md; then
echo "has_errors=true" >> $GITHUB_ENV
else
echo "has_errors=false" >> $GITHUB_ENV
fi
# Format the date for the issue title and store it in an environment variable
- name: Format Date
id: format_date
run: echo "DATE=$(date +'%A, %e. %b %Y')" >> $GITHUB_ENV
# Create an issue if there are broken links
- name: Create Issue From File
id: create_issue
if: env.has_errors == 'true'
uses: peter-evans/create-issue-from-file@e8ef132d6df98ed982188e460ebb3b5d4ef3a9cd # v5.0.1
with:
title: "External Link Check Report - ${{ env.DATE }}"
content-filepath: ./lychee/out.md
labels: report, automated issue, contribution message, help wanted, good first issue
# Store the issue number in an environment variable
- name: Store Issue Number
if: steps.create_issue.outputs.issue-number != ''
run: echo "ISSUE_NUMBER=${{ steps.create_issue.outputs.issue-number }}" >> $GITHUB_ENV
# Add a comment to the issue with the contribution message
- name: Add contribution message as new comment
if: env.ISSUE_NUMBER != ''
run: gh issue comment "$ISSUE_NUMBER" --body-file "$BODY"
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GH_REPO: ${{ github.repository }}
BODY: "./.github/contribution_message.md"