Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CI: verify docs resources #235

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions .github/workflows/deploy-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,29 @@ jobs:
run: echo "##[set-output name=flag;]$([[ \"${GITHUB_REF#refs/heads/}\" == \"master\" ]] && echo \"--prod\" || true)"

- name: Deploy docs
id: deploy
uses: netlify/actions/cli@master
with:
args: deploy --dir='apps/govuk-docs/.netlify/publish/' --functions='apps/govuk-docs/.netlify/functions/' ${{ steps.target.outputs.flag }}
env:
NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }}
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}

- name: Scan docs links
id: linkscan
uses: JustinBeckwith/linkinator-action@v1
with:
config: apps/govuk-docs/linkinator.config.json
paths: ${{ steps.deploy.outputs.NETLIFY_URL }}

- name: Check docs scan results
uses: r26d/jq-action@master
env:
SELECTOR: '.links | .[] | select(.state | contains("BROKEN"))'
TEMPLATE: '.state, " link [", .status, "] in page ", .parent, ", for target: ", .url, "\n"'
OUTCOME: '.passed | "Links and assets verified: ", .'
with:
cmd: |
cd apps/govuk-docs/
echo "${{ steps.linkscan.outputs.value }}" \
| jq -jre "( ${{ env.SELECTOR }} | ${{ env.TEMPLATE }} ), ( ${{ env.OUTCOME }} )"
28 changes: 28 additions & 0 deletions apps/govuk-docs/check-links.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/bash +x
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we still need the +x?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it better to do #! /bin/env bash these days?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question! Not really a short answer, but I think it boils down to using /bin/env is more portable but slightly less secure. I don't think either is a strong enough consideration to influence this context though.


set -e
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-euo pipefail?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh maybe not, you disable this later.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, there's more than one thing running here, so the exit code needs to be set after clean-up, and reflect the outcome of the test process.

SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
cd "${SCRIPT_DIR}"

[ -d node_modules ] && [ -f dist/server/index.js ] || make deps build > /dev/null
set +e
npm run ssr > /dev/null &
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dev:ssr?

Or even SSR_ONLY=true npm start?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I see, you added a script for this.

server=$!

selector='.links | .[] | select(.state | contains("BROKEN"))'
template='.state, " link [", .status, "] in page ", .parent, ", for target: ", .url, "\n"'
outcome='.passed | "Links and assets verified: ", .'
curl -fs \
--retry 15 \
--retry-delay 2 \
--retry-max-time 30 \
--retry-connrefused \
http://localhost:8080/ > /dev/null && \
linkinator http://localhost:8080 \
--verbosity warning \
--config ./linkinator.config.json \
| jq -jre "( ${selector} | ${template} ), ( ${outcome} )"
result=$?
echo
kill $server
exit $result
6 changes: 6 additions & 0 deletions apps/govuk-docs/linkinator.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"format": "json",
"recurse": true,
"verbosity": "info",
"timeout": 10000
}
6 changes: 4 additions & 2 deletions apps/govuk-docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@
"main": "dist/server/index.js",
"scripts": {
"start": "node .",
"test": "echo \"Error: no test specified\" && exit 1",
"test": "exec ./check-links.sh",
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the exec?

"build": "webpack",
"package:serverless": "sls package",
"clean": "rm -rf .serverless dist",
"dev": "NODE_ENV=development node-hot --fork | bunyan",
"dev:ssr": "NODE_ENV=development SSR_ONLY=true node-hot --fork | bunyan"
"dev:ssr": "NODE_ENV=development SSR_ONLY=true node-hot --fork | bunyan",
"ssr": "NODE_ENV=production SSR_ONLY=true exec node ."
},
"author": "Daniel A.C. Martin <[email protected]> (http://daniel-martin.co.uk/)",
"license": "MIT",
Expand All @@ -30,6 +31,7 @@
"@types/react-router-dom": "^5.1.5",
"@types/webpack-env": "^1.15.2",
"bunyan": "^1.8.12",
"linkinator": "^2.13.6",
"node-hot-loader": "^1.19.0",
"react": "^16.9.55",
"react-dom": "^16.9.55",
Expand Down
Loading