-
-
Notifications
You must be signed in to change notification settings - Fork 2
feat: shared site testing script and move to linkinator #97
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,3 +20,4 @@ KeymanHosts.php | |
| KeymanSentry.php | ||
| KeymanVersion.php | ||
| MarkdownHost.php | ||
| tests.inc.sh | ||
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,94 @@ | ||||||||
| # shellcheck shell=bash | ||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
| # | ||||||||
| # Keyman is copyright (C) SIL Global. MIT License. | ||||||||
| # | ||||||||
| # Shared test functions for PHP lint, unit test, and general broken link checks | ||||||||
| # | ||||||||
|
|
||||||||
| # Record the start time for unit tests for later log review | ||||||||
| function do_test_record_start_time() { | ||||||||
| TEST_START_TIME=$(date -Is -u) | ||||||||
| } | ||||||||
|
|
||||||||
| # Run unit tests through phpunit | ||||||||
| # | ||||||||
| # Parameters | ||||||||
| # 1: CONTAINER container_desc to run on | ||||||||
| # | ||||||||
| function do_test_unit_tests() { | ||||||||
| local CONTAINER="$1" | ||||||||
| docker exec "${CONTAINER}" sh -c "vendor/bin/phpunit --testdox ${builder_extra_params[*]}" | ||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think we can use |
||||||||
| } | ||||||||
|
|
||||||||
| # Lint .php files for obvious errors | ||||||||
| # | ||||||||
| # Parameters | ||||||||
| # 1: CONTAINER container_desc to run on | ||||||||
| # | ||||||||
| function do_test_lint() { | ||||||||
| local CONTAINER="$1" | ||||||||
| docker exec "${CONTAINER}" sh -c "find . -name '*.php' | grep -v '/vendor/' | xargs -n 1 -d '\\n' php -l" | ||||||||
| } | ||||||||
|
|
||||||||
| ## Check links on live local server using linkinator | ||||||||
| # | ||||||||
| # Parameters | ||||||||
| # 1: baseURL the top level URL for the site | ||||||||
| # 2: testPath path under baseURL to start testing, e.g. / | ||||||||
| # 3[,4..]: skipPaths list of paths (under baseURL) to skip crawling, optional | ||||||||
| # | ||||||||
| function do_test_links() { | ||||||||
| local baseURL="$1" | ||||||||
| local testPath="$2" | ||||||||
| shift 2 | ||||||||
| local skipPaths=("$@") | ||||||||
| local skip skipParams=() | ||||||||
|
|
||||||||
| for skip in "${skipPaths[@]}"; do | ||||||||
| skipParams+=(--skip "^${baseURL}${skip}") | ||||||||
| done | ||||||||
|
|
||||||||
| npx https://github.com/keymanapp/linkinator \ | ||||||||
| "${baseURL}${testPath}" \ | ||||||||
| --clean-urls \ | ||||||||
| --concurrency 50 \ | ||||||||
| --format json \ | ||||||||
| --output-filename linkinator-results.json \ | ||||||||
| --skip "^(?!${baseURL})" \ | ||||||||
| "${skipParams[@]}" \ | ||||||||
| --recurse \ | ||||||||
| --redirects verify \ | ||||||||
| --retry-errors \ | ||||||||
| --root-path "${baseURL}" | ||||||||
| } | ||||||||
|
|
||||||||
| # Print summary of results from linkinator | ||||||||
| function do_test_print_link_report() { | ||||||||
| echo ---------------------------------------------------------------------- | ||||||||
| echo Link check summary | ||||||||
| echo ---------------------------------------------------------------------- | ||||||||
| # Emit full JSON detail for broken links (may not be necessary) | ||||||||
| jq '.links[] | select(.state != "OK")' < linkinator-results.json | ||||||||
| echo | ||||||||
| echo | ||||||||
| # Emit a summary report | ||||||||
| jq -r '.links[] | select(.state != "OK") | "\(.state)[\(.status)]: \(.parent) --> \(.url)"' < linkinator-results.json | ||||||||
| } | ||||||||
|
|
||||||||
| # Scan logs recorded on container since start of tests to find any reported PHP | ||||||||
| # errors (note, depends on '[php#:xxxx]' marker string, where # = 7 for PHP7, omitted for PHP8) | ||||||||
| # | ||||||||
| # Parameters | ||||||||
| # 1: CONTAINER container_desc to run on | ||||||||
| # | ||||||||
| function do_test_print_container_error_logs() { | ||||||||
| local CONTAINER="$1" | ||||||||
| if docker container logs "${CONTAINER}" --since "${TEST_START_TIME}" 2>&1 | grep -qP '\[php7?:(error|warn|notice)\]'; then | ||||||||
| echo 'PHP reported errors or warnings:' | ||||||||
| docker container logs "${CONTAINER}" --since "${TEST_START_TIME}" 2>&1 | grep -P '\[php7?:(error|warn|notice)\]' | ||||||||
| return 1 | ||||||||
| else | ||||||||
| echo 'No PHP errors found' | ||||||||
| return 0 | ||||||||
| fi | ||||||||
| } | ||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the purpose of
tier.txt?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is used to specify the tier across server and script contexts consistently (as env vars may not be available in http server context). See:
shared-sites/bootstrap.inc.sh
Lines 209 to 216 in 5ac4983
shared-sites/_common/KeymanHosts.php
Lines 128 to 136 in 2c8091d