link-check-git-diff v0.0.12
Link Check
This project is a small CI tool built for the DVC website that checks the current HEAD's diff compared to origin/master, and then sends a request to each one to make sure the links are valid.
The base library has two frontends compiled with Rollup: a GitHub Actions driver and a CLI driver.
GitHub Actions
Since GitHub actions code is delivered through git repos, this repo uses Git Submodules to minimize the required payload of cloning the precompiled JS blob.
You can use yarn build
to compile the sources, then cd
into action
to push
to the production repo to update the dist repo.
The action takes the following options:
rootURL
The URL that root-relative links will have prepended.
Use an interpolation from the GitHub Actions payload to get the URL of your deploy preview.
exclusionFile
A path to a file in the repo that contains links to be excluded from the check. Each line is read in as a micromatch string, and any link that matches any line will be noted as excluded in the report.
fileFilter
If set to a string, files will be filtered using the string as a micromatch matcher.
CLI
The CLI runner is provided through this project's NPM package.
To use the CLI runner, install link-check-git-diff
and then invoke
the link-check-git-diff
binary.
yarn add -D link-check-git-diff
yarn run link-check-git-diff
The CLI runner takes the following environment variables for config:
It also calls dotenv
, so that can be used for developer convenience.
LINK_CHECK_ROOT_URL
The URL that root-relative links will have prepended.
LINK_CHECK_EXCLUSION_FILE
A path to a file in the repo that contains links to be excluded from the check. Each line is read in as a micromatch string, and any link that matches any line will be noted as excluded in the report.
LINK_CHECK_FILE_FILTER
If set to a string, files will be filtered using the string as a micromatch matcher.
LINK_CHECK_FAILURE_EXIT_CODE
If set to anything truthy, the CLI script will exit with code 1 if any of the link checks fail. Only relevant for CI for the most part.
Contributing
About submodules
Okay, I know what you're thinking, but I swear this is one of the rare decent use-cases!
GitHub Actions is kind of like AWS Lambda and its cousins in that all the JS has to be in one bundle, including dependencies.
Unlike most Lambdas, GitHub actions are uploaded and deployed through GitHub repos.
In this case, I'm trading some complexity on the commit/deploy for the ability to send just what is needed to the action, which is a best practice for any Lambda-like thing. The source is useless without either bundling or checking in node_modules, so I figure this is the least of all evils.
Anyway, here's how to commit to this repo and deploy to prod:
How to push to both source and action
git pull --recurse-submodules
if you haven't already.yarn build
with your required changes either staged or committed.commit all changes in the submodule repo in the
action
subdirectory.commit all changes in this source repo, including the changed submodule commit.
git push --recurse-submodules=on-demand
in the source repo to push both repos.yarn publish
to update the NPM package with the CLI binary, if necessary (this has nothing to do with submodules)