From 7b793cefb1ddc735431ca5bee3b9464e19ab439b Mon Sep 17 00:00:00 2001 From: Wilken Rivera Date: Tue, 5 Jan 2021 10:18:51 -0500 Subject: [PATCH] Add GHA to check for broken links on pull-request - Add scheduled cron job for checking against master - Change configuration file path --- .github/workflows/linkchecker.yml | 14 ++++++++++++++ .github/workflows/scheduled-link-checker.yml | 14 ++++++++++++++ mlc_config.json | 15 +++++++++++++++ website/README.md | 13 ++++++++++++- 4 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/linkchecker.yml create mode 100644 .github/workflows/scheduled-link-checker.yml create mode 100644 mlc_config.json diff --git a/.github/workflows/linkchecker.yml b/.github/workflows/linkchecker.yml new file mode 100644 index 000000000..27ed60cee --- /dev/null +++ b/.github/workflows/linkchecker.yml @@ -0,0 +1,14 @@ +on: [pull_request] +name: Check Markdown links for modified files +jobs: + markdown-link-check: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@master + - uses: gaurav-nelson/github-action-markdown-link-check@v1 + with: + use-quiet-mode: 'yes' + file-extension: 'mdx' + check-modified-files-only: 'yes' + folder-path: 'website/content' + diff --git a/.github/workflows/scheduled-link-checker.yml b/.github/workflows/scheduled-link-checker.yml new file mode 100644 index 000000000..d626f67d2 --- /dev/null +++ b/.github/workflows/scheduled-link-checker.yml @@ -0,0 +1,14 @@ +on: + schedule: + - cron: "45 0 * * *" +name: Check Markdown links on main branch +jobs: + markdown-link-check: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@master + - uses: gaurav-nelson/github-action-markdown-link-check@v1 + with: + use-quiet-mode: 'yes' + file-extension: 'mdx' + folder-path: 'website/content' diff --git a/mlc_config.json b/mlc_config.json new file mode 100644 index 000000000..ec22c5470 --- /dev/null +++ b/mlc_config.json @@ -0,0 +1,15 @@ +{ + "ignorePatterns": [ + { + "pattern": "^https://github.com/hashicorp/packer-plugin-scaffolding" + } + ], + "replacementPatterns": [ + { + "pattern": "^/", + "replacement": "https://packer.io/" + } + ], + "timeout": "20s", + "retryOn429": true +} diff --git a/website/README.md b/website/README.md index 152cd5ee1..a130d3882 100644 --- a/website/README.md +++ b/website/README.md @@ -20,6 +20,7 @@ This subdirectory contains the entire source for the [Packer Website](https://pa - [Editing Markdown Content](#editing-markdown-content) - [Editing Navigation Sidebars](#editing-navigation-sidebars) - [Changing the Release Version](#changing-the-release-version) +- [Link Validation](#link-validation) - [Redirects](#redirects) - [Browser Support](#browser-support) - [Deployment](#deployment) @@ -148,7 +149,7 @@ $ curl ... -Contined normal markdown content +Continued normal markdown content ```` The intentionally skipped line is a limitation of the mdx parser which is being actively worked on. All tabs must have a heading, and there is no limit to the number of tabs, though it is recommended to go for a maximum of three or four. @@ -376,6 +377,16 @@ You may customize the parameters in any way you'd like. To remove a prerelease f +## Link Validation + +The Packer GitHub repository is configured to run a [Markdown Link Check](https://github.com/gaurav-nelson/github-action-markdown-link-check#github-action---markdown-link-check-%EF%B8%8F) on a nightly basis to check for potential broken links within the Packer documentation. There is also a GitHub action that will check any modified `.mdx` files on new pull-requests. + +The master configuration file for the markdown-link-checker is called `mlc_config.json` and is located under the project's root directory. +The configuration helps with relative links in the documentation that will be valid once deployed, and configures a few ignored URLs which are valid but may not return a valid 200 HTTP response code due to permissions or DDoS protection settings on the domain. + +**Potential False Positives** +The link checker will prepend the BASEURL `https://packer.io/` to any relative links found within the documentation, which can be an issue when adding new `/docs` or `/guides` documents as the pages have not been deployed. To help mitigate this issue check the site preview to ensure newly added documentation pages work as expected. + ## Redirects This website structures URLs based on the filesystem layout. This means that if a file is moved, removed, or a folder is re-organized, links will break. If a path change is necessary, it can be mitigated using redirects.