Skip to content

Commit

Permalink
updating scripts based on PR feedback
Browse files Browse the repository at this point in the history
Signed-off-by: Nate W <[email protected]>
  • Loading branch information
nate-double-u committed Oct 18, 2024
1 parent 22070e6 commit 8bcca37
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 91 deletions.
56 changes: 5 additions & 51 deletions .github/workflows/check-links.yml
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -17,60 +17,14 @@ 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:
node-version-file: .nvmrc
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
18 changes: 15 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
23 changes: 10 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
24 changes: 0 additions & 24 deletions scripts/check-build-log.sh

This file was deleted.

0 comments on commit 8bcca37

Please sign in to comment.