Skip to content

Commit b9c0431

Browse files
jrfnlschlessera
andcommitted
CI: switch to GitHub Actions - step 3: test and coverage stage
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]>
1 parent a78ba51 commit b9c0431

File tree

4 files changed

+159
-42
lines changed

4 files changed

+159
-42
lines changed

.codecov.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
codecov:
2+
notify:
3+
after_n_builds: 2
4+
15
coverage:
26
round: nearest
37
# Status will be green when coverage is between 85 and 100%.

.github/workflows/test.yml

Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
name: Test
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
pull_request:
8+
# Allow manually triggering the workflow.
9+
workflow_dispatch:
10+
11+
jobs:
12+
#### TEST STAGE ####
13+
test:
14+
runs-on: ubuntu-latest
15+
16+
strategy:
17+
# Keys:
18+
# - coverage: Whether to run the tests with code coverage.
19+
# - experimental: Whether the build is "allowed to fail".
20+
matrix:
21+
php: ['5.6', '7.0', '7.1', '7.2', '7.3', '7.4']
22+
coverage: [false]
23+
experimental: [false]
24+
25+
include:
26+
# Run code coverage on high/low PHP.
27+
- php: '5.5'
28+
coverage: true
29+
experimental: false
30+
- php: '8.0'
31+
coverage: true
32+
experimental: false
33+
34+
# Test against PHP Nightly.
35+
# This should be enabled once the PHPUnit version constraints have been widened.
36+
#- php: '8.1'
37+
# coverage: false
38+
# experimental: true
39+
40+
name: "Test: PHP ${{ matrix.php }}"
41+
42+
continue-on-error: ${{ matrix.experimental }}
43+
44+
steps:
45+
- name: Checkout code
46+
uses: actions/checkout@v2
47+
48+
- name: Set coverage variable
49+
id: set_cov
50+
run: |
51+
if [ ${{ matrix.coverage }} == "true" ]; then
52+
echo '::set-output name=COV::xdebug'
53+
else
54+
echo '::set-output name=COV::none'
55+
fi
56+
57+
- name: Install PHP
58+
uses: shivammathur/setup-php@v2
59+
with:
60+
php-version: ${{ matrix.php }}
61+
coverage: ${{ steps.set_cov.outputs.COV }}
62+
tools: cs2pr
63+
64+
# Install dependencies and handle caching in one go.
65+
# @link https://github.com/marketplace/actions/install-composer-dependencies
66+
- name: Install Composer dependencies - normal
67+
if: ${{ startsWith( matrix.php, '8' ) == false && matrix.php != 'latest' }}
68+
uses: "ramsey/composer-install@v1"
69+
70+
# For PHP 8.0 and "nightly", we need to install with ignore platform reqs.
71+
- name: Install Composer dependencies - with ignore platform
72+
if: ${{ startsWith( matrix.php, '8' ) || matrix.php == 'latest' }}
73+
uses: "ramsey/composer-install@v1"
74+
with:
75+
composer-options: --ignore-platform-reqs
76+
77+
- name: Setup problem matcher to provide annotations for PHPUnit
78+
run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"
79+
80+
- name: Setup Python
81+
uses: actions/setup-python@v2
82+
with:
83+
python-version: '3.8'
84+
85+
- name: Setup proxy server
86+
run: pip3 install mitmproxy
87+
88+
- name: Start test server
89+
run: |
90+
PORT=8080 vendor/bin/start.sh
91+
echo "REQUESTS_TEST_HOST_HTTP=localhost:8080" >> $GITHUB_ENV
92+
93+
- name: Start proxy server
94+
run: |
95+
PORT=9002 tests/utils/proxy/start.sh
96+
PORT=9003 AUTH="test:pass" tests/utils/proxy/start.sh
97+
echo "REQUESTS_HTTP_PROXY=localhost:9002" >> $GITHUB_ENV
98+
echo "REQUESTS_HTTP_PROXY_AUTH=localhost:9003" >> $GITHUB_ENV
99+
echo "REQUESTS_HTTP_PROXY_AUTH_USER=test" >> $GITHUB_ENV
100+
echo "REQUESTS_HTTP_PROXY_AUTH_PASS=pass" >> $GITHUB_ENV
101+
102+
- name: Ensure the HTTPS test instance on Heroku is spun up
103+
run: curl -s -I http://requests-php-tests.herokuapp.com/ > /dev/null
104+
105+
- name: Check mitmproxy version
106+
run: mitmdump --version
107+
108+
- name: Ping localhost domain
109+
run: ping -c1 localhost
110+
111+
- name: Access localhost on port 8080
112+
run: curl -i http://localhost:8080
113+
114+
- name: Access localhost on port 9002
115+
run: curl -i http://localhost:9002
116+
117+
- name: Show PHPUnit version
118+
run: vendor/bin/phpunit --version
119+
120+
- name: Run the unit tests, no code coverage
121+
if: ${{ matrix.coverage == false }}
122+
run: composer test
123+
124+
- name: Run the unit tests with code coverage
125+
if: ${{ matrix.coverage == true }}
126+
run: vendor/bin/phpunit --coverage-clover clover.xml
127+
128+
- name: Stop proxy server
129+
continue-on-error: true
130+
run: |
131+
PORT=9002 tests/utils/proxy/stop.sh
132+
PORT=9003 tests/utils/proxy/stop.sh
133+
134+
- name: Stop test server
135+
continue-on-error: true
136+
run: vendor/bin/stop.sh
137+
138+
- name: Send coverage report to Codecov
139+
if: ${{ success() && matrix.coverage == true }}
140+
uses: codecov/codecov-action@v1
141+
with:
142+
files: ./clover.xml
143+
fail_ci_if_error: true
144+
verbose: true

.travis.yml

Lines changed: 9 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,15 @@
11
dist: xenial
22
language: php
33

4-
env:
5-
- COMPOSER_PHPUNIT=true
6-
74
jobs:
85
fast_finish: true
96
include:
107
- php: 5.2
118
dist: precise
12-
env: COMPOSER_PHPUNIT=false
139
- php: 5.3
1410
dist: precise
15-
env: COMPOSER_PHPUNIT=false
1611
- php: 5.4
1712
dist: trusty
18-
env: COMPOSER_PHPUNIT=false
19-
- php: 5.5
20-
dist: trusty
21-
env: COMPOSER_PHPUNIT=false
22-
- php: 5.6
23-
env: TEST_COVERAGE=1
24-
- php: 7.0
25-
- php: 7.1
26-
- php: 7.2
27-
- php: 7.3
28-
- php: 7.4
29-
- php: 8.0
30-
- php: nightly
31-
32-
allow_failures:
33-
- php: nightly
3413

3514
cache:
3615
directories:
@@ -41,28 +20,20 @@ cache:
4120
- $HOME/.cache/composer/files
4221

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

4928
# Setup the test server
50-
- if [ "$COMPOSER_PHPUNIT" == 'false' ]; then phpenv local $( phpenv versions | grep 5.6 | tail -1 ); fi
51-
- if [ "$COMPOSER_PHPUNIT" == 'false' ]; then travis_retry composer remove --dev --no-update phpunit/phpunit; fi
52-
- if [ "$COMPOSER_PHPUNIT" == 'false' ]; then export PHPUNIT_BIN="phpunit";
53-
else export PHPUNIT_BIN="$(pwd)/vendor/bin/phpunit";
54-
fi
29+
- phpenv local $( phpenv versions | grep 5.6 | tail -1 )
5530
# The PHPCS and lint dependencies require PHP 5.3, so would block install on PHP < 5.3.
5631
# As they are only needed for code sniffing, remove them.
57-
- 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
58-
- |
59-
if [[ ${TRAVIS_PHP_VERSION:0:1} == "8" || $TRAVIS_PHP_VERSION == "nightly" ]]; then
60-
travis_retry composer install --no-interaction --ignore-platform-reqs
61-
else
62-
travis_retry composer install --no-interaction
63-
fi
32+
# Also remove PHPUnit as we'll be using the Phar provided by Travis.
33+
- 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
34+
- travis_retry composer install --no-interaction
6435
- TESTPHPBIN=$(phpenv which php)
65-
- if [ "$COMPOSER_PHPUNIT" == 'false' ]; then phpenv local --unset; fi
36+
- phpenv local --unset
6637

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

8455
# Environment checks
85-
- $PHPUNIT_BIN --version
56+
- phpunit --version
8657

8758
script:
8859
# Lint PHP files against parse errors for PHP 5.2 - 5.4.
@@ -97,10 +68,8 @@ script:
9768
9869
# Run the unit tests.
9970
- |
100-
if [ "$TEST_COVERAGE" == '1' ]; then
101-
$PHPUNIT_BIN --coverage-clover clover.xml;
10271
# PHPUnit 4.x does not yet support the `no-coverage` flag.
103-
elif [ ${TRAVIS_PHP_VERSION:0:3} == "5.2" ]; then
72+
if [ ${TRAVIS_PHP_VERSION:0:3} == "5.2" ]; then
10473
$PHPUNIT_BIN;
10574
else
10675
$PHPUNIT_BIN --no-coverage;
@@ -109,4 +78,3 @@ script:
10978
after_script:
11079
- tests/utils/proxy/stop.sh
11180
- PATH=$PATH vendor/bin/stop.sh
112-
- test $TEST_COVERAGE && bash <(curl -s https://codecov.io/bash)

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ Requests for PHP
33

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

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

0 commit comments

Comments
 (0)