-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1040 from woocommerce/add/github-actions
Migrate Travis CI tasks to GitHub Actions
- Loading branch information
Showing
10 changed files
with
410 additions
and
3 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
name: Prepare Node | ||
description: Load npm cache, install Node dependencies | ||
|
||
inputs: | ||
install-deps: | ||
description: Whether to run `npm ci`. Set "maybe" to install deps if cache is missing. "yes" by default. | ||
required: false | ||
default: "yes" | ||
|
||
ignore-scripts: | ||
description: Whether to run `npm ci` with --ignore-scripts. "yes" by default. | ||
required: false | ||
default: "yes" | ||
|
||
runs: | ||
using: composite | ||
steps: | ||
# Log debug information | ||
- shell: sh -e {0} | ||
run: | | ||
node --version | ||
npm --version | ||
# Get npm cache directory | ||
- uses: actions/cache@v2 | ||
id: npm-cache | ||
with: | ||
path: ~/.npm | ||
key: ${{ runner.os }}-node-${{ hashFiles('package-lock.json') }} | ||
restore-keys: | | ||
${{ runner.os }}-node- | ||
# Install node dependencies | ||
- shell: sh -e {0} | ||
# Update npm cache directory if package-lock has changed | ||
run: | | ||
if [ "${{ inputs.install-deps }}" = "yes" ] || [ "${{ steps.npm-cache.outputs.cache-hit }}" != "true" ]; then | ||
npm ci `if [ "${{ inputs.ignore-scripts }}" = "yes" ]; then printf %s "--ignore-scripts"; fi` | ||
else | ||
echo "Skip npm ci" | ||
fi |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
name: Prepare PHP | ||
description: Set up PHP, load Composer cache, install Composer dependencies | ||
|
||
inputs: | ||
php-version: | ||
description: Specify PHP version. "7.4" by default. | ||
required: false | ||
default: "7.4" | ||
|
||
tools: | ||
description: Specify the tools parameter of shivammathur/setup-php@v2. null by default. | ||
required: false | ||
default: null | ||
|
||
install-deps: | ||
description: Whether to run `composer install`. Set "maybe" to install deps if cache is missing. "yes" by default. | ||
required: false | ||
default: "yes" | ||
|
||
runs: | ||
using: composite | ||
steps: | ||
# Set up PHP | ||
- name: | ||
uses: shivammathur/setup-php@v2 | ||
with: | ||
php-version: ${{ inputs.php-version }} | ||
coverage: none | ||
tools: ${{ inputs.tools }} | ||
|
||
# Log debug information | ||
- shell: sh -e {0} | ||
run: | | ||
php --version | ||
composer --version | ||
# Get Composer cache directory | ||
- shell: sh -e {0} | ||
id: composer-cache-config | ||
run: echo "::set-output name=dir::$(composer config cache-files-dir)" | ||
|
||
# Set up Composer caching | ||
- uses: actions/cache@v2 | ||
id: composer-cache | ||
with: | ||
path: ${{ steps.composer-cache-config.outputs.dir }} | ||
key: ${{ runner.os }}-composer-${{ hashFiles('composer.lock') }} | ||
restore-keys: | | ||
${{ runner.os }}-composer- | ||
# Install Composer dependencies | ||
- shell: sh -e {0} | ||
# Update Composer cache directory if composer.lock has changed | ||
run: | | ||
if [ "${{ inputs.install-deps }}" = "yes" ] || [ "${{ steps.composer-cache.outputs.cache-hit }}" != "true" ]; then | ||
composer install --prefer-dist --no-suggest --no-progress --no-ansi --no-interaction | ||
echo "${PWD}/vendor/bin" >> $GITHUB_PATH | ||
else | ||
echo "Skip composer install" | ||
fi |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
name: Bundle Size | ||
|
||
on: | ||
push: | ||
branches: | ||
- trunk | ||
- develop | ||
pull_request: | ||
|
||
jobs: | ||
BundleSize: | ||
name: Bundle size | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v2 | ||
|
||
- name: Prepare PHP | ||
uses: ./.github/actions/prepare-php | ||
with: | ||
install-deps: "maybe" | ||
|
||
- name: Prepare node | ||
uses: ./.github/actions/prepare-node | ||
with: | ||
ignore-scripts: "no" | ||
|
||
- name: Build production bundle | ||
run: | | ||
echo "::group::Build log" | ||
npm run build | ||
echo "::endgroup::" | ||
# Since BundleWatch is having issues when getting some environment variables from GitHub Actions, | ||
# it needs some workarounds to specify `CI_COMMIT_SHA`, `CI_BRANCH`, and `CI_BRANCH_BASE` here. | ||
# References: | ||
# - https://github.com/bundlewatch/bundlewatch/blob/v0.3.2/src/app/config/getCIVars.js#L8-L10 | ||
# - https://github.com/bundlewatch/bundlewatch/issues/423 | ||
# - https://github.com/bundlewatch/bundlewatch/issues/220 | ||
- name: Prepare BundleWatch env values - push | ||
if: ${{ github.event_name == 'push' }} | ||
run: | | ||
BRANCH=$(echo '${{ github.event.ref }}' | sed 's/^refs\/heads\///') | ||
echo "CI_BRANCH=$BRANCH" >> $GITHUB_ENV | ||
echo "CI_BRANCH_BASE=$BRANCH" >> $GITHUB_ENV | ||
echo "CI_COMMIT_SHA=${{ github.sha }}" >> $GITHUB_ENV | ||
- name: Prepare BundleWatch env values - pull request | ||
if: ${{ github.event_name == 'pull_request' }} | ||
run: | | ||
echo "CI_BRANCH=${{ github.head_ref }}" >> $GITHUB_ENV | ||
echo "CI_BRANCH_BASE=${{ github.base_ref }}" >> $GITHUB_ENV | ||
echo "CI_COMMIT_SHA=${{ github.event.pull_request.head.sha }}" >> $GITHUB_ENV | ||
- name: Run BundleWatch | ||
env: | ||
BUNDLEWATCH_GITHUB_TOKEN: ${{ secrets.BUNDLEWATCH_GITHUB_TOKEN }} | ||
run: node ./node_modules/bundlewatch/lib/bin/index.js |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
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: Prepare node | ||
uses: ./.github/actions/prepare-node | ||
with: | ||
install-deps: "maybe" | ||
|
||
JSLintingCheck: | ||
name: Lint JavaScript | ||
needs: Setup | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v2 | ||
|
||
- name: Prepare node | ||
uses: ./.github/actions/prepare-node | ||
|
||
- 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: Prepare node | ||
uses: ./.github/actions/prepare-node | ||
|
||
- name: Lint CSS | ||
run: npm run lint:css |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
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: Prepare node | ||
uses: ./.github/actions/prepare-node | ||
|
||
- name: Run JavaScript unit tests | ||
run: npm run test-unit |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
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: Prepare PHP | ||
uses: ./.github/actions/prepare-php | ||
with: | ||
tools: cs2pr | ||
|
||
- 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 |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
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: Prepare node | ||
uses: ./.github/actions/prepare-node | ||
with: | ||
install-deps: "maybe" | ||
|
||
- name: Prepare PHP | ||
uses: ./.github/actions/prepare-php | ||
with: | ||
install-deps: "maybe" | ||
|
||
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: Prepare node | ||
uses: ./.github/actions/prepare-node | ||
|
||
- name: Prepare PHP | ||
uses: ./.github/actions/prepare-php | ||
with: | ||
php-version: "${{ matrix.php }}" | ||
|
||
- 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: Build client bundles | ||
run: 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 |
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
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
Oops, something went wrong.