Skip to content

Commit e206b09

Browse files
committed
chore: replace broken-link-checker with linkinator
Based-on: keymanapp/keyman.com#788
1 parent f73ae55 commit e206b09

3 files changed

Lines changed: 46 additions & 59 deletions

File tree

.github/workflows/ci.yml

Lines changed: 39 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ jobs:
88
runs-on: ubuntu-latest
99
env:
1010
KEYMANHOSTS_TIER: TIER_TEST
11+
CONTAINER_DESC: help-keyman-com-app
12+
CONTAINER_PORT: 8055
1113

1214
steps:
1315
- name: Checkout
@@ -23,45 +25,58 @@ jobs:
2325
fail-fast: true
2426

2527
#
26-
# Finally, run the tests; note that this is almost all replicated in build.sh; here logging is reduced (TODO sync)
28+
# Run tests -- these step definitions are NEARLY identical across:
29+
# help.keyman.com, keyman.com, keymanweb.com, api.keyman.com
2730
#
28-
- name: PHP unit tests
31+
# No differences on this site
32+
#
33+
- name: Test setup
2934
shell: bash
3035
run: |
31-
docker exec help-keyman-com-app sh -c "vendor/bin/phpunit --testdox"
36+
source ./_common/tests.inc.sh
37+
set -e
38+
do_test_record_start_time
39+
echo "TEST_START_TIME=${TEST_START_TIME}" >> "$GITHUB_ENV"
40+
41+
- name: PHP test
42+
if: ${{ !cancelled() }}
43+
shell: bash
44+
run: |
45+
source ./_common/tests.inc.sh
46+
set -e
47+
do_test_unit_tests "$CONTAINER_DESC"
3248
3349
- name: Lint
50+
if: ${{ !cancelled() }}
3451
shell: bash
3552
run: |
36-
( set +e; set +o pipefail; find . -name '*.php' | grep -v '/vendor/' | xargs -n 1 -d '\n' php -l | grep -v "No syntax errors detected"; exit ${PIPESTATUS[2]} )
53+
source ./_common/tests.inc.sh
54+
set -e
55+
do_test_lint "$CONTAINER_DESC"
3756
3857
- name: Check broken links
58+
if: ${{ !cancelled() }}
3959
shell: bash
40-
continue-on-error: false
4160
run: |
42-
set +e
43-
set +o pipefail
44-
npx broken-link-checker http://localhost:8055 --ordered --recursive --host-requests 50 -e --filter-level 3 | tee blc.log
45-
echo "BLC_RESULT=${PIPESTATUS[0]}" >> "$GITHUB_ENV"
61+
source ./_common/tests.inc.sh
62+
set -e
63+
do_test_links "http://localhost:${CONTAINER_PORT}" /
64+
65+
# We split the reporting of broken links into a separate step for ease of
66+
# viewing because the broken links are otherwise hidden in a sea of good
67+
# links in a very long report
4668

4769
- name: Report on broken links
70+
if: ${{ !cancelled() }}
4871
run: |
49-
set +e
50-
set +o pipefail
51-
cat blc.log | \
52-
grep -E "BROKEN|Getting links from" | \
53-
grep -B 1 "BROKEN";
54-
exit "${BLC_RESULT}"
72+
source ./_common/tests.inc.sh
73+
set -e
74+
do_test_print_link_report
5575
5676
- name: Check PHP errors
77+
if: ${{ !cancelled() }}
5778
shell: bash
5879
run: |
59-
CONTAINER=`docker container ls -l -q`
60-
if docker container logs $CONTAINER 2>&1 | grep -q 'php7'; then
61-
echo 'PHP reported errors or warnings:'
62-
docker container logs $CONTAINER 2>&1 | grep 'php7'
63-
exit 1
64-
else
65-
echo 'No PHP errors found'
66-
exit 0
67-
fi
80+
source ./_common/tests.inc.sh
81+
set -e
82+
do_test_print_container_error_logs "$CONTAINER_DESC"

.gitignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ cdn/deploy
66
tier.txt
77

88
# unit test artifacts
9-
blc.log
9+
linkinator-results.json
1010
.phpunit.result.cache
1111

1212
vendor*
@@ -24,4 +24,4 @@ _control/debug
2424

2525
# Cache of keyboard metadata, deleted on site rebuild
2626
keyboard/index.cache
27-
.phpunit.result.cache
27+
.phpunit.result.cache

build.sh

Lines changed: 5 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
## START STANDARD SITE BUILD SCRIPT INCLUDE
33
readonly THIS_SCRIPT="$(readlink -f "${BASH_SOURCE[0]}")"
44
readonly BOOTSTRAP="$(dirname "$THIS_SCRIPT")/resources/bootstrap.inc.sh"
5-
readonly BOOTSTRAP_VERSION=v1.0.13
5+
readonly BOOTSTRAP_VERSION=feat/linkinator-and-central-test-script
66
if ! [ -f "$BOOTSTRAP" ] || ! source "$BOOTSTRAP"; then
77
curl -H "Cache-Control: no-cache" --fail --silent --show-error -w "curl: Finished attempt to download %{url}" "https://raw.githubusercontent.com/keymanapp/shared-sites/$BOOTSTRAP_VERSION/bootstrap.inc.sh" -o "$BOOTSTRAP.tmp" || exit 1
88
source "$BOOTSTRAP.tmp"
@@ -29,44 +29,16 @@ builder_describe \
2929
start \
3030
stop \
3131
test \
32+
"--no-unit-test" \
33+
"--no-lint" \
34+
"--no-link-check"
3235

3336
builder_parse "$@"
3437

35-
function test_docker_container() {
36-
# Note: ci.yml replicates these
37-
38-
echo "TIER_TEST" > tier.txt
39-
set +e;
40-
set +o pipefail;
41-
42-
builder_echo blue "---- PHP unit tests"
43-
docker exec $HELP_CONTAINER_DESC sh -c "vendor/bin/phpunit --testdox"
44-
45-
# Lint .php files for obvious errors
46-
builder_echo blue "---- Lint PHP files"
47-
docker exec $HELP_CONTAINER_DESC sh -c "find . -name '*.php' | grep -v '/vendor/' | xargs -n 1 -d '\\n' php -l"
48-
49-
# Check all internal links
50-
# NOTE: link checker runs on host rather than in docker image
51-
builder_echo blue "---- Testing links"
52-
npx broken-link-checker http://localhost:8055 --recursive --ordered ---host-requests 50 -e --filter-level 3 | tee blc.log
53-
local BLC_RESULT=${PIPESTATUS[0]}
54-
echo ----------------------------------------------------------------------
55-
echo Link check summary
56-
echo ----------------------------------------------------------------------
57-
cat blc.log | \
58-
grep -E "BROKEN|Getting links from" | \
59-
grep -B 1 "BROKEN";
60-
61-
builder_echo blue "Done checking links"
62-
rm tier.txt
63-
return "${BLC_RESULT}"
64-
}
65-
6638
builder_run_action configure bootstrap_configure
6739
builder_run_action clean clean_docker_container $HELP_IMAGE_NAME $HELP_CONTAINER_NAME
6840
builder_run_action stop stop_docker_container $HELP_IMAGE_NAME $HELP_CONTAINER_NAME
6941
builder_run_action build build_docker_container $HELP_IMAGE_NAME $HELP_CONTAINER_NAME $BUILDER_CONFIGURATION
7042
builder_run_action start start_docker_container $HELP_IMAGE_NAME $HELP_CONTAINER_NAME $HELP_CONTAINER_DESC $HOST_HELP_KEYMAN_COM $PORT_HELP_KEYMAN_COM $BUILDER_CONFIGURATION
7143

72-
builder_run_action test test_docker_container
44+
builder_run_action test test_docker_container $HELP_CONTAINER_DESC $PORT_HELP_KEYMAN_COM /

0 commit comments

Comments
 (0)