Skip to content
Merged
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
75 changes: 72 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,90 @@ on: [pull_request]
jobs:
build-test:
runs-on: ubuntu-latest
env:
KEYMANHOSTS_TIER: TIER_TEST
CONTAINER_DESC: api-keyman-com-app
CONTAINER_PORT: 8058

steps:
- name: Checkout
uses: actions/checkout@v6.0.2

# Build the docker image and create link to vendor/ dependencies
- name: Build the Docker image
shell: bash
run: |
echo "TIER_TEST" > tier.txt
./build.sh build start
./build.sh configure build start --debug
env:
fail-fast: true

- name: Run tests
#
# Run tests -- these step definitions are NEARLY identical across:
# help.keyman.com, keyman.com, keymanweb.com, api.keyman.com
#
# No differences on this site
#
- name: Test setup
shell: bash
run: |
./build.sh test
source ./_common/tests.inc.sh
set -e
do_test_record_start_time
echo "TEST_START_TIME=${TEST_START_TIME}" >> "$GITHUB_ENV"

- name: PHP test
if: ${{ !cancelled() }}
shell: bash
run: |
source ./_common/tests.inc.sh
set -e
do_test_unit_tests "$CONTAINER_DESC"

- name: Lint
if: ${{ !cancelled() }}
shell: bash
run: |
source ./_common/tests.inc.sh
set -e
do_test_lint "$CONTAINER_DESC"

- name: Check broken links
if: ${{ !cancelled() }}
shell: bash
run: |
source ./_common/tests.inc.sh
set -e
do_test_links "http://localhost:${CONTAINER_PORT}" /

# We split the reporting of broken links into a separate step for ease of
# viewing because the broken links are otherwise hidden in a sea of good
# links in a very long report

- name: Report on broken links
if: ${{ !cancelled() }}
run: |
source ./_common/tests.inc.sh
set -e
do_test_print_link_report

- name: Check PHP errors
if: ${{ !cancelled() }}
shell: bash
run: |
source ./_common/tests.inc.sh
set -e
do_test_print_container_error_logs "$CONTAINER_DESC"

- name: Verify .bootstrap-required-version
if: ${{ !cancelled() }}
shell: bash
run: |
# We want to avoid merging a bootstrap version that is not based on a published tag
# in the shared-sites repo. We will do this with a heuristic based on the normal
# shape of the tags, which is `v#.#.#`. Any other shape we will assume is a test
# branch.
cat resources/.bootstrap-required-version | grep -qP '^v\d+\.\d+\.\d+$' || (
echo "::error file=resources/.bootstrap-required-version,line=1,col=1::This branch cannot be merged, because resources/.bootstrap-required-version references \`$(cat resources/.bootstrap-required-version)\`, which does not appear to be a published tag -- is it a test branch?"
exit 1
)
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ vendor*
/node_modules/
.vscode/

linkinator-results.json

# Shared files are bootstrapped:
resources/bootstrap.inc.sh
resources/.bootstrap-version
Expand Down
42 changes: 12 additions & 30 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
## START STANDARD SITE BUILD SCRIPT INCLUDE
readonly THIS_SCRIPT="$(readlink -f "${BASH_SOURCE[0]}")"
readonly BOOTSTRAP="$(dirname "$THIS_SCRIPT")/resources/bootstrap.inc.sh"
readonly BOOTSTRAP_VERSION=v1.0.14
BOOTSTRAP_VERSION="$(cat "$(dirname "THIS_SCRIPT")/resources/.bootstrap-required-version")" || exit 1
readonly BOOTSTRAP_VERSION
if ! [ -f "$BOOTSTRAP" ] || ! source "$BOOTSTRAP"; then
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
source "$BOOTSTRAP.tmp"
Expand Down Expand Up @@ -32,6 +33,7 @@ builder_describe \
"start" \
"stop" \
"test" \
"info" \
"--rebuild-test-fixtures Rebuild the test fixtures from live data" \
"--no-unit-test" \
"--no-lint" \
Expand All @@ -41,34 +43,6 @@ builder_describe \

builder_parse "$@"

function test_docker_container() {
echo "TIER_TEST" > tier.txt
# Note: ci.yml replicates these

if builder_has_option --rebuild-test-fixtures; then
touch rebuild-test-fixtures.txt
fi

if ! builder_has_option --no-unit-test; then
# Run unit tests
# shellcheck disable=SC2154
docker exec $API_KEYMAN_CONTAINER_DESC sh -c "vendor/bin/phpunit --testdox ${builder_extra_params[*]}"
fi

if ! builder_has_option --no-lint; then
# Lint .php files for obvious errors
docker exec $API_KEYMAN_CONTAINER_DESC sh -c "find . -name '*.php' | grep -v '/vendor/' | xargs -n 1 -d '\\n' php -l"
fi

if ! builder_has_option --no-link-check; then
# Check all internal links
# NOTE: link checker runs on host rather than in docker image
npx broken-link-checker http://localhost:8058 --ordered --recursive --host-requests 10 -e --filter-level 3
fi

rm tier.txt
}

builder_run_action configure bootstrap_configure

builder_run_action clean:db clean_docker_container $API_KEYMAN_DB_IMAGE_NAME $API_KEYMAN_DB_CONTAINER_NAME
Expand Down Expand Up @@ -203,4 +177,12 @@ function start_docker_container_app() {
builder_run_action start:db start_docker_container_db $API_KEYMAN_DB_IMAGE_NAME $API_KEYMAN_DB_CONTAINER_NAME $API_KEYMAN_DB_CONTAINER_DESC $PORT_API_KEYMAN_COM_DB
builder_run_action start:app start_docker_container_app $API_KEYMAN_IMAGE_NAME $API_KEYMAN_CONTAINER_NAME $API_KEYMAN_CONTAINER_DESC $HOST_API_KEYMAN_COM $PORT_API_KEYMAN_COM

builder_run_action test:app test_docker_container
builder_run_action test:app test_docker_container $API_KEYMAN_CONTAINER_DESC $PORT_API_KEYMAN_COM /

do_info() {
echo "BUILDER_TIER: $BUILDER_TIER"
echo "KEYMAN_VERSION_ENVIRONMENT: $KEYMAN_VERSION_ENVIRONMENT"
}

builder_run_action info do_info

1 change: 1 addition & 0 deletions resources/.bootstrap-required-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v1.0.14