Skip to content

Regularly scheduled check links #40

Regularly scheduled check links

Regularly scheduled check links #40

# This is called after the deployed environment is ready to be checked
name: Regularly scheduled check links
on:
schedule:
- cron: "0 2 * * 1,4"
workflow_dispatch:
inputs:
url:
description: 'Site to check for broken links'
required: true
type: string
default: 'https://docs.platform.sh/'
jobs:
check-links:
name: Check links
runs-on: ubuntu-latest
steps:
- uses: actions/setup-python@v4
with:
python-version: '3.10'
- name: install linkchecker
id: install-linkchecker
run: |
pip3 install linkchecker
- name: checkout xml to markdown
uses: actions/checkout@v3
with:
repository: platformsh/linkchecker-xml2md
- name: install-parser
run: |
pip3 install -r requirements.txt
- name: Set URL to scan
id: set-url
shell: bash
run: |
# If this is a workflow dispatch, then use what was entered.
# If not, then use the repository variable SCAN_URL if it is set
# if not, fall back to the hard-coded default
scanURL="https://docs.platform.sh/"
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
scanURL="${{ inputs.url }}"
elif [[ -n "${{ vars.SCAN_URL }}" ]]; then
scanURL="${{ vars.SCAN_URL }}"
fi
echo "scanURL=${scanURL}" >> "$GITHUB_ENV"
- name: Run linkchecker
id: run-link-checker
continue-on-error: true
shell: bash
run: |
echo "::notice::Scanning ${{ inputs.url }} for broken links."
# if linkchecker exits with a non-zero then it means broken links were found.
scan=$(linkchecker ${{ env.scanURL }} -F xml/utf_8/brokenlinks.xml --check-extern --user-agent "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36" --ignore-url="^https://github.com/platformsh*" --ignore-url="console.platform.sh/projects/*" --ignore-url="support.blackfire.io/*" --ignore-url="cloud.orange-business.com/*" --ignore-url="developers.cloudflare.com/*" --ignore-url="discord.com/*" --ignore-url="pptr.dev/*" --ignore-url="mvnrepository.com/*" --ignore-url="https://dev.mysql.com/doc/refman/en/" --ignore-url="https://www.microsoft.com/en-us/trust-center/privacy/data-management")
result=$?
if [[ $result -ne 0 ]]; then
echo "::notice::Broken links detected."
fi
- name: Convert xml to markdown
if: ${{ steps.run-link-checker.outcome == 'failure' }}
run: |
./xml2md.py brokenlinks.xml > broken_links.md
- name: Report no broken links
if: ${{ steps.run-link-checker.outcome == 'success' }}
run: |
echo "::notice::No broken links were detected"
- name: Create issue from Markdown file
id: create-issue
if: ${{ steps.run-link-checker.outcome == 'failure' }}
uses: actions/github-script@v6
with:
script: |
var fs = require('fs');
var bodyMsg = fs.readFileSync('broken_links.md','utf8');
failMsg = ':bug: Broken links detected'
github.rest.issues.create({
owner: context.repo.owner,
repo: context.repo.repo,
title: failMsg,
body: bodyMsg,
labels: ['broken-links'],
})