Skip to content

Commit

Permalink
CI: switch to GitHub Actions - step 3: test and coverage stage
Browse files Browse the repository at this point in the history
This commit:
* Adds a GH Actions workflow for running the unit tests against PHP 5.5 - current.
    Note:
    - This workflow will run for all pull requests and for merges to master, but not for other push events.
    - Code coverage will be checked for the highest and lowest PHP version so the results can be combined to cover any polyfills and work-arounds.
        Includes adjusting the codecov configuration to expect 2 reports for each build.
    - The PHP 8.1 (nightly) job is "allowed to fail" (`experimental` = true). If it does fail, the build status will unfortunately show as "failed", even though all non-experimental jobs have succeeded.
         This is a known issue in GHA: https://github.com/actions/toolkit/issues/399
    - For PHP 5.2-5.4, the tests will still be run via Travis as the test server setup is incompatible with PHP < 5.5 and using multiple PHP versions in a workflow run does work on Travis, but doesn't work the same on GH Actions.
* Strips down the `.travis.yml` configuration to the bare minimum to run the tests against PHP 5.2 - 5.4.
* Adds a "Build Status" badge in the Readme to use the results from this particular GH Actions runs.

Note: for the time being, the tests will not be run against PHP 8.1/nightly as PHPUnit 7 is incompatible, meaning that that build would _always_ fail.
Once the version constraints for PHHUnit have been widened (see PR 446), the build against PHP nightly should be enabled.

Co-authored-by: Alain Schlesser <[email protected]>
  • Loading branch information
jrfnl and schlessera committed Apr 16, 2021
1 parent a78ba51 commit b9c0431
Show file tree
Hide file tree
Showing 4 changed files with 159 additions and 42 deletions.
4 changes: 4 additions & 0 deletions .codecov.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
codecov:
notify:
after_n_builds: 2

coverage:
round: nearest
# Status will be green when coverage is between 85 and 100%.
Expand Down
144 changes: 144 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
name: Test

on:
push:
branches:
- master
pull_request:
# Allow manually triggering the workflow.
workflow_dispatch:

jobs:
#### TEST STAGE ####
test:
runs-on: ubuntu-latest

strategy:
# Keys:
# - coverage: Whether to run the tests with code coverage.
# - experimental: Whether the build is "allowed to fail".
matrix:
php: ['5.6', '7.0', '7.1', '7.2', '7.3', '7.4']
coverage: [false]
experimental: [false]

include:
# Run code coverage on high/low PHP.
- php: '5.5'
coverage: true
experimental: false
- php: '8.0'
coverage: true
experimental: false

# Test against PHP Nightly.
# This should be enabled once the PHPUnit version constraints have been widened.
#- php: '8.1'
# coverage: false
# experimental: true

name: "Test: PHP ${{ matrix.php }}"

continue-on-error: ${{ matrix.experimental }}

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

- name: Set coverage variable
id: set_cov
run: |
if [ ${{ matrix.coverage }} == "true" ]; then
echo '::set-output name=COV::xdebug'
else
echo '::set-output name=COV::none'
fi
- name: Install PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
coverage: ${{ steps.set_cov.outputs.COV }}
tools: cs2pr

# Install dependencies and handle caching in one go.
# @link https://github.com/marketplace/actions/install-composer-dependencies
- name: Install Composer dependencies - normal
if: ${{ startsWith( matrix.php, '8' ) == false && matrix.php != 'latest' }}
uses: "ramsey/composer-install@v1"

# For PHP 8.0 and "nightly", we need to install with ignore platform reqs.
- name: Install Composer dependencies - with ignore platform
if: ${{ startsWith( matrix.php, '8' ) || matrix.php == 'latest' }}
uses: "ramsey/composer-install@v1"
with:
composer-options: --ignore-platform-reqs

- name: Setup problem matcher to provide annotations for PHPUnit
run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"

- name: Setup Python
uses: actions/setup-python@v2
with:
python-version: '3.8'

- name: Setup proxy server
run: pip3 install mitmproxy

- name: Start test server
run: |
PORT=8080 vendor/bin/start.sh
echo "REQUESTS_TEST_HOST_HTTP=localhost:8080" >> $GITHUB_ENV
- name: Start proxy server
run: |
PORT=9002 tests/utils/proxy/start.sh
PORT=9003 AUTH="test:pass" tests/utils/proxy/start.sh
echo "REQUESTS_HTTP_PROXY=localhost:9002" >> $GITHUB_ENV
echo "REQUESTS_HTTP_PROXY_AUTH=localhost:9003" >> $GITHUB_ENV
echo "REQUESTS_HTTP_PROXY_AUTH_USER=test" >> $GITHUB_ENV
echo "REQUESTS_HTTP_PROXY_AUTH_PASS=pass" >> $GITHUB_ENV
- name: Ensure the HTTPS test instance on Heroku is spun up
run: curl -s -I http://requests-php-tests.herokuapp.com/ > /dev/null

- name: Check mitmproxy version
run: mitmdump --version

- name: Ping localhost domain
run: ping -c1 localhost

- name: Access localhost on port 8080
run: curl -i http://localhost:8080

- name: Access localhost on port 9002
run: curl -i http://localhost:9002

- name: Show PHPUnit version
run: vendor/bin/phpunit --version

- name: Run the unit tests, no code coverage
if: ${{ matrix.coverage == false }}
run: composer test

- name: Run the unit tests with code coverage
if: ${{ matrix.coverage == true }}
run: vendor/bin/phpunit --coverage-clover clover.xml

- name: Stop proxy server
continue-on-error: true
run: |
PORT=9002 tests/utils/proxy/stop.sh
PORT=9003 tests/utils/proxy/stop.sh
- name: Stop test server
continue-on-error: true
run: vendor/bin/stop.sh

- name: Send coverage report to Codecov
if: ${{ success() && matrix.coverage == true }}
uses: codecov/codecov-action@v1
with:
files: ./clover.xml
fail_ci_if_error: true
verbose: true
50 changes: 9 additions & 41 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,36 +1,15 @@
dist: xenial
language: php

env:
- COMPOSER_PHPUNIT=true

jobs:
fast_finish: true
include:
- php: 5.2
dist: precise
env: COMPOSER_PHPUNIT=false
- php: 5.3
dist: precise
env: COMPOSER_PHPUNIT=false
- php: 5.4
dist: trusty
env: COMPOSER_PHPUNIT=false
- php: 5.5
dist: trusty
env: COMPOSER_PHPUNIT=false
- php: 5.6
env: TEST_COVERAGE=1
- php: 7.0
- php: 7.1
- php: 7.2
- php: 7.3
- php: 7.4
- php: 8.0
- php: nightly

allow_failures:
- php: nightly

cache:
directories:
Expand All @@ -41,28 +20,20 @@ cache:
- $HOME/.cache/composer/files

install:
# Speed up build time by disabling Xdebug unless actually needed.
# Speed up build time by disabling Xdebug.
# https://johnblackbourn.com/reducing-travis-ci-build-times-for-wordpress-projects/
# https://twitter.com/kelunik/status/954242454676475904
- if [ "$TEST_COVERAGE" != '1' ]; then phpenv config-rm xdebug.ini || echo 'No xdebug config.'; fi
- phpenv config-rm xdebug.ini || echo 'No xdebug config.'

# Setup the test server
- if [ "$COMPOSER_PHPUNIT" == 'false' ]; then phpenv local $( phpenv versions | grep 5.6 | tail -1 ); fi
- if [ "$COMPOSER_PHPUNIT" == 'false' ]; then travis_retry composer remove --dev --no-update phpunit/phpunit; fi
- if [ "$COMPOSER_PHPUNIT" == 'false' ]; then export PHPUNIT_BIN="phpunit";
else export PHPUNIT_BIN="$(pwd)/vendor/bin/phpunit";
fi
- phpenv local $( phpenv versions | grep 5.6 | tail -1 )
# The PHPCS and lint dependencies require PHP 5.3, so would block install on PHP < 5.3.
# As they are only needed for code sniffing, remove them.
- travis_retry composer remove --dev --no-update squizlabs/php_codesniffer phpcompatibility/php-compatibility wp-coding-standards/wpcs dealerdirect/phpcodesniffer-composer-installer php-parallel-lint/php-parallel-lint php-parallel-lint/php-console-highlighter
- |
if [[ ${TRAVIS_PHP_VERSION:0:1} == "8" || $TRAVIS_PHP_VERSION == "nightly" ]]; then
travis_retry composer install --no-interaction --ignore-platform-reqs
else
travis_retry composer install --no-interaction
fi
# Also remove PHPUnit as we'll be using the Phar provided by Travis.
- travis_retry composer remove --dev --no-update phpunit/phpunit squizlabs/php_codesniffer phpcompatibility/php-compatibility wp-coding-standards/wpcs dealerdirect/phpcodesniffer-composer-installer php-parallel-lint/php-parallel-lint php-parallel-lint/php-console-highlighter
- travis_retry composer install --no-interaction
- TESTPHPBIN=$(phpenv which php)
- if [ "$COMPOSER_PHPUNIT" == 'false' ]; then phpenv local --unset; fi
- phpenv local --unset

# Setup the proxy
- pip install --user mitmproxy==0.18.2
Expand All @@ -82,7 +53,7 @@ before_script:
- curl -s -I http://requests-php-tests.herokuapp.com/ > /dev/null

# Environment checks
- $PHPUNIT_BIN --version
- phpunit --version

script:
# Lint PHP files against parse errors for PHP 5.2 - 5.4.
Expand All @@ -97,10 +68,8 @@ script:
# Run the unit tests.
- |
if [ "$TEST_COVERAGE" == '1' ]; then
$PHPUNIT_BIN --coverage-clover clover.xml;
# PHPUnit 4.x does not yet support the `no-coverage` flag.
elif [ ${TRAVIS_PHP_VERSION:0:3} == "5.2" ]; then
if [ ${TRAVIS_PHP_VERSION:0:3} == "5.2" ]; then
$PHPUNIT_BIN;
else
$PHPUNIT_BIN --no-coverage;
Expand All @@ -109,4 +78,3 @@ script:
after_script:
- tests/utils/proxy/stop.sh
- PATH=$PATH vendor/bin/stop.sh
- test $TEST_COVERAGE && bash <(curl -s https://codecov.io/bash)
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ Requests for PHP

[![CS](https://github.com/WordPress/Requests/actions/workflows/cs.yml/badge.svg)](https://github.com/WordPress/Requests/actions/workflows/cs.yml)
[![Lint](https://github.com/WordPress/Requests/actions/workflows/lint.yml/badge.svg)](https://github.com/WordPress/Requests/actions/workflows/lint.yml)
[![Build Status](https://travis-ci.org/WordPress/Requests.svg?branch=master)](https://travis-ci.org/WordPress/Requests)
[![Test](https://github.com/WordPress/Requests/actions/workflows/test.yml/badge.svg)](https://github.com/WordPress/Requests/actions/workflows/test.yml)
[![CI PHP 5.2-5.4](https://travis-ci.org/WordPress/Requests.svg?branch=master)](https://travis-ci.org/WordPress/Requests)
[![codecov.io](http://codecov.io/github/WordPress/Requests/coverage.svg?branch=master)](http://codecov.io/github/WordPress/Requests?branch=master)

Requests is a HTTP library written in PHP, for human beings. It is roughly
Expand Down

0 comments on commit b9c0431

Please sign in to comment.