Check links #44
Workflow file for this run
This file contains 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
# This workflow verifies hyperlinks using the deployed | |
# docs site. It has to be triggered manually. | |
name: Check links | |
on: | |
workflow_dispatch: {} | |
schedule: | |
- cron: '39 0 20 * *' # every 20th of the month at 00:39 | |
env: | |
# space-separated list of the top-level sections to check in https://docs.giantswarm.io/{section}/ | |
SECTIONS: 'getting-started overview reference support tutorials' | |
jobs: | |
check-links: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Pull image | |
run: docker pull ghcr.io/linkchecker/linkchecker:latest | |
- name: Create output folder | |
run: | | |
mkdir -p output | |
chmod 777 output | |
- name: check-links-in-overview-pages | |
shell: python {0} | |
continue-on-error: true | |
run: | | |
import os | |
import subprocess | |
pwd = os.getcwd() | |
sections = os.getenv('SECTIONS').split() | |
for i, section in enumerate(sections): | |
# call docker run command | |
cmd = ['docker', 'run', '--rm', '--name', 'linkchecker', | |
'--volume', f'{pwd}/output:/workdir', '--workdir', '/workdir', | |
'ghcr.io/linkchecker/linkchecker:latest', | |
f'https://docs.giantswarm.io/{section}/', | |
'--check-extern', | |
'--threads', '1', | |
'--recursion-level', '2', | |
'--no-status', | |
'--file-output', f'html/utf8/{section}.html'] | |
result = subprocess.run(cmd) | |
if result.returncode > 0: | |
env_file = os.getenv('GITHUB_ENV') | |
with open(env_file, 'a') as f: | |
f.write(f"failed{i}=true\n") | |
- name: Store reports as artifacts | |
uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.2 | |
with: | |
name: link-check-reports | |
path: ./output | |
if-no-files-found: warn | |
retention-days: 14 | |
- name: Report errors | |
shell: python {0} | |
run: | | |
import sys | |
import os | |
found_error = False | |
sections = os.getenv('SECTIONS').split() | |
for i, section in enumerate(sections): | |
failed = os.getenv(f"failed{i}") | |
if failed == "true": | |
print(f"Found link errors in the {section} section. Please download the report artifact and fix.") | |
found_error = True | |
if found_error: | |
sys.exit(1) |