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

Migrate Travis CI tasks to GitHub Actions #1040

Merged
merged 13 commits into from
Oct 8, 2021
Merged
Show file tree
Hide file tree
Changes from 6 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
61 changes: 61 additions & 0 deletions .github/workflows/bundle-size.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: Bundle Size

on:
pull_request:

jobs:
BundleSize:
name: Bundle size
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Set up PHP
uses: shivammathur/setup-php@v2
with:
php-version: "7.4"
coverage: none

- name: Set up Node
uses: actions/setup-node@v2
with:
node-version: "12.21.0"
cache: "npm"

- name: Log debug information
run: |
php --version
composer --version
node --version
npm --version

- name: Get Composer cache directory
id: composer-cache-config
run: echo "::set-output name=dir::$(composer config cache-files-dir)"

- name: Set up Composer caching
uses: actions/cache@v2
with:
path: ${{ steps.composer-cache-config.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('composer.lock') }}
restore-keys: |
${{ runner.os }}-composer-

- name: Install Node dependencies
run: npm ci

- name: Build production bundle
run: |
echo "::group::Build log"
tomalec marked this conversation as resolved.
Show resolved Hide resolved
npm run build
echo "::endgroup::"

- name: Run BundleWatch
env:
BUNDLEWATCH_GITHUB_TOKEN: ${{ secrets.BUNDLEWATCH_GITHUB_TOKEN }}
# Workaround of https://github.com/bundlewatch/bundlewatch/issues/423
CI_BRANCH_BASE: ${{ github.base_ref }}
# Workaround of https://github.com/bundlewatch/bundlewatch/issues/220
CI_COMMIT_SHA: ${{ github.event.pull_request.head.sha }}
run: node ./node_modules/bundlewatch/lib/bin/index.js
92 changes: 92 additions & 0 deletions .github/workflows/js-css-linting.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
name: JavaScript and CSS Linting

on:
push:
branches:
- trunk
- develop
pull_request:

jobs:
Setup:
name: Setup for jobs
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Log debug information
run: |
node --version
npm --version

- name: Get npm cache directory
id: npm-cache
uses: actions/cache@v2
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-

- name: Update npm cache directory # if package-lock has changed
if: steps.npm-cache.outputs.cache-hit != 'true'
run: npm ci --ignore-scripts

JSLintingCheck:
name: Lint JavaScript
needs: Setup
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Get npm cache directory
uses: actions/cache@v2
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-

- name: Install Node dependencies
run: npm ci --ignore-scripts

- name: Save code linting report JSON
run: npm run lint:js -- --quiet --output-file eslint_report.json --format json
# Continue to the next step even if this fails
continue-on-error: true

- name: Annotate code linting results
uses: ataylorme/[email protected]
with:
repo-token: "${{ secrets.GITHUB_TOKEN }}"
report-json: "eslint_report.json"

- name: Upload ESLint report
uses: actions/upload-artifact@v2
with:
name: eslint_report.json
path: eslint_report.json

CSSLintingCheck:
name: Lint CSS
needs: Setup
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Get npm cache directory
uses: actions/cache@v2
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-

- name: Install Node dependencies
run: npm ci --ignore-scripts

- name: Lint CSS
run: npm run lint:css
35 changes: 35 additions & 0 deletions .github/workflows/js-unit-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: JavaScript Unit Tests

on:
push:
branches:
- trunk
- develop
pull_request:

jobs:
UnitTests:
name: JavaScript unit tests
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Log debug information
run: |
node --version
npm --version

- name: Get npm cache directory
uses: actions/cache@v2
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-

Copy link
Member

Choose a reason for hiding this comment

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

💅 I wonder If we could somehow DRY it, as this bit repeats in many other workflows.

Copy link
Contributor

Choose a reason for hiding this comment

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

Doing a search about this led me to this issue as well as Composite Actions. I didn't delve deeply enough to see how that might play out with our actions.

Copy link
Member Author

Choose a reason for hiding this comment

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

Adjusted by 148dd5f, b86b5fe, and e7467f7. And it needs some workarounds due to lack of if syntax in composite actions. (ref: actions/runner#834)

- name: Install Node dependencies
run: npm ci --ignore-scripts

- name: Run JavaScript unit tests
run: npm run test-unit
51 changes: 51 additions & 0 deletions .github/workflows/php-coding-standards.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: PHP Coding Standards

on:
push:
branches:
- trunk
- develop
pull_request:

jobs:
phpcs:
name: PHP coding standards
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Set up PHP
uses: shivammathur/setup-php@v2
with:
php-version: "7.4"
coverage: none
tools: cs2pr

- name: Log debug information
run: |
php --version
composer --version

- name: Get Composer cache directory
id: composer-cache-config
run: echo "::set-output name=dir::$(composer config cache-files-dir)"

- name: Set up Composer caching
uses: actions/cache@v2
with:
path: ${{ steps.composer-cache-config.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('composer.lock') }}
restore-keys: |
${{ runner.os }}-composer-

- name: Install Composer dependencies
run: |
composer install --prefer-dist --no-suggest --no-progress --no-ansi --no-interaction
echo "${PWD}/vendor/bin" >> $GITHUB_PATH

- name: Log PHPCS debug information
run: vendor/bin/phpcs -i

- name: Run PHPCS on all files
run: vendor/bin/phpcs ./src -q -n --report=checkstyle | cs2pr
117 changes: 117 additions & 0 deletions .github/workflows/php-unit-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
name: PHP Unit Tests

on:
push:
branches:
- trunk
- develop
pull_request:

jobs:
Setup:
name: Setup for jobs
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Log debug information
run: |
node --version
npm --version
composer --version

- name: Get npm cache directory
id: npm-cache
uses: actions/cache@v2
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-

- name: Update npm cache directory # if package-lock has changed
if: steps.npm-cache.outputs.cache-hit != 'true'
run: npm ci --ignore-scripts

- name: Get Composer cache directory
id: composer-cache-config
run: echo "::set-output name=dir::$(composer config cache-files-dir)"

- name: Set up Composer caching
id: composer-cache
uses: actions/cache@v2
with:
path: ${{ steps.composer-cache-config.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('composer.lock') }}
restore-keys: |
${{ runner.os }}-composer-

- name: Update Composer cache directory # if composer-lock has changed
if: steps.composer-cache.outputs.cache-hit != 'true'
run: composer install --prefer-dist --no-suggest --no-progress --no-ansi --no-interaction

UnitTests:
name: PHP unit tests - PHP ${{ matrix.php }}, WP ${{ matrix.wp-version }}
needs: Setup
runs-on: ubuntu-latest
env:
WP_CORE_DIR: "/tmp/wordpress/src"
WP_TESTS_DIR: "/tmp/wordpress/tests/phpunit"
strategy:
matrix:
php: [7.3, 7.4]
wp-version: [5.6, 5.7, 5.8]

steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Get npm cache directory
uses: actions/cache@v2
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-

- name: Get Composer cache directory
id: composer-cache-config
run: echo "::set-output name=dir::$(composer config cache-files-dir)"

- name: Set up Composer caching
uses: actions/cache@v2
with:
path: ${{ steps.composer-cache-config.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('composer.lock') }}
restore-keys: |
${{ runner.os }}-composer-

- name: Set up MySQL
# MySQL 8.0 uses the `caching_sha2_password` authentication method by default.
# So here alter password with `mysql_native_password` authentication method
# to make older PHP (7.3.x) mysql client be able to create database connections.
run: |
sudo systemctl start mysql.service
mysql -u root -proot -e "ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'root';"

- name: Set up PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
coverage: none

- name: Install Composer dependencies
run: composer install --prefer-dist --no-suggest --no-progress --no-ansi --no-interaction

- name: Install Node dependencies and build
run: |
npm ci
npm run dev

- name: Install WP tests
shell: bash
run: ./bin/install-wp-tests.sh wordpress_test root root localhost ${{ matrix.wp-version }}

- name: Run PHP unit tests
run: composer test-unit
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
"dealerdirect/phpcodesniffer-composer-installer": "^v0.7",
"phpunit/phpunit": "^7.5",
"wp-cli/i18n-command": "^2.2",
"wp-coding-standards/wpcs": "^2.3"
"wp-coding-standards/wpcs": "^2.3",
"yoast/phpunit-polyfills": "^1.0"
Copy link
Member

Choose a reason for hiding this comment

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


Is this a dependency needed for GH Actions, or something that was missing before?

Copy link
Member Author

Choose a reason for hiding this comment

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

That's the problem stuck me for the longest before. I got error when running composer test-unit on my local and GHA. Not sure why it can run successfully on Travis CI.

> ./vendor/bin/phpunit
Error: The PHPUnit Polyfills library is a requirement for running the WP test suite.
If you are trying to run plugin/theme integration tests, make sure the PHPUnit Polyfills library (https://github.com/Yoast/PHPUnit-Polyfills) is available and either load the autoload file of this library in your own test bootstrap before calling the WP Core test bootstrap file; or set the absolute path to the PHPUnit Polyfills library in a "WP_TESTS_PHPUNIT_POLYFILLS_PATH" constant to allow the WP Core bootstrap to load the Polyfills.

If you are trying to run the WP Core tests, make sure to set the "WP_RUN_CORE_TESTS" constant to 1 and run `composer install` before running the tests.
Once the dependencies are installed, you can run the tests using the Composer-installed version of PHPUnit or using a PHPUnit phar file, but the dependencies do need to be installed whichever way the tests are run.
Script ./vendor/bin/phpunit handling the test-unit event returned with error code 1

Finally, I ended up this problem by adding the yoast/phpunit-polyfills dependency.

},
"replace": {
"symfony/polyfill-mbstring": "*"
Expand Down
Loading