Bump body-parser and express #1662
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build, test & measure | |
on: | |
push: | |
branches: | |
- develop | |
# Include all release branches. | |
- '[0-9]+.[0-9]+' | |
pull_request: | |
# Run workflow whenever a PR is opened, updated (synchronized), or marked ready for review. | |
types: [opened, synchronize, ready_for_review] | |
jobs: | |
pre-run: | |
name: 'Pre run' | |
runs-on: ubuntu-latest | |
outputs: | |
changed-file-count: ${{ steps.determine-file-counts.outputs.count }} | |
changed-php-count: ${{ steps.determine-file-counts.outputs.php-count }} | |
changed-js-count: ${{ steps.determine-file-counts.outputs.js-count }} | |
steps: | |
- name: Checkout including last 2 commits | |
# Fetch last 2 commits if it's not a PR, so that we can determine the list of modified files. | |
if: ${{ github.base_ref == null }} | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 2 | |
- name: Checkout | |
# Do usual checkout if it's a PR. | |
if: ${{ github.base_ref != null }} | |
uses: actions/checkout@v4 | |
- name: Fetch base branch | |
# Only fetch base ref if it's a PR. | |
if: ${{ github.base_ref != null }} | |
run: git fetch --depth=1 --no-tags origin ${{ github.base_ref }} | |
- name: Determine modified files for PR | |
if: ${{ github.base_ref != null }} | |
run: echo "MODIFIED_FILES=$(git diff --name-only FETCH_HEAD HEAD | base64 -w 0)" >> $GITHUB_ENV | |
- name: Determine modified files for commit | |
if: ${{ github.base_ref == null }} | |
run: echo "MODIFIED_FILES=$(git diff --name-only HEAD~1 HEAD | base64 -w 0)" >> $GITHUB_ENV | |
- id: determine-file-counts | |
name: Determine if modified files should make the workflow run continue | |
run: | | |
MODIFIED_FILES=$(echo "$MODIFIED_FILES" | base64 -d) | |
echo -e "Modified files:\n$MODIFIED_FILES\n" | |
FILE_COUNT=$(php -f bin/determine-modified-files-count.php "$IGNORE_PATH_REGEX" "$MODIFIED_FILES" --invert) | |
PHP_FILE_COUNT=$(php -f bin/determine-modified-files-count.php ".+\.php|composer\.(json|lock)|phpstan\.neon\.dist|phpunit\.xml" "$MODIFIED_FILES") | |
JS_FILE_COUNT=$(php -f bin/determine-modified-files-count.php ".+\.(js|snap)|package\.(json|lock)" "$MODIFIED_FILES") | |
echo "Changed file count: $FILE_COUNT" | |
echo "Changed PHP file count: $PHP_FILE_COUNT" | |
echo "Changed JS file count: $JS_FILE_COUNT" | |
echo "count=$FILE_COUNT" >> $GITHUB_OUTPUT | |
echo "php-count=$PHP_FILE_COUNT" >> $GITHUB_OUTPUT | |
echo "js-count=$JS_FILE_COUNT" >> $GITHUB_OUTPUT | |
env: | |
# Ignore Paths: | |
# - .github/ | |
# - !.github/workflows | |
# - .wordpress-org/ | |
IGNORE_PATH_REGEX: \.github\/(?!workflows)|\.wordpress-org\/ | |
#----------------------------------------------------------------------------------------------------------------------- | |
lint-js: | |
name: 'Lint: JS' | |
needs: pre-run | |
if: needs.pre-run.outputs.changed-js-count > 0 | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Setup Node | |
uses: actions/[email protected] | |
with: | |
node-version-file: '.nvmrc' | |
cache: npm | |
- name: Install Node dependencies | |
run: npm ci | |
env: | |
CI: true | |
- name: Validate package.json | |
run: npm run lint:pkg-json | |
- name: Detect ESLint coding standard violations | |
if: > | |
github.event.pull_request.head.repo.fork == true || | |
github.event.pull_request.user.login == 'dependabot[bot]' | |
run: npm run lint:js | |
- name: Generate ESLint coding standard violations report | |
# Prevent generating the ESLint report if PR is from a fork or authored by Dependabot. | |
if: > | |
! ( github.event.pull_request.head.repo.fork == true || | |
github.event.pull_request.user.login == 'dependabot[bot]' ) | |
run: npm run lint:js:report | |
continue-on-error: true | |
- name: Annotate code linting results | |
# The action cannot annotate the PR when run from a PR fork or was authored by Dependabot. | |
if: > | |
! ( github.event.pull_request.head.repo.fork == true || | |
github.event.pull_request.user.login == 'dependabot[bot]' ) | |
uses: ataylorme/[email protected] | |
with: | |
repo-token: '${{ secrets.GITHUB_TOKEN }}' | |
report-json: 'lint-js-report.json' | |
#----------------------------------------------------------------------------------------------------------------------- | |
lint-php: | |
name: 'Lint: PHP' | |
needs: pre-run | |
if: needs.pre-run.outputs.changed-php-count > 0 | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Setup PHP | |
uses: shivammathur/setup-php@v2 | |
with: | |
php-version: '8.1' | |
coverage: none | |
tools: cs2pr | |
- name: Get Composer Cache Directory | |
id: composer-cache | |
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT | |
- name: Configure Composer cache | |
uses: actions/cache@v4 | |
with: | |
path: ${{ steps.composer-cache.outputs.dir }} | |
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} | |
restore-keys: | | |
${{ runner.os }}-composer- | |
- name: Install Composer dependencies | |
run: composer install --prefer-dist --optimize-autoloader --no-progress --no-interaction | |
- name: Validate composer.json | |
run: composer --no-interaction validate --no-check-all | |
- name: Detect coding standard violations (PHPCS) | |
run: vendor/bin/phpcs -q --report=checkstyle --runtime-set ignore_errors_on_exit 1 --runtime-set ignore_warnings_on_exit 1 | cs2pr --graceful-warnings | |
- name: Normalize composer.json | |
run: vendor/bin/composer-normalize --dry-run | |
#----------------------------------------------------------------------------------------------------------------------- | |
static-analysis-php: | |
name: 'Static Analysis: PHP' | |
runs-on: ubuntu-latest | |
needs: pre-run | |
if: needs.pre-run.outputs.changed-php-count > 0 | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Setup PHP | |
uses: shivammathur/setup-php@v2 | |
with: | |
# phpstan requires PHP 7.1+. | |
php-version: '8.0' | |
extensions: dom, iconv, json, libxml, zip | |
- name: Get Composer Cache Directory | |
id: composer-cache | |
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT | |
- name: Configure Composer cache | |
uses: actions/cache@v4 | |
with: | |
path: ${{ steps.composer-cache.outputs.dir }} | |
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} | |
restore-keys: | | |
${{ runner.os }}-composer- | |
- name: Install Composer dependencies | |
run: composer install | |
- name: Static Analysis (PHPStan) | |
run: | | |
vendor/bin/phpstan --version | |
vendor/bin/phpstan | |
#----------------------------------------------------------------------------------------------------------------------- | |
# Adapted from workflow for running PHP unit tests on google/web-stories-wp. | |
# See https://github.com/google/web-stories-wp/blob/cb2ebada48039171e25c279bdb27d3712dd70b22/.github/workflows/continuous-integration-unit-php.yml | |
unit-test-php: | |
name: "Unit test${{ matrix.coverage && ' (with coverage)' || '' }}: PHP ${{ matrix.php }}, WP ${{ matrix.wp }}" | |
runs-on: ubuntu-latest | |
needs: pre-run | |
if: needs.pre-run.outputs.changed-file-count > 0 | |
env: | |
WP_CORE_DIR: /tmp/wordpress | |
WP_TESTS_DIR: /tmp/wordpress-tests-lib | |
WP_ENVIRONMENT_TYPE: local | |
services: | |
mysql: | |
image: mariadb:latest | |
env: | |
MARIADB_ALLOW_EMPTY_ROOT_PASSWORD: true | |
MARIADB_DATABASE: wordpress_test | |
MARIADB_MYSQL_LOCALHOST_USER: 1 | |
MARIADB_MYSQL_LOCALHOST_GRANTS: USAGE | |
ports: | |
- 3306 | |
options: --health-cmd="healthcheck.sh --su-mysql --connect --innodb_initialized" --health-interval=10s --health-timeout=5s --health-retries=3 | |
continue-on-error: ${{ matrix.experimental == true }} | |
strategy: | |
fail-fast: false | |
matrix: | |
coverage: [false] | |
php: ['7.3', '7.2', '7.1'] | |
wp: ['latest'] | |
phpunit: ['7'] | |
include: | |
- php: '8.3' | |
wp: 'trunk' | |
coverage: false | |
phpunit: '9.6' | |
- php: '8.2' | |
wp: 'trunk' | |
coverage: false | |
phpunit: '9.6' | |
- php: '8.1' | |
wp: 'latest' | |
coverage: false | |
phpunit: '9.6' | |
- php: '8.0' | |
wp: 'latest' | |
coverage: false | |
phpunit: '9.3' | |
- php: '7.4' | |
wp: 'latest' | |
coverage: false | |
phpunit: '9.3' | |
- php: '7.4' | |
wp: 'latest' | |
coverage: true | |
phpunit: '9.3' | |
- php: '7.0' | |
wp: '6.3' | |
coverage: false | |
phpunit: '6' | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Setup PHP | |
uses: shivammathur/setup-php@v2 | |
with: | |
php-version: ${{ matrix.php }} | |
extensions: curl, date, dom, gd, iconv, json, libxml, mysql, spl | |
coverage: ${{ matrix.coverage && 'xdebug' || 'none' }} | |
tools: phpunit:${{ matrix.phpunit }} | |
- name: Shutdown default MySQL service | |
run: sudo service mysql stop | |
- name: Verify MariaDB connection | |
run: | | |
while ! mysqladmin ping -h"127.0.0.1" -P"${{ job.services.mysql.ports[3306] }}" --silent; do | |
sleep 1 | |
done | |
- name: Setup Node | |
uses: actions/[email protected] | |
with: | |
node-version-file: '.nvmrc' | |
cache: npm | |
- name: Get Composer Cache Directory | |
id: composer-cache | |
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT | |
- name: Configure Composer cache | |
uses: actions/cache@v4 | |
with: | |
path: ${{ steps.composer-cache.outputs.dir }} | |
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} | |
restore-keys: | | |
${{ runner.os }}-composer- | |
- name: Install Composer dependencies | |
run: composer install --prefer-dist --ignore-platform-reqs --no-progress --no-interaction | |
- name: Install Node dependencies | |
run: npm ci | |
env: | |
CI: true | |
- name: Build plugin | |
run: npm run build | |
# Avoid conflicts with globally installed PHPUnit. | |
- name: Remove locally installed PHPUnit | |
if: needs.pre-run.outputs.changed-php-count > 0 | |
run: | | |
rm -rf vendor/phpunit | |
composer dump-autoload -o | |
# Scan the logs for failing tests and surface that information by creating annotations and log file decorations. | |
- name: Setup problem matcher to provide annotations for PHPUnit | |
# The JSON file is provided by the `shivammathur/setup-php` action. See https://github.com/shivammathur/setup-php#problem-matchers. | |
run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json" | |
- name: Install WP tests | |
run: bash bin/ci/install-wp-tests.sh wordpress_test root '' 127.0.0.1:${{ job.services.mysql.ports['3306'] }} ${{ matrix.wp }} true | |
- name: Copy plugin to WP plugins directory | |
run: cp -r "$PWD" "$WP_CORE_DIR/src/wp-content/plugins/pwa" | |
- name: Run tests | |
if: ${{ matrix.coverage == false }} | |
run: phpunit --verbose | |
working-directory: ${{ env.WP_CORE_DIR }}/src/wp-content/plugins/pwa | |
- name: Run tests with coverage | |
if: ${{ matrix.coverage == true }} | |
run: phpunit --verbose --coverage-clover build/logs/clover.xml | |
working-directory: ${{ env.WP_CORE_DIR }}/src/wp-content/plugins/pwa | |
- name: Upload code coverage report | |
if: ${{ matrix.coverage == true }} | |
uses: codecov/codecov-action@v3 | |
with: | |
file: ${{ env.WP_CORE_DIR }}/src/wp-content/plugins/pwa/build/logs/clover.xml | |
flags: php,unit | |
fail_ci_if_error: true |