Skip to content

Commit

Permalink
CI: switch to GitHub Actions - step 1: code style
Browse files Browse the repository at this point in the history
This commit:
* Adds a GH Actions workflow for the CI code style check and to validate the `composer.json` file.
* Removes those actions from the `.travis.yml` configuration.
* Adds a "Build Status" badge in the Readme to use the results from this particular GH Actions run.

Notes:
1. Builds will run on all pushes and on pull requests.
2. Builds can also be manually triggered.
    Note: manual triggering of builds has to be [explicitly allowed](https://github.blog/changelog/2020-07-06-github-actions-manual-triggers-with-workflow_dispatch/). This is not a feature which is enabled by default.
3. If a previous GH actions run for the same branch hadn't finished yet when the same branch is pushed again, the previous run will be cancelled.
    In Travis, this was an option on the "Settings" page - "Auto cancellation" -, which was turned on for most, if not all, Yoast repos. The `concurrency` configuration in the GHA script emulates the same behaviour.
4. Composer dependency downloads will be cached for faster builds using a [predefined GH action](https://github.com/marketplace/actions/install-composer-dependencies) specifically created for this purpose.
    The alternative would be to handle the caching manually, which would add three extra steps to the script.
    Note: Caching works differently between Travis and GH Actions.
    On GH Actions, once a cache has been created, it can't be updated. It can only be replaced by a new cache with a different key.
    As the PHP version, the `composer.json` and a potential `composer.lock` hash are all part of the key used by the above mentioned action, this difference should not have a significant impact.
    Ref: https://docs.github.com/en/actions/advanced-guides/caching-dependencies-to-speed-up-workflows
5. The CS check will display the results in the actions script output log, as well as display any violations found inline in the GitHub code view using the [cs2pr](https://github.com/staabm/annotate-pull-request-from-checkstyle) tool.

 Differences with the Travis implementation:
* This check will now run on ALL pushes and pulls.
    The branch filtering which was previously being applied in Travis has not been implemented for this script.
* The `composer validate` command will now only be run against the PHP version used in the `cs` script (PHP 7.4), not against multiple PHP versions.
  • Loading branch information
jrfnl committed Oct 11, 2021
1 parent 73335a3 commit d33e368
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 13 deletions.
50 changes: 50 additions & 0 deletions .github/workflows/cs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: CS

on:
# Run on all pushes and on all pull requests.
push:
pull_request:
# Allow manually triggering the workflow.
workflow_dispatch:

# Cancels all previous workflow runs for the same branch that have not yet completed.
concurrency:
# The concurrency group contains the workflow name and the branch name.
group: ${{ github.workflow }}-${{ github.head_ref }}
cancel-in-progress: true

jobs:
checkcs:
name: 'Check code style'
runs-on: ubuntu-latest

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

- name: Install PHP
uses: shivammathur/setup-php@v2
with:
php-version: '7.4'
coverage: none
tools: cs2pr

# Validate the composer.json file.
# @link https://getcomposer.org/doc/03-cli.md#validate
- name: Validate Composer installation
run: composer validate --no-check-all

# Install dependencies and handle caching in one go.
# @link https://github.com/marketplace/actions/install-composer-dependencies
- name: Install Composer dependencies
uses: ramsey/composer-install@v1

# Check the codestyle of the files.
# The results of the CS check will be shown inline in the PR via the CS2PR tool.
# @link https://github.com/staabm/annotate-pull-request-from-checkstyle/
- name: Check PHP code style
continue-on-error: true
run: composer check-cs -- --report-full --report-checkstyle=./phpcs-report.xml

- name: Show PHPCS results in PR
run: cs2pr ./phpcs-report.xml
15 changes: 2 additions & 13 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
fast_finish: true
include:
- php: 7.4
env: PHPLINT=1 PHPCS=1 SECURITY=1
env: PHPLINT=1 SECURITY=1
- php: 5.6
env: PHPLINT=1
- php: 8.0
Expand Down Expand Up @@ -45,7 +45,6 @@ jobs:

cache:
directories:
- .cache
- vendor
- $HOME/.composer/cache

Expand All @@ -55,7 +54,7 @@ before_install:

install:
- |
if [[ "$PHPCS" == "1" || "$PHPLINT" == "1" ]]; then
if [[ "$PHPLINT" == "1" ]]; then
composer install --no-interaction
fi
- if [[ "$SECURITY" == "1" ]]; then wget -P $SECURITYCHECK_DIR https://github.com/fabpot/local-php-security-checker/releases/download/v1.2.0/local-php-security-checker_1.2.0_linux_amd64 && chmod +x $SECURITYCHECK_DIR/local-php-security-checker_1.2.0_linux_amd64;fi
Expand All @@ -80,16 +79,6 @@ script:
if [[ "$PHPLINT" == "1" ]]; then
composer lint
fi
# PHP CS
- |
if [[ "$PHPCS" == "1" ]]; then
travis_fold start "PHP.code-style" && travis_time_start
composer check-cs
travis_time_finish && travis_fold end "PHP.code-style"
fi
# Validate the composer.json file.
# @link https://getcomposer.org/doc/03-cli.md#validate
- if [[ $TRAVIS_PHP_VERSION == "5.6" || $TRAVIS_PHP_VERSION == "7.4" ]]; then composer validate --no-check-all; fi
# Check for known security vulnerabilities in the currently locked-in dependencies.
- if [[ "$SECURITY" == "1" ]]; then $SECURITYCHECK_DIR/local-php-security-checker_1.2.0_linux_amd64 --path=$(pwd)/composer.lock;fi
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
Yoast Test Helper
=================

[![CS](https://github.com/Yoast/yoast-test-helper/actions/workflows/cs.yml/badge.svg)](https://github.com/Yoast/yoast-test-helper/actions/workflows/cs.yml)
[![Build Status](https://api.travis-ci.org/Yoast/yoast-test-helper.svg?branch=master)](https://travis-ci.org/Yoast/wordpress-seo)
[![License: GPL v3](https://img.shields.io/badge/License-GPL%20v3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0)

Expand Down

0 comments on commit d33e368

Please sign in to comment.