Skip to content

Hourly forecast design iteration #781

Hourly forecast design iteration

Hourly forecast design iteration #781

Workflow file for this run

name: code standards
on:
pull_request:
merge_group:
jobs:
should-test:
name: check if we should run tests
runs-on: ubuntu-latest
outputs:
"no": ${{ steps.skip-tests.outputs.no }}
"yes": ${{ steps.skip-tests.outputs.yes }}
steps:
- name: checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: list files that have changed from main
id: diff
run: echo "diff=$(git diff --name-only origin/main)" | tr "\n" "\t" >> $GITHUB_OUTPUT
- name: determine whether to skip tests
id: skip-tests
uses: actions/github-script@v6
with:
script: |
// The paths that are exempt from testing. If all of the changed
// files are in these paths, we can skip tests completely.
const exemptPaths = [
"docs/",
"scripts/",
".bp-config/",
];
// Get the list of changed files from the previous step and turn it
// into something we can work with.
const changedFiles = ${{ toJSON(steps.diff.outputs.diff) }}
.split("\t")
.filter(value => value.length > 0);
// Determine whether to skip tests. We will skip tests if it is true
// for EVERY FILE that they are in ANY of the exempted paths.
const skipTests = changedFiles.every(file => exemptPaths.some(path => file.startsWith(path)));
// Set the output so other jobs can use it. If we are skipping
// tests, add an annotation so we know, and list out the files that
// were changed. This may be helpful for debugging if things go
// sideways later on.
core.setOutput('no', skipTests);
core.setOutput('yes', !skipTests);
if(skipTests) {
core.notice(`Skipping tests. Modified files are:\n* ${changedFiles.join("\n* ")}`);
}
php-lint:
name: PHP lint
runs-on: ubuntu-latest
needs: [should-test]
if: needs.should-test.outputs.yes == 'true'
steps:
- name: checkout
uses: actions/checkout@v3
- name: setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: "8.2"
- name: get composer paths
id: composer-paths
run: |
echo "cache-dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
echo "bin-dir=${{ github.workspace }}/$(composer config bin-dir)" >> $GITHUB_OUTPUT
- name: cache composer caches
uses: actions/cache@v3
with:
path: ${{ steps.composer-paths.outputs.cache-dir }}
key: composer-cache-${{ hashFiles('composer.lock') }}
- name: install dependencies
env:
COMPOSER_NO_DEV: 0
run: composer install
- name: run phpcs
run: |
echo "::add-matcher::${{ github.workspace }}/.github/workflows/problem-matcher-phpcs.json"
vendor/bin/phpcs --report=checkstyle
js-lint:
name: JS lint
runs-on: ubuntu-latest
needs: [should-test]
if: needs.should-test.outputs.yes == 'true'
steps:
- name: checkout
uses: actions/checkout@v3
- name: setup node
uses: actions/setup-node@v3
with:
node-version: 18
cache: npm
- name: install dependencies
run: npm ci
- name: install proxy dependencies
run: cd tests/api && npm ci
- name: add problem matcher
run: echo "::add-matcher::${{ github.workspace }}/.github/workflows/problem-matcher-eslint.json"
- name: run eslint
run: npm run js-lint
style-lint:
name: SCSS lint
runs-on: ubuntu-latest
needs: [should-test]
if: needs.should-test.outputs.yes == 'true'
steps:
- name: checkout
uses: actions/checkout@v3
- name: setup node
uses: actions/setup-node@v3
with:
node-version: 18
cache: npm
- name: install dependencies
run: npm ci
# Stylelint has a GitHub workflow commands output available by default,
# so we can use that instead of needing a problem matcher.
# https://stylelint.io/user-guide/options#formatter
# https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions
- name: run stylelint
run: npm run style-lint -- -f github
php-unit-tests:
name: PHP unit tests
runs-on: ubuntu-latest
needs: [should-test]
if: needs.should-test.outputs.yes == 'true'
steps:
- name: checkout
uses: actions/checkout@v3
- name: setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: "8.2"
coverage: xdebug
- name: get composer paths
id: composer-paths
run: |
echo "cache-dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
echo "bin-dir=${{ github.workspace }}/$(composer config bin-dir)" >> $GITHUB_OUTPUT
- name: cache composer caches
uses: actions/cache@v3
with:
path: ${{ steps.composer-paths.outputs.cache-dir }}
key: composer-cache-${{ hashFiles('composer.lock') }}
- name: install dependencies
env:
COMPOSER_NO_DEV: 0
run: composer install
- name: run unit tests
run: |
vendor/bin/phpunit --coverage-clover coverage.xml
- name: store coverage output
uses: actions/upload-artifact@v3
with:
name: coverage-report
path: coverage.xml
retention-days: 1
min-code-coverage:
name: "90% code coverage"
runs-on: ubuntu-latest
needs: [php-unit-tests]
steps:
- name: get coverage output
uses: actions/download-artifact@v3
with:
name: coverage-report
- name: 90% code coverage
id: test-coverage
uses: johanvanhelden/gha-clover-test-coverage-check@v1
with:
percentage: 90
filename: coverage.xml
metric: statements
build-drupal-image:
name: build Drupal image
runs-on: ubuntu-latest
needs: [should-test]
if: needs.should-test.outputs.yes == 'true'
steps:
- name: checkout
uses: actions/checkout@v4
- name: setup image cacheing
uses: actions/cache@v3
id: cache
with:
key: drupal-image-${{ hashFiles('composer.lock','web/sites/example.settings.dev.php') }}
path: /tmp/image.tar
- name: Set up Docker Buildx
if: steps.cache.outputs.cache-hit != 'true'
uses: docker/setup-buildx-action@v3
- name: build and export
if: steps.cache.outputs.cache-hit != 'true'
uses: docker/build-push-action@v5
with:
context: .
file: ./Dockerfile.dev
tags: 18f-zscaler-drupal:10-apache
outputs: type=docker,dest=/tmp/image.tar
end-to-end-tests:
name: end-to-end tests
runs-on: ubuntu-latest
needs: [build-drupal-image]
steps:
- name: checkout
uses: actions/checkout@v3
- name: setup image cacheing
uses: actions/cache@v3
id: cache
with:
key: drupal-image-${{ hashFiles('composer.lock','web/sites/example.settings.dev.php') }}
path: /tmp/image.tar
- name: start the site
run: |
docker load --input /tmp/image.tar
docker compose up -d
# Give the containers a moment to settle.
- name: wait a tick
run: sleep 10
- name: populate the site
run: |
cp web/sites/example.settings.dev.php web/sites/settings.dev.php
make install-site
- name: Cypress run
uses: cypress-io/github-action@v6
with:
project: tests/e2e
cache-key: cypress-e2e-${{ hashFiles('package-lock.json') }}
- name: save screenshots
uses: actions/upload-artifact@v3
with:
name: screenshots
path: tests/e2e/cypress/screenshots/screenshots.cy.js/
accessibility-tests:
name: accessibility tests
runs-on: ubuntu-latest
needs: [build-drupal-image]
steps:
- name: checkout
uses: actions/checkout@v3
- name: setup image cacheing
uses: actions/cache@v3
id: cache
with:
key: drupal-image-${{ hashFiles('composer.lock','web/sites/example.settings.dev.php') }}
path: /tmp/image.tar
- name: start the site
run: |
docker load --input /tmp/image.tar
docker compose up -d
# Give the containers a moment to settle.
- name: wait a tick
run: sleep 10
- name: populate the site
run: |
cp web/sites/example.settings.dev.php web/sites/settings.dev.php
make install-site
- name: Cypress run
uses: cypress-io/github-action@v6
with:
project: tests/a11y
cache-key: cypress-a11y-${{ hashFiles('package-lock.json') }}
page-load-time-tests:
name: page load time tests
runs-on: ubuntu-latest
needs: [build-drupal-image]
steps:
- name: checkout
uses: actions/checkout@v3
- name: setup image cacheing
uses: actions/cache@v3
id: cache
with:
key: drupal-image-${{ hashFiles('composer.lock','web/sites/example.settings.dev.php') }}
path: /tmp/image.tar
- name: start the site
run: |
docker load --input /tmp/image.tar
docker compose up -d
# Give the containers a moment to settle.
- name: wait a tick
run: sleep 10
- name: populate the site
run: |
cp web/sites/example.settings.dev.php web/sites/settings.dev.php
make install-site
- name: Cypress run
uses: cypress-io/github-action@v6
with:
project: tests/load-times
cache-key: cypress-a11y-${{ hashFiles('package-lock.json') }}