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

CD-511 Demo content and Github Actions #348

Merged
merged 122 commits into from
Jan 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
122 commits
Select commit Hold shift + click to select a range
0c117fc
feat: lighthouse GA workflow from UNOCHA
left23 Nov 21, 2023
a01c8ba
feat: demo content module with csv from unocha
left23 Nov 21, 2023
abfcc30
Merge branch 'develop' into CD-511
left23 Nov 21, 2023
486a8d3
chore: remove run-tests so lighthouse test are used instead
left23 Nov 21, 2023
fbdf150
chore: run only if label is applied
left23 Nov 21, 2023
5323953
chore: remove duplicate steps
left23 Nov 21, 2023
7c3f5e2
chore: remove install sub theme step
left23 Nov 21, 2023
fd78c03
chore: remove slack steps for ease
left23 Nov 21, 2023
2bf8cf8
chore: remove sub theme step again
left23 Nov 21, 2023
adec149
chore: remove reference to permissions
left23 Nov 21, 2023
fc25983
chore: add debug before fail
left23 Nov 21, 2023
3017159
chore: debug and remove run tests
left23 Nov 21, 2023
f8398e3
chore: indentation so it runs
left23 Nov 21, 2023
b5873a6
chore: update config for demo content module
left23 Nov 21, 2023
18e499e
chore: remove debug, notice no vendor directory
left23 Nov 21, 2023
34e5322
chore: curl 127
left23 Nov 21, 2023
cf647ae
chore: tell nginx about custom port
left23 Nov 22, 2023
75f4512
chore: add port
left23 Nov 22, 2023
67e0f52
chore: reduce to running on labeled only
left23 Nov 22, 2023
49929ac
chore: bring back previously failing starterkit tests
left23 Nov 22, 2023
a988d92
chore: test sh file and update tests docker-compose volume perms
left23 Nov 22, 2023
fba75bd
chore: try it without usr bin
left23 Nov 22, 2023
74c29a6
chore: subtheme script in composer
left23 Nov 22, 2023
797e604
chore: Remove breaking line for now
left23 Nov 22, 2023
9f06716
chore: remove browser output for now
left23 Nov 22, 2023
b64fd2d
chore: update version of lighthouse actions
left23 Nov 22, 2023
8e9b35c
chore: path for lighthous rc
left23 Nov 22, 2023
3ae8f59
chore: path from site root
left23 Nov 22, 2023
54b45d6
chore: re-add en demo module step and set perf urls in config
left23 Nov 23, 2023
a512e16
chore: urls plural
left23 Nov 23, 2023
884e086
chore: urls back into yml
left23 Nov 23, 2023
4328d8c
chore: use a live URL
left23 Nov 23, 2023
6d89499
chore: live url only
left23 Nov 23, 2023
e32922f
chore: run curl
left23 Nov 23, 2023
4ef74eb
chore: drush run server
left23 Nov 23, 2023
c21a4d1
chore: transfer run server to start server command in lighthouse
left23 Nov 23, 2023
c8f3a48
chore: update urls to test and set runs to 3
left23 Dec 7, 2023
15ca76f
Merge branch 'develop' into CD-511
left23 Dec 7, 2023
7a9ef2d
chore: label-based conditional for performance tests
left23 Dec 7, 2023
2ade872
chore: rename to run-tests, indicating performance pieces are optional
left23 Dec 7, 2023
49522a9
chore: re-add portions previously removed while debuggin
left23 Dec 11, 2023
195e67c
chore: run tests on most PR conditions
left23 Dec 11, 2023
7e3b6f5
chore: missing phpunit config
left23 Dec 11, 2023
8ebc1a4
chore: phpunit config
left23 Dec 11, 2023
1757243
chore: pre-pool-create composer from starterkit
left23 Dec 11, 2023
c59123c
chore: add phpunit as dev dependency
left23 Dec 11, 2023
38c6d95
chore: regen lock
left23 Dec 11, 2023
6716449
chore: composer defaults from starterkit
left23 Dec 11, 2023
0df65bf
chore: fail false
left23 Dec 11, 2023
e527e6f
chore: remove unit tests again
left23 Dec 11, 2023
8ee32b5
Merge branch 'develop' into CD-511
left23 Dec 12, 2023
9ec00d3
chore: update dockerfile from starterkit, add dev_mode
left23 Dec 12, 2023
cfd3153
chore: add memcache service from starterkit
left23 Dec 12, 2023
258f6e8
chore: remove memcache service and reference to file as module is not…
left23 Dec 12, 2023
9ed1cfb
chore: reset dockerfile
left23 Dec 12, 2023
3c1f834
chore: remove leftover files from previous module iteration
left23 Dec 12, 2023
0a97783
chore: phpunit is back
left23 Dec 12, 2023
d5f8a31
chore: add a test
left23 Dec 12, 2023
7f02722
style: cs
left23 Dec 12, 2023
b513e12
chore: phpunit config in the correct place
left23 Dec 12, 2023
60db195
chore: remove --prefer-dist from composer install step
left23 Dec 13, 2023
2f57e49
chore: allow plugins list from starterkit
left23 Dec 13, 2023
0ea0ddc
chore: update composer and lock
left23 Dec 13, 2023
492712b
chore: more composer and lock
left23 Dec 13, 2023
928b389
chore: more dockerfile from starterkit
left23 Dec 13, 2023
eeb0ef2
chore: no memcache
left23 Dec 13, 2023
3341b7c
chore: properly formed composer file
left23 Dec 13, 2023
b230078
chore: scripts and assets, regen lock FTW
left23 Dec 13, 2023
04b25d3
chore: i dunno, remove it?
left23 Dec 13, 2023
40d7d7b
chore: docker file from starterkit
left23 Dec 13, 2023
561a457
chore: bump mysql image in tests
lazysoundsystem Dec 20, 2023
aa2cb65
Merge remote-tracking branch 'origin/OPS-9749-bump-mysql-image-in-tes…
left23 Dec 20, 2023
b08471d
chore: remove duplicate
left23 Dec 20, 2023
c91e082
chore: add e2e test step
left23 Dec 20, 2023
66b71fc
chore: set up node step and add label for e2e
left23 Dec 20, 2023
a501882
chore: update readme
left23 Dec 20, 2023
792c20c
chore: add urls and refine budget
left23 Dec 20, 2023
52408e3
chore: increase value for demo page
left23 Dec 20, 2023
2a52f6c
chore: test homepage, not all
left23 Dec 20, 2023
ece4bdc
chore: budget based on web core vitals
left23 Dec 20, 2023
99e363a
chore: add another page with its own budget
left23 Dec 20, 2023
0ce25b2
chore: URLs are in the test file
left23 Dec 20, 2023
7dbe91e
Merge branch 'develop' into CD-511
left23 Dec 21, 2023
b4e9a5f
chore: bypass test error for now, install node, attempt to run e2e
left23 Dec 21, 2023
c79e729
chore: not cd
left23 Dec 21, 2023
7d60722
chore: still use composer script
left23 Dec 21, 2023
55db496
chore: cache node modules and test -d
left23 Dec 21, 2023
a3a8989
chore: still no cd and path to custom not contrib
left23 Dec 21, 2023
c0679ba
Merge branch 'develop' into CD-511-e2e
left23 Jan 2, 2024
1a4bf18
chore: install node and checks
left23 Jan 2, 2024
afddd73
chore: cd to sub theme
left23 Jan 2, 2024
be3b4ce
chore: cache npm
left23 Jan 2, 2024
b64355b
chore: try dependency path as sub theme relative to gh dir
left23 Jan 2, 2024
aca2f21
chore: run npm in same step as node set up
left23 Jan 2, 2024
3696099
chore: no run in node set up
left23 Jan 2, 2024
8c733e3
chore: test if node is available
left23 Jan 2, 2024
4f70d43
chore: bypass composer script and set work dir
left23 Jan 2, 2024
62aac98
chore: remove ampersands
left23 Jan 2, 2024
6dd2393
chore: reference docker
left23 Jan 2, 2024
8cab11b
chore: try to get to subtheme dir
left23 Jan 2, 2024
ed28290
chore: proper commands would be nice
left23 Jan 2, 2024
043b0e0
chore: plural
left23 Jan 2, 2024
1a06b36
chore: npm install step
left23 Jan 2, 2024
070d365
chore: run e2e
left23 Jan 2, 2024
4f1b5f2
chore: node env and ci instead of travis
left23 Jan 2, 2024
5d100f2
chore: set node env for ci in script
left23 Jan 2, 2024
ce8a8cd
chore: re-enable php tests and disable cache
left23 Jan 3, 2024
591565e
chore: remove sample db and readme as no longer used
left23 Jan 3, 2024
13efedb
chore: enable demo content so e2e tests pass
left23 Jan 3, 2024
0e8b1a9
chore: reduce to only what is needed
left23 Jan 3, 2024
bb9cf63
CD-511 Github Actions and e2e (#368)
left23 Jan 3, 2024
c985154
Merge branch 'CD-511-e2e' into CD-511
left23 Jan 3, 2024
77f268f
chore: prevent running when labels are removed
left23 Jan 3, 2024
3d74e67
chore: prevent running tests when PR descr is edited
left23 Jan 3, 2024
59af832
chore: rename as tests as per starterkit
left23 Jan 3, 2024
73afb03
chore: remove theme compilation scripts from composer, no longer used
left23 Jan 4, 2024
1072bea
chore: re-add slack notifications and reorder
left23 Jan 4, 2024
40eeebb
chore: reorder to better group tests
left23 Jan 4, 2024
07e7801
Merge branch 'develop' into CD-511
left23 Jan 10, 2024
560a2b2
chore: regen lock
left23 Jan 10, 2024
86a85c5
chore: regen lock smore
left23 Jan 10, 2024
c300fe2
docs: add tests info to readme
left23 Jan 10, 2024
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
43 changes: 41 additions & 2 deletions .github/workflows/lighthouse-budget.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,24 @@
[
{
"path": "/*",
"path": "/",
"timings": [
{
"metric": "largest-contentful-paint",
"budget": 4000
},
{
"metric": "max-potential-fid",
"budget": 300
},
{
"metric": "interactive",
"budget": 5000
},
{
"metric": "cumulative-layout-shift",
"budget": 0.25
}
],
"resourceSizes": [
{
"resourceType": "document",
Expand All @@ -12,12 +30,33 @@
},
{
"resourceType": "stylesheet",
"budget": 20
"budget": 30
},
{
"resourceType": "total",
"budget": 700
}
]
},
{
"path": "/demo",
"timings": [
{
"metric": "largest-contentful-paint",
"budget": 5000
},
{
"metric": "max-potential-fid",
"budget": 400
},
{
"metric": "interactive",
"budget": 6000
},
{
"metric": "cumulative-layout-shift",
"budget": 0.35
}
]
}
]
1 change: 0 additions & 1 deletion .github/workflows/lighthouserc.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
module.exports = {
ci: {
collect: {
url: ['http://127.0.0.1:8080/demo'],
startServerCommand: 'docker compose -f tests/docker-compose.yml exec -T drupal drush rs 127.0.0.1:8080'
},
assert: {
Expand Down
122 changes: 109 additions & 13 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
name: Run tests

on: [pull_request]
on:
pull_request:
types: [labeled, opened, synchronize]

jobs:
tests:
runs-on: ubuntu-latest
permissions:
contents: write
checks: write
pull-requests: write
actions: read
statuses: write

steps:
- name: Checkout Code
Expand Down Expand Up @@ -64,8 +59,7 @@ jobs:
uses: cafuego/command-output@main
with:
run: |
# Uncomment this if we have custom modules.
# test ! -d ./html/modules/custom || find -L ./html/modules/custom -iregex '.*\.\(php\|module\|inc\|install\)$' -print0 | xargs -0 -n 1 -P 4 php -l
test ! -d ./html/modules/custom || find -L ./html/modules/custom -iregex '.*\.\(php\|module\|inc\|install\)$' -print0 | xargs -0 -n 1 -P 4 php -l
test ! -d ./html/themes/custom || find -L ./html/themes/custom -iregex '.*\.\(php\|theme\)$' -print0 | xargs -0 -n 1 -P 4 php -l
env:
fail-fast: true
Expand Down Expand Up @@ -111,12 +105,19 @@ jobs:
env:
fail-fast: true

- name: Install Subtheme
id: subtheme
uses: cafuego/command-output@main
with:
run: |
docker compose -f tests/docker-compose.yml exec -w /srv/www -T drupal /usr/bin/composer run sub-theme

- name: PHPCS
id: phpcs
uses: cafuego/command-output@main
with:
run: |
docker compose -f tests/docker-compose.yml exec -u appuser -w /srv/www -T drupal phpcs -p --report=full --standard=phpcs.xml ./html/themes/custom
docker compose -f tests/docker-compose.yml exec -u appuser -w /srv/www -T drupal phpcs -p --report=full --standard=phpcs.xml ./html/modules/custom ./html/themes/custom
env:
fail-fast: true

Expand All @@ -125,12 +126,107 @@ jobs:
uses: cafuego/command-output@main
with:
run: |
# This isn't very useful as we're not actually running tests.
docker compose -f tests/docker-compose.yml exec -T drupal drush -y si --existing-config
docker compose -f tests/docker-compose.yml exec -T drupal drush -y si --existing-config minimal install_configure_form.enable_update_status_emails=NULL
env:
fail-fast: true

- name: Run tests
id: tests
uses: cafuego/command-output@main
with:
run: |
docker compose -f tests/docker-compose.yml exec -T drupal drush -y en dblog
docker compose -f tests/docker-compose.yml exec -T drupal chmod -R 777 /srv/www/html/sites/default/files /srv/www/html/sites/default/private
docker compose -f tests/docker-compose.yml exec -T drupal mkdir -p /srv/www/html/build/logs
docker compose -f tests/docker-compose.yml exec -T drupal chmod -R 777 /srv/www/html/build/logs
docker-compose -f tests/docker-compose.yml exec -T drupal mkdir -p /srv/www/html/build/logs /srv/www/html/sites/default/files/browser_output
docker-compose -f tests/docker-compose.yml exec -T drupal chmod -R 777 /srv/www/html/build/logs /srv/www/html/sites/default/files/browser_output
docker compose -f tests/docker-compose.yml exec -T -w /srv/www -e XDEBUG_MODE=coverage -e BROWSERTEST_OUTPUT_DIRECTORY=/srv/www/html/sites/default/files/browser_output -e DTT_BASE_URL=http://127.0.0.1 drupal ./vendor/bin/phpunit --coverage-clover /srv/www/html/build/logs/clover.xml --debug
env:
fail-fast: true

- name: Copy Coveralls
id: copy_coveralls
if: success()
run: docker cp "$(docker compose -f tests/docker-compose.yml ps -q drupal)":/srv/www/html/build/logs/clover.xml . || echo "skip=true" >> "$GITHUB_OUTPUT"

- name: Monitor coverage
id: coveralls
if: ${{ steps.copy_coveralls.outputs.skip != 'true' }}
uses: slavcodev/coverage-monitor-action@v1
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
coverage_path: "clover.xml"
threshold_alert: 0
threshold_warning: 50
threshold_metric: "lines"
comment_footer: false

- name: Install demo content
# Install Demo content if the PR has the label "e2e" or "performance"
if: contains(github.event.pull_request.labels.*.name, 'e2e') || contains(github.event.pull_request.labels.*.name, 'performance')
id: content
uses: cafuego/command-output@main
with:
run: |
docker-compose -f tests/docker-compose.yml exec -T drupal drush -y en unocha_demo_content
curl -v http://127.0.0.1:8080/demo
env:
fail-fast: true

- name: Set up node
# Run Jest e2e tests if the PR has the label "e2e"
if: contains(github.event.pull_request.labels.*.name, 'e2e')
uses: actions/setup-node@v4
with:
node-version: '^18.16.1'

- name: Install node dependencies
# Run Jest e2e tests if the PR has the label "e2e"
if: contains(github.event.pull_request.labels.*.name, 'e2e')
run: |
docker compose -f tests/docker-compose.yml exec -w /srv/www drupal sh
cd html/themes/custom/common_design_subtheme
npm install

- name: Run e2e tests
# Run Jest e2e tests if the PR has the label "e2e"
if: contains(github.event.pull_request.labels.*.name, 'e2e')
run: |
docker compose -f tests/docker-compose.yml exec -w /srv/www drupal sh
cd html/themes/custom/common_design_subtheme
npm run ci -- -t '^(?!.*Subtheme).*$'
env:
fail-fast: true

# - name: Debug Server
# uses: cafuego/command-output@main
# with:
# run: |
# docker ps -a

- name: Audit URLs using Lighthouse
# Run Lighthouse if the PR has the label "performance"
if: contains(github.event.pull_request.labels.*.name, 'performance')
uses: treosh/lighthouse-ci-action@10.1.0
with:
urls: |
http://127.0.0.1:8080/
http://127.0.0.1:8080/demo
runs: 3
budgetPath: .github/workflows/lighthouse-budget.json # test performance budgets
configPath: .github/workflows/lighthouserc.js
uploadArtifacts: true # save results as an action artifacts
temporaryPublicStorage: true # upload lighthouse report to the temporary storage

- name: DB Logs
id: dblog
if: failure()
uses: cafuego/command-output@main
with:
run: |
docker compose -f tests/docker-compose.yml exec -T drupal drush watchdog:show

- name: Find Comment
uses: peter-evans/find-comment@v2
if: ${{ !env.ACT }}
Expand Down
38 changes: 34 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Common Design Demo | [![Build Status](https://travis-ci.com/UN-OCHA/common-design-site.svg?branch=master)](https://travis-ci.com/UN-OCHA/common-design-site)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤣

# Common Design Demo

This is the Common Design Drupal 8 site. The code for this project is managed with composer.
This is the Common Design Drupal 10 site. The code for this project is managed with composer.

To install security updates for Drupal, run `composer update drupal/core drupal/core-dev --with-dependencies`.

Expand Down Expand Up @@ -29,9 +29,11 @@ and stage_file_proxy.

### Remote

Automatic testing is run via Travis CI. Code syntax, style and quality are inspected.
Automatic testing is run via GitHub Actions.
Code syntax, style and quality are inspected by default, based on [drupal-starterkit run-tests.yml](https://github.com/UN-OCHA/drupal-starterkit/blob/develop/.github/workflows/run-tests.yml)

With a small alteration, these tests could run via GitHub Actions.
To run Lighthouse tests, add the label "performance" to the PR.
To run end-to-end test with Jest, add the label "e2e" to the PR.

### Locally

Expand Down Expand Up @@ -79,3 +81,31 @@ fin composer outdated drupal/*
fin composer update drupal/* --with-dependencies
fin drush updb -y && fin drush cr
```

### Set up with local stack
See [/local/README](https://github.com/UN-OCHA/common-design-site/tree/develop/local)

## Performance or e2e tests with Github Actions
Optional test steps - see `run-tests.yml`

Custom Github labels need to be applied to the PR for the above test steps to run: `performance` or `e2e` depending.

### Install demo content

Enables unocha_demo_content module and imports nodes, menu items etc from json, set the frontpage

### Set up node

Github action to install node

### Install node dependencies

In sub theme, install packages including Jest for e2e

### Run e2e tests

Runs Jest e2e tests in sub theme using as ci at http://127.0.0.1:8080

### Audit URLs using Lighthouse

Runs multiple times on 2 URLS (http://127.0.0.1:8080 and http://127.0.0.1:8080/demo) against a performance budget and provides temporary links to Lighthouse reports.
31 changes: 31 additions & 0 deletions assets/docker-build-image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Build docker image

on:
push:
branches:
- develop
- 'feature/**'
- main
release:
types: [published]

jobs:
build:
runs-on: ubuntu-latest
steps:

- name: Build
id: build-action
uses: UN-OCHA/actions/drupal-docker-build@main
with:
aws_access_key_id: ${{ secrets.ECR_AWS_ACCESS_KEY_ID }}
aws_secret_access_key: ${{ secrets.ECR_AWS_ACCESS_KEY_ID }}
docker_registry_url: public.ecr.aws
docker_registry_path: /unocha/
docker_image: starterkit-site
docker_username: ${{ secrets.ECR_AWS_ACCESS_KEY_ID }}
docker_password: ${{ secrets.ECR_AWS_SECRET_ACCESS_KEY }}
ecr_github_token: ${{ secrets.ECR_GITHUB_TOKEN }}
ecr_jenkins_token: ${{ secrets.JENKINS_ECR_TOKEN }}
slack_bot_token: ${{ secrets.SLACK_BOT_TOKEN }}
slack_channel_name: ${{ secrets.SLACK_CHANNEL }}
1 change: 1 addition & 0 deletions assets/robots.txt.append
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Sitemap
Loading