Skip to content

Commit

Permalink
Rewrite link check script in Python
Browse files Browse the repository at this point in the history
  • Loading branch information
marians committed Dec 9, 2024
1 parent 2de9e29 commit c35b4f7
Showing 1 changed file with 42 additions and 108 deletions.
150 changes: 42 additions & 108 deletions .github/workflows/check-links-in-prod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,92 +20,40 @@ jobs:
chmod 777 output
- name: check-links-in-overview-pages
run: |
docker run --rm --name linkchecker \
--volume ${PWD}/output:/workdir --workdir /workdir \
ghcr.io/linkchecker/linkchecker:latest \
https://docs.giantswarm.io/overview/ \
--check-extern \
--threads 1 \
--recursion-level 2 \
--no-status \
--file-output html/utf8/overview.html \
|| echo "failed1=true" >> "$GITHUB_ENV"
shell: python {0}
continue-on-error: true

- name: check-links-in-getting-started-pages
run: |
docker run --rm --name linkchecker \
--volume ${PWD}/output:/workdir --workdir /workdir \
ghcr.io/linkchecker/linkchecker:latest \
https://docs.giantswarm.io/getting-started/ \
--check-extern \
--threads 1 \
--recursion-level 2 \
--no-status \
--file-output html/utf8/getting-started.html \
|| echo "failed2=true" >> "$GITHUB_ENV"
continue-on-error: true
# The different sections we are going to check
sections = [
'getting-started',
'overview',
'reference',
'support',
'tutorials',
]
- name: check-links-in-tutorials-pages
run: |
docker run --rm --name linkchecker \
--volume ${PWD}/output:/workdir --workdir /workdir \
ghcr.io/linkchecker/linkchecker:latest \
https://docs.giantswarm.io/tutorials/ \
--check-extern \
--threads 1 \
--recursion-level 2 \
--no-status \
--file-output html/utf8/tutorials.html \
|| echo "failed3=true" >> "$GITHUB_ENV"
continue-on-error: true
import os
import subprocess
- name: check-links-in-reference-pages
run: |
docker run --rm --name linkchecker \
--volume ${PWD}/output:/workdir --workdir /workdir \
ghcr.io/linkchecker/linkchecker:latest \
https://docs.giantswarm.io/reference/ \
--check-extern \
--threads 1 \
--recursion-level 2 \
--no-status \
--file-output html/utf8/reference.html \
|| echo "failed4=true" >> "$GITHUB_ENV"
continue-on-error: true
pwd = os.getcwd()
- name: check-links-in-support-pages
run: |
docker run --rm --name linkchecker \
--volume ${PWD}/output:/workdir --workdir /workdir \
ghcr.io/linkchecker/linkchecker:latest \
https://docs.giantswarm.io/support/ \
--check-extern \
--threads 1 \
--recursion-level 2 \
--no-status \
--file-output html/utf8/support.html \
|| echo "failed5=true" >> "$GITHUB_ENV"
continue-on-error: true

- name: check-links-in-changelogs
run: |
docker run --rm --name linkchecker \
--volume ${PWD}/output:/workdir --workdir /workdir \
ghcr.io/linkchecker/linkchecker:latest \
https://docs.giantswarm.io/changes/ \
--threads 1 \
--recursion-level 2 \
--no-status \
--file-output html/utf8/changes.html \
--ignore-url="^https://github.com/giantswarm/docs/.*" \
--ignore-url="^https://.*example\.com/.*" \
--ignore-url="^https://my-org\.github\.com/.*" \
--ignore-url="^https://github\.com/giantswarm/giantswarm/.*" \
--ignore-url=".*gigantic\.io.*" \
|| echo "failed6=true" >> "$GITHUB_ENV"
continue-on-error: true
for i, section in enumerate(sections):
# call docker run command
cmd = f"docker run --name linkchecker \
--volume {pwd}/output:/workdir --workdir /workdir \
ghcr.io/linkchecker/linkchecker:latest \
https://docs.giantswarm.io/{section}/ \
--check-extern \
--threads 1 \
--recursion-level 2 \
--no-status \
--file-output 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
Expand All @@ -116,31 +64,17 @@ jobs:
retention-days: 14

- name: Report errors
shell: python {0}
run: |
if [[ $failed1 == "true" ]]; then
echo "There has been some errors in overview checks, please check the step."
failed=true
fi
if [[ $failed2 == "true" ]]; then
echo "There has been some errors in getting started checks, please check the step."
failed=true
fi
if [[ $failed3 == "true" ]]; then
echo "There has been some errors in tutorials checks, please check the step."
failed=true
fi
if [[ $failed4 == "true" ]]; then
echo "There has been some errors in reference checks, please check the step."
failed=true
fi
if [[ $failed5 == "true" ]]; then
echo "There has been some errors in support checks, please check the step."
failed=true
fi
if [[ $failed6 == "true" ]]; then
echo "There has been some errors in changelogs checks, please check the step."
failed=true
fi
if [[ $failed == "true" ]]; then
exit 1
fi
import sys
found_error = False
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)

0 comments on commit c35b4f7

Please sign in to comment.