diff --git a/.github/workflows/check-links.yml b/.github/workflows/check-links.yml index fc2c46e74..ce68764e9 100644 --- a/.github/workflows/check-links.yml +++ b/.github/workflows/check-links.yml @@ -1,11 +1,11 @@ -# Adapted from @chalin's work on opentelemetry.io -# https://github.com/open-telemetry/opentelemetry.io/blob/main/.github/workflows/check-links.yml +# 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: @@ -17,16 +17,7 @@ jobs: - name: Create NPM cache-hash input file run: | mkdir -p tmp - jq '{devDependencies, dependencies, engines, gitHubActionCacheKey}' package.json > tmp/package-ci.json - - - name: Create and use reduced-dependencies package.json - run: | - jq '.devDependencies |= with_entries( - select(.key | test("prefix|hugo|css")) - ) - | del(.dependencies, .optionalDependencies)' \ - package.json > tmp/package-min.json - cp tmp/package-min.json package.json + jq '{devDependencies, engines, gitHubActionCacheKey}' package.json > tmp/package-ci.json - uses: actions/setup-node@v4 with: @@ -34,43 +25,6 @@ jobs: cache: npm cache-dependency-path: tmp/package-ci.json - - run: | - npm install --omit=optional - npm run log:check:links - continue-on-error: true - - uses: actions/upload-artifact@v4 - with: - name: build-log-etc - path: | - tmp/build-log.txt - tmp/package*.json - static/refcache.json + - run: npm install --omit=optional - check-refcache: - name: REFCACHE updates? - needs: build-and-check-links - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - uses: actions/download-artifact@v4 - with: { name: build-log-etc } - - name: Fail when refcache contains entries with HTTP status 4XX - run: | - if grep -B 1 -e '"StatusCode": 4' static/refcache.json; then - echo "Run 'npx gulp prune' to remove 4xx entries from the refcache" - exit 1 - fi - - name: Does the refcache need updating? - run: npm run diff:fail - - check-build-log-for-issues: - name: WARNINGS in build log? - needs: build-and-check-links - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - uses: actions/download-artifact@v4 - with: { name: build-log-etc } - - run: | - cat tmp/build-log.txt - scripts/check-build-log.sh + - run: npm run check:links diff --git a/Makefile b/Makefile index 96b9e5430..7c64ddc8e 100644 --- a/Makefile +++ b/Makefile @@ -2,6 +2,9 @@ HTMLTEST_DIR=tmp HTMLTEST?=htmltest # Specify as make arg if different HTMLTEST_ARGS?=--skip-external +DOCS=public/docs +LATEST_VERSION=$(shell grep -e '^docs' config.toml | grep -oe '[0-9][0-9]*.[0-9]' | head -1) + # Use $(HTMLTEST) in PATH, if available; otherwise, we'll get a copy ifeq (, $(shell which $(HTMLTEST))) override HTMLTEST=$(HTMLTEST_DIR)/bin/htmltest @@ -10,13 +13,22 @@ GET_LINK_CHECKER_IF_NEEDED=get-link-checker endif endif -check-links: $(GET_LINK_CHECKER_IF_NEEDED) +check-links: $(GET_LINK_CHECKER_IF_NEEDED) make-redirects-for-checking $(HTMLTEST) $(HTMLTEST_ARGS) + find public/* -type l -ls -exec rm -f {} \; -clean: - rm -rf $(HTMLTEST_DIR) public/* resources +make-redirects-for-checking: + @if [ -z $(LATEST_VERSION) ]; then \ + echo "Failed to extract LATEST_VERSION. Cannot setup symlinks for checking"; \ + exit 1; \ + fi + @echo "Creating symlinks of 'latest' to $(LATEST_VERSION) for the purpose of link checking" + (cd public && rm -f scalers && ln -s docs/$(LATEST_VERSION)/scalers scalers) + (cd public/docs && rm -f latest && ln -s $(LATEST_VERSION) latest) get-link-checker: rm -Rf $(HTMLTEST_DIR)/bin curl https://htmltest.wjdp.uk | bash -s -- -b $(HTMLTEST_DIR)/bin +clean: + rm -rf $(HTMLTEST_DIR) public/* resources diff --git a/package.json b/package.json index 546401424..046234005 100644 --- a/package.json +++ b/package.json @@ -1,27 +1,24 @@ { "scripts": { "_build": "hugo --cleanDestinationDir -e dev -DFE", - "_check-links": "make check-links", - "_check-links--warn": "npm run _check-links || (echo; echo 'WARNING: see link-checker output for issues.'; echo)", - "_diff:check": "git diff --name-only --exit-code", + "__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", - "diff:check": "npm run _diff:check || (echo; echo 'WARNING: the files above have not been committed'; echo)", - "diff:fail": "npm run _diff:check || (echo; echo 'ERROR: the files above have changed. Locally rerun `npm run test-and-fix` and commit changes'; echo; exit 1)", - "log:check:links": "npm run _check-links--warn | tee tmp/build-log.txt", - "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", + "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", diff --git a/scripts/check-build-log.sh b/scripts/check-build-log.sh deleted file mode 100755 index 3dcb18ae3..000000000 --- a/scripts/check-build-log.sh +++ /dev/null @@ -1,24 +0,0 @@ -#!/bin/bash -# -# NOTE: add warning skip patterns, one per line to WARNINGS_SKIP_LIST to -# temporarily skip known warnings or errors. -# -# Adapted from @chalin & @cartermp's work in https://github.com/open-telemetry/opentelemetry.io/blob/main/scripts/check-build-log.sh - -BUILD_LOG=tmp/build-log.txt -WARNINGS_SKIP_LIST=.warnings-skip-list.txt - -WARNINGS=`grep -E -ie 'warn(ing)?|error' $BUILD_LOG | grep -v -f $WARNINGS_SKIP_LIST` - -if [ -e $BUILD_LOG ]; then - if [ -n "$WARNINGS" ]; then - echo "WARNINGs or ERRORs found in build log:" - echo "$WARNINGS" - echo - echo "INFO: if this is run in the context of a GitHub job, you can see" - echo " the full build log output from the previous step." - exit 1 - fi -else - echo "INFO: $BUILD_LOG file not found." -fi