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

Replace Travis CI with GitHub Actions workflows #447

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
3b4192b
Add code quality checks via GHA
schlessera Feb 9, 2021
71523d2
Simplify CS workflow
schlessera Feb 9, 2021
4318db1
Add basic unit testing workflow
schlessera Feb 9, 2021
f599b11
Avoid resetting Composer root version
schlessera Feb 9, 2021
a3ba0e7
Add missing TestCase file
schlessera Feb 9, 2021
b1c0eea
Start and stop proxy server
schlessera Feb 9, 2021
b0763cc
Install pip requirements first before using pip
schlessera Feb 9, 2021
44115c1
Install pip wheel
schlessera Feb 9, 2021
3417253
Avoid forcing an old version of the proxy server
schlessera Feb 9, 2021
9d12893
Try to use apt to install mitmproxy
schlessera Feb 9, 2021
73244c7
Use GITHUB_ENV to pass env variables between steps
schlessera Feb 9, 2021
80f1c26
Remove left-over export keyword
schlessera Feb 9, 2021
a14d410
Improve quotes
schlessera Feb 9, 2021
3dfb326
Use IP instead of localhost
schlessera Feb 9, 2021
0001052
Revert "Use IP instead of localhost"
schlessera Feb 9, 2021
c0a1011
Use pip to install mitmproxy
schlessera Feb 9, 2021
ca37850
Ping proxy domain
schlessera Feb 9, 2021
e1348f9
Use --version instead of -v for mitmproxy check
schlessera Feb 9, 2021
a10ea71
Add 8080 to env checks
schlessera Feb 9, 2021
e83ad7d
Fix proxy scripts to work with newest mitmproxy release
schlessera Feb 9, 2021
3fa16bc
Show header on curl requests
schlessera Feb 9, 2021
dd776cc
Add edge case TODO for fsockopen invalid auth test
schlessera Feb 9, 2021
1ba6d61
Test from PHP 5.3 onwards
schlessera Feb 9, 2021
2bdfa08
Terminate proxy servers properly
schlessera Feb 9, 2021
793b2ca
Bump testing to PHP 5.5+
schlessera Feb 9, 2021
4b48645
Also run GHA workflows on push to master
schlessera Feb 9, 2021
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
74 changes: 74 additions & 0 deletions .github/workflows/code-quality.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
name: Code Quality Checks

on:
push:
branches:
- master
pull_request:

jobs:

lint: #-----------------------------------------------------------------------
name: Lint PHP files
runs-on: ubuntu-latest
steps:
- name: Check out source code
uses: actions/checkout@v2

- name: Set up PHP envirnoment
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
- name: Set up PHP envirnoment
- name: Set up PHP environment

(here and everywhere else)

uses: shivammathur/setup-php@v2
with:
php-version: '7.4'
tools: cs2pr

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

- name: Use Composer cache
uses: actions/cache@v1
with:
path: ${{ steps['composer-cache'].outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-composer-

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

- name: Run Linter
run: vendor/bin/parallel-lint -j 10 . --exclude vendor --checkstyle | cs2pr

phpcs: #----------------------------------------------------------------------
name: PHPCS
runs-on: ubuntu-latest

steps:
- name: Check out source code
uses: actions/checkout@v2

- name: Set up PHP envirnoment
uses: shivammathur/setup-php@v2
with:
php-version: '7.4'
tools: cs2pr

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

- name: Use Composer cache
uses: actions/cache@v1
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-composer-

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

- name: Run PHPCS
run: vendor/bin/phpcs -q --report=checkstyle | cs2pr
96 changes: 96 additions & 0 deletions .github/workflows/testing.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
name: Testing

on:
push:
branches:
- master
pull_request:

jobs:

unit:
name: Unit test / PHP ${{ matrix.php }}
strategy:
fail-fast: false
matrix:
php: ['5.5', '5.6', '7.0', '7.1', '7.2', '7.3', '7.4', '8.0']
runs-on: ubuntu-latest

steps:
- name: Check out source code
uses: actions/checkout@v2

- name: Set up PHP environment
uses: shivammathur/setup-php@v2
with:
php-version: '${{ matrix.php }}'
coverage: none
tools: composer,cs2pr

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

- name: Use Composer cache
uses: actions/cache@master
with:
path: ${{ steps['composer-cache'].outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-composer-

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

- 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=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: Run PHPUnit
run: composer test

- name: Stop proxy server
run: |
PORT=9002 tests/utils/proxy/stop.sh
PORT=9003 tests/utils/proxy/stop.sh

- name: Stop test server
run: vendor/bin/stop.sh
7 changes: 2 additions & 5 deletions .phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,8 @@
#############################################################################
-->

<config name="testVersion" value="5.2-"/>
<rule ref="PHPCompatibility">
<!-- The example code may contain code samples targetted at PHP > 5.2. -->
<exclude-pattern>/examples/*\.php$</exclude-pattern>
</rule>
<config name="testVersion" value="5.5-"/>
<rule ref="PHPCompatibility"></rule>


<!--
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
"phpcompatibility/php-compatibility": "^9.0",
"wp-coding-standards/wpcs": "^2.0",
"dealerdirect/phpcodesniffer-composer-installer": "^0.7",
"yoast/phpunit-polyfills": "^0.2.0"
"yoast/phpunit-polyfills": "^0.2.0",
"php-parallel-lint/php-parallel-lint": "^1.2"
},
"type": "library",
"autoload": {
Expand Down
9 changes: 8 additions & 1 deletion tests/Proxy/HTTP.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,14 +118,21 @@ public function testConnectWithAuth($transport) {
public function testConnectWithInvalidAuth($transport) {
$this->checkProxyAvailable('auth');

$options = array(
$options = array(
'proxy' => array(
REQUESTS_HTTP_PROXY_AUTH,
REQUESTS_HTTP_PROXY_AUTH_USER . '!',
REQUESTS_HTTP_PROXY_AUTH_PASS . '!',
),
'transport' => $transport,
);

if ($transport === 'Requests_Transport_fsockopen') {
// @TODO fsockopen connection times out on invalid auth instead of returning 407.
$this->expectException('Requests_Exception');
$this->expectExceptionMessage('fsocket timed out');
}

$response = Requests::get(httpbin('/get'), array(), $options);
$this->assertSame(407, $response->status_code);
}
Expand Down
5 changes: 5 additions & 0 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php

class RequestsTest_TestCase extends \Yoast\PHPUnitPolyfills\TestCases\TestCase {

}
14 changes: 11 additions & 3 deletions tests/utils/proxy/start.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
#!/usr/bin/env bash

PROXYDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
PORT=${PORT:-9000}

PROXYBIN=${PROXYBIN:-"$(which mitmdump)"}
ARGS="-s '$PROXYDIR/proxy.py' -p $PORT"
if [[ ! -z "$AUTH" ]]; then
ARGS="$ARGS --singleuser=$AUTH"
ARGS="$ARGS --proxyauth $AUTH"
fi
PIDFILE="$PROXYDIR/proxy.pid"
PIDFILE="$PROXYDIR/proxy-$PORT.pid"

set -x

start-stop-daemon --verbose --start --background --pidfile $PIDFILE --make-pidfile --exec $PROXYBIN -- $ARGS

start-stop-daemon --start --background --pidfile $PIDFILE --make-pidfile --exec $PROXYBIN -- $ARGS
ps -p $(cat $PIDFILE) -u
sleep 2
ps -p $(cat $PIDFILE) -u
9 changes: 7 additions & 2 deletions tests/utils/proxy/stop.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
#!/usr/bin/env bash

PROXYDIR="$PWD/$(dirname $0)"
PORT=${PORT:-9000}

PIDFILE="$PROXYDIR/proxy-$PORT.pid"

PIDFILE="$PROXYDIR/proxy.pid"
set -x

start-stop-daemon --stop --pidfile $PIDFILE --make-pidfile && rm $PROXYDIR/proxy.pid
start-stop-daemon --verbose --stop --pidfile $PIDFILE --remove-pidfile