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

UHF-11137: Run CI pipelines using Docker compose setup #1613

Merged
merged 7 commits into from
Dec 16, 2024
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
2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ COMPOSE_PROJECT_NAME=hel-fi-drupal-grant-applications
DRUPAL_HOSTNAME=hel-fi-drupal-grant-applications.docker.so

# Docker image
DRUPAL_IMAGE=ghcr.io/city-of-helsinki/drupal-web:8.2
DRUPAL_IMAGE=ghcr.io/city-of-helsinki/drupal-web:8.3

# Default source @alias where to sync database and files from
DRUPAL_SYNC_SOURCE=main
Expand Down
38 changes: 19 additions & 19 deletions .github/workflows/artifact.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,32 @@ name: Build artifacts
jobs:
build:
runs-on: ubuntu-latest
container:
image: ghcr.io/city-of-helsinki/drupal-php-docker:8.3-alpine

services:
db:
image: mysql:8
env:
MYSQL_USER: drupal
MYSQL_PASSWORD: drupal
MYSQL_DATABASE: drupal
MYSQL_ROOT_PASSWORD: drupal
ports:
- 3306:3306

steps:
- uses: actions/checkout@v4

- name: Install and start Stonehenge
run: |
git clone -b 5.x https://github.com/druidfi/stonehenge.git ~/stonehenge
cd ~/stonehenge && make up

# This must be done after we start Stonehenge.
- name: Setup Docker compose environment variables
run: |
echo "COMPOSE_FILE=compose.yaml:compose.ci.yaml" >> $GITHUB_ENV

- name: Start project
run: make up

- name: Build project
run: composer install --no-interaction
run: docker compose exec app bash -c "composer install --no-interaction"

- name: Setup drupal and save database dump
run: |
drush si -y && drush cr
drush si --existing-config -y
drush cim -y
drush sql-dump --result-file=${GITHUB_WORKSPACE}/latest.sql
docker compose exec app bash -c "drush si -y && drush cr"
docker compose exec app bash -c "drush si --existing-config -y"
docker compose exec app bash -c "drush cr"
docker compose exec app bash -c "drush cim -y"
docker compose exec app bash -c "drush sql-dump --result-file=/app/latest.sql"

- name: Upload latest database dump
uses: actions/upload-artifact@v4
Expand Down
70 changes: 32 additions & 38 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,12 @@ on:
push:
branches: ['main', 'dev']
name: CI
env:
SYMFONY_DEPRECATIONS_HELPER: disabled
SIMPLETEST_BASE_URL: http://app:8888
jobs:
tests:
runs-on: ubuntu-latest
container:
image: ghcr.io/city-of-helsinki/drupal-php-docker:8.3-alpine
options: --hostname app

services:
db:
image: mysql:8
env:
MYSQL_USER: drupal
MYSQL_PASSWORD: drupal
MYSQL_DATABASE: drupal
MYSQL_ROOT_PASSWORD: drupal
ports:
- 3306:3306
steps:
- uses: actions/checkout@v4

- name: Set browsertest output folder
run: |
echo "BROWSERTEST_OUTPUT_DIRECTORY=$GITHUB_WORKSPACE/public/sites/simpletest" >> $GITHUB_ENV

# TODO this does not pass
#- name: Make sure configuration was exported in correct language (en or und)
# run: |
Expand All @@ -41,22 +20,36 @@ jobs:
# exit 1
# fi

- name: Install and start Stonehenge
run: |
git clone -b 5.x https://github.com/druidfi/stonehenge.git ~/stonehenge
cd ~/stonehenge && make up

# This must be done after we start Stonehenge.
- name: Setup Docker compose environment variables
run: |
echo "COMPOSE_FILE=compose.yaml:compose.ci.yaml" >> $GITHUB_ENV
echo "COMPOSE_PROFILES=" >> $GITHUB_ENV

- name: Start project
run: make up

- name: Build project
run: composer install --no-interaction
run: docker compose exec app bash -c "composer install --no-interaction"

- name: Scan security updates
run: composer audit
run: docker compose exec app bash -c "composer audit"

- name: Check that subtheme is not built with dev mode
run: if grep -q 'sourceMappingURL=' -R public/themes/custom/hdbt_subtheme/dist/css; then exit 1; fi
run: docker compose exec app bash -c "if grep -q 'sourceMappingURL=' -R public/themes/custom/hdbt_subtheme/dist/css; then exit 1; fi"

- name: Run PHPCS
run: |
vendor/bin/phpcs public/modules/custom/
vendor/bin/phpcs public/themes/custom/
docker compose exec app bash -c "vendor/bin/phpcs public/modules/custom/"
docker compose exec app bash -c "vendor/bin/phpcs public/themes/custom/"

- name: Run phpstan
run: vendor/bin/phpstan analyze
run: docker compose exec app bash -c "vendor/bin/phpstan analyze"

- name: Download latest dump
env:
Expand All @@ -65,25 +58,26 @@ jobs:

- name: Install Drupal
run: |
mysql --user=drupal --password=drupal --database=drupal --host=db --port=3306 -A < latest.sql
drush deploy
docker compose exec app bash -c "mysql --user=drupal --password=drupal --database=drupal --host=db --port=3306 -A < latest.sql"
docker compose exec app bash -c "drush deploy"

- name: Start services
- name: Run PHPUnit tests
run: |
drush runserver $SIMPLETEST_BASE_URL --dns > /dev/null 2>&1 &
docker compose exec app bash -c "mkdir -p /app/results"

# Wait for drush server to start.
for i in {1..5}; do RESPONSE_CODE=$(curl -s -o /dev/null -w "%{http_code}" "$SIMPLETEST_BASE_URL" || true); if [ "$RESPONSE_CODE" -gt "301" ] || [ "$RESPONSE_CODE" -lt "200" ]; then sleep 2; fi; done
if [ -d "tests/" ]; then
docker compose exec app bash -c "composer test-php tests/"
fi
docker compose exec app bash -c "composer test-php public/modules/custom"

- name: Run PHPUnit tests
run: |
composer test-php public/modules/custom
if [ -d "tests/" ]; then composer test-php tests/; else echo "No DTT tests found. Ignoring..."; fi
- name: Export logs
if: always()
run: docker compose logs app > results/service.log

- name: Create an artifact from test report
uses: actions/upload-artifact@v4
if: always()
with:
name: results
path: ${{ env.BROWSERTEST_OUTPUT_DIRECTORY }}
path: results/
retention-days: 1
3 changes: 2 additions & 1 deletion .github/workflows/update-config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ jobs:
update-config:
runs-on: ubuntu-latest
container:
image: ghcr.io/city-of-helsinki/drupal-php-docker:8.3-alpine
image: ghcr.io/city-of-helsinki/drupal-web:8.3
options: --hostname app --user 1001
services:
db:
image: mysql:8
Expand Down
38 changes: 19 additions & 19 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 3 additions & 4 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,11 @@
<ini name="error_reporting" value="32767"/>
<!-- Do not limit the amount of memory tests take to run. -->
<ini name="memory_limit" value="-1"/>
<env name="MINK_DRIVER_ARGS_WEBDRIVER" value='["chrome", {"browserName":"chrome","chromeOptions":{"w3c": false}}, "http://chromium:4444"]' />
<env name="DTT_MINK_DRIVER_ARGS" value='["chrome", {"chromeOptions":{"w3c": false }}, "http://chromium:4444"]'/>
<env name="MINK_DRIVER_ARGS_WEBDRIVER" value='["chrome", {"browserName":"chrome", "goog:chromeOptions":{"w3c": true, "args":["--no-sandbox", "--ignore-certificate-errors", "--allow-insecure-localhost", "--headless", "--dns-prefetch-disable"]}}, "http://chromium:4444"]' />
<env name="DTT_MINK_DRIVER_ARGS" value='["chrome", {"browserName":"chrome", "goog:chromeOptions":{"w3c": true, "args":["--no-sandbox","--ignore-certificate-errors", "--allow-insecure-localhost", "--headless", "--dns-prefetch-disable"]}}, "http://chromium:4444"]'/>
<env name="DTT_API_OPTIONS" value='{"socketTimeout": 360, "domWaitTimeout": 3600000}' />
<env name="DTT_API_URL" value="http://chromium:9222"/>
<env name="DTT_BASE_URL" value="http://app:8888"/>
</php>
<env name="DTT_BASE_URL" value="https://app"/></php>
<testsuites>
<testsuite name="unit">
<directory>./public/modules/custom/*/tests/src/Unit</directory>
Expand Down
2 changes: 1 addition & 1 deletion tools/make/project/git.mk
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
PHONY += copy-commit-message-script
copy-commit-message-script:
@$(foreach name,$(shell find public/modules/custom public/themes/custom public/modules/contrib public/themes/contrib -type d -name ".git" -exec dirname {} \; 2> /dev/null ) .,cp tools/commit-msg $(name)/.git/hooks || true;)
@$(foreach name,$(shell find . -type d -name ".git" -exec dirname {} \; 2> /dev/null ),cp tools/commit-msg $(name)/.git/hooks;)
Loading