From a11eda5bcb93501664cd811dd199eeacbab644d6 Mon Sep 17 00:00:00 2001 From: Nate W Date: Wed, 21 Aug 2024 18:14:44 -0700 Subject: [PATCH] Adding link checking GitHub workflow Signed-off-by: Nate W --- .github/workflows/check-links.yml | 30 ++++++++++++++++++++++++++++++ package.json | 18 ++++++++++-------- 2 files changed, 40 insertions(+), 8 deletions(-) create mode 100644 .github/workflows/check-links.yml diff --git a/.github/workflows/check-links.yml b/.github/workflows/check-links.yml new file mode 100644 index 000000000..ce68764e9 --- /dev/null +++ b/.github/workflows/check-links.yml @@ -0,0 +1,30 @@ +# Adapted from @chalin's work on https://github.com/chalin/docsy-starter + +name: Links + +on: + merge_group: + pull_request: + push: { branches: [main] } + +jobs: + build-and-check-links: + name: BUILD and CHECK LINKS + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Create NPM cache-hash input file + run: | + mkdir -p tmp + jq '{devDependencies, engines, gitHubActionCacheKey}' package.json > tmp/package-ci.json + + - uses: actions/setup-node@v4 + with: + node-version-file: .nvmrc + cache: npm + cache-dependency-path: tmp/package-ci.json + + - run: npm install --omit=optional + + - run: npm run check:links diff --git a/package.json b/package.json index f84c65291..046234005 100644 --- a/package.json +++ b/package.json @@ -1,22 +1,24 @@ { "scripts": { "_build": "hugo --cleanDestinationDir -e dev -DFE", - "_check-links": "make check-links", + "__check:links": "make --keep-going check-links", + "_check:links": "HTMLTEST_ARGS='--log-level 1 --skip-external' npm run __check:links", + "_check:links--warn": "npm run _check:links || (echo; echo 'WARNING: see link-checker output for issues.'; echo)", "_serve:hugo": "hugo serve -DFE --minify", "_serve": "netlify dev -c \"npm run _serve:hugo\" --framework hugo", "build:preview": "set -x && npm run _build -- --minify --baseURL \"${DEPLOY_PRIME_URL:-/}\"", "build:production": "hugo --cleanDestinationDir --minify", "build": "npm run _build", - "check-links:all": "HTMLTEST_ARGS= npm run _check-links", - "check-links": "npm run _check-links", + "check:links:all": "HTMLTEST_ARGS= npm run _check:links", + "check:links": "npm run _check:links", "clean": "make clean", - "postbuild:preview": "npm run _check-links", - "postbuild:production": "npm run _check-links", - "precheck-links:all": "npm run build", - "precheck-links": "npm run build", + "postbuild:preview": "npm run _check:links--warn", + "postbuild:production": "npm run _check:links--warn", + "precheck:links:all": "npm run build", + "precheck:links": "npm run build", "serve:hugo": "npm run _serve:hugo", "serve": "npm run _serve", - "test": "npm run check-links" + "test": "npm run check:links" }, "devDependencies": { "bulma": "^0.8.2",