diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d667f84..868fe2e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -17,30 +17,9 @@ jobs: runs-on: ubuntu-latest steps: - - name: Install just - run: | - curl --proto '=https' \ - --tlsv1.2 -sSf https://just.systems/install.sh | bash -s -- --to /usr/local/bin - - name: Checkout the code uses: actions/checkout@5a4ac9002d0be2fb38bd78e4b4dbde5606d7042f # v2.3.4 - name: Build and test run: | - docker compose version - - docker network create traefik_proxy - - cp --no-clobber .env.example .env - - docker compose build --progress plain - - docker compose up --detach - docker compose logs - - just composer install --quiet --no-progress - - just test --testdox --colors=always - - just _run php phpcs - just _run php phpstan analyze --no-progress --memory-limit=512M \ No newline at end of file + ./run ci:test diff --git a/.gitignore b/.gitignore index 3782cca..6227464 100644 --- a/.gitignore +++ b/.gitignore @@ -34,3 +34,6 @@ web/themes/README.txt web/themes/contrib/ web/update.php web/web.config + +# Docker +/docker-compose.override.yml diff --git a/justfile b/justfile deleted file mode 100644 index 824ebf5..0000000 --- a/justfile +++ /dev/null @@ -1,66 +0,0 @@ -# Do not edit this file. It is automatically generated by https://www.oliverdavies.uk/build-configs. - -default: - @just --list - -# Start the project -start: - cp -v --no-clobber .env.example .env - docker compose up -d - -# Stop the project -stop: - docker compose down - -composer *args: - just _exec php composer {{ args }} - -alias phpunit := test - -test *args: - just _exec php phpunit --colors=always {{ args }} - -drush *args: - just _exec php drush {{ args }} - -install *args: - just _exec php drush site:install -y {{ args }} - -# Enable or disable Git hooks -git-hooks command: - #!/usr/bin/env bash - set -euo pipefail - - case "{{ command }}" in - "on") - echo "Enabling Git hooks..." - git config core.hooksPath .githooks - ;; - "off") - echo "Disabling Git hooks..." - git config --unset core.hooksPath - ;; - *) - echo "Error: Invalid argument. Must be either 'on' or 'off'" - ;; - esac - -test-commit: - just _run php phpcs - just _run php phpstan analyze --no-progress --memory-limit=512M - - just test --testdox --testsuite unit - just test --testdox --testsuite kernel - -_exec +args: - docker compose exec -T {{ args }} - -_run service command *args: - docker compose run \ - --entrypoint {{ command }} \ - --no-deps \ - --rm \ - -T \ - {{ service }} {{ args }} - -# vim: ft=just diff --git a/run b/run new file mode 100755 index 0000000..642e8a1 --- /dev/null +++ b/run @@ -0,0 +1,118 @@ +#!/usr/bin/env bash + +# Do not edit this file. It is automatically generated by https://www.oliverdavies.uk/build-configs. + +set -eu + +# Run automated tests as part of the Continuous Integration (CI) pipeline. +function ci:test { + lint:dockerfile + + docker compose version + + docker network create traefik_proxy + + cp --no-clobber .env.example .env + + docker compose build --progress plain + + docker compose up --detach + docker compose logs + + composer install --quiet --no-progress + + test --testdox + + quality +} + +# Run a command within the php container. +function cmd { + docker compose exec php "${@}" +} + +function coding-standards { + cmd phpcs "${@}" +} + +function composer { + _exec php composer "${@}" +} + +function drush { + _exec php drush "${@}" +} + +function git-hooks:off { + git config --unset core.hooksPath +} + +function git-hooks:on { + git config core.hooksPath .githooks +} + +# Display a list of all available commands. +function help { + printf "%s [args]\n\nTasks:\n" "${0}" + + compgen -A function | grep -v "^_" | cat -n + + printf "\nExtended help:\n Each task has comments for general usage\n" +} + +function lint:dockerfile { + docker container run --rm -i \ + hadolint/hadolint hadolint --ignore DL3008 --ignore DL3059 -t style "${@}" - < Dockerfile +} + +function quality { + coding-standards + static-analysis +} + +function start { + cp -v --no-clobber .env.example .env + + docker compose up -d +} + +function static-analysis { + cmd phpstan --memory-limit=-1 --no-progress "${@}" +} + +function stop { + docker compose down +} + +function test { + _exec php phpunit --colors=always "${@}" +} + +function test:commit { + test --testdox --testsuite functional + test --testdox --testsuite kernel + test --testdox --testsuite unit + + quality +} + +function _exec { + docker compose exec -T "${@}" +} + +function _run { + local service="${1}" + local command="${2}" + + docker compose run \ + --entrypoint "${command}" \ + --no-deps \ + --rm \ + -T \ + "${service}" "${@}" +} + +TIMEFORMAT=$'\nTask completed in %3lR' +time "${@:-help}" + +# vim: ft=bash