Skip to content

Commit

Permalink
run phpunit in github workflow
Browse files Browse the repository at this point in the history
setting up old varnish versions did not work, commenting out the legacy
builds
  • Loading branch information
dbu committed Dec 21, 2021
1 parent e4ced75 commit 769fe99
Show file tree
Hide file tree
Showing 18 changed files with 295 additions and 120 deletions.
207 changes: 207 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,207 @@
name: CI

on:
push:
branches:
- master
pull_request:

env:
VARNISH_VERSION: '6.6'
VARNISH_MODULES_VERSION: '0.18.0'
DEPENDENCIES: 'toflar/psr6-symfony-http-cache-store:^2.2.0|^3.0.0'
SYMFONY_DEPRECATIONS_HELPER: 'max[self]=0'
SYMFONY_PHPUNIT_VERSION: '8'

jobs:
latest:
name: PHP ${{ matrix.php }} Varnish ${{ VARNISH_VERSION }}
runs-on: ubuntu-20.04
strategy:
matrix:
include:
- php: '7.2'
- php: '7.3'
- php: '7.4'
env:
DEPENDENCIES: 'symfony/lts:^3 toflar/psr6-symfony-http-cache-store:^2.2.0\|^3.0.0'
- php: '7.4'
env:
DEPENDENCIES: 'symfony/flex'
SYMFONY_VERSION: '^4'
- php: '8.0'
- php: '8.1'

steps:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
tools: composer:v2
coverage: none

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

- name: Setup Varnish and Nginx
run: |
sh ${GITHUB_WORKSPACE}/.github/workflows/setup-varnish.sh
sh ${GITHUB_WORKSPACE}/.github/workflows/setup-nginx.sh
- name: Install composer dependencies
run: |
composer require --no-update ${DEPENDENCIES}
composer update --prefer-dist --no-interaction --no-progress
vendor/bin/simple-phpunit install
- name: Execute tests
run: vendor/bin/simple-phpunit -v

# spent hours trying to make this work
# unfortunately, the installation always picks the varnish 5 from ubuntu instead of the specified one
# installing with `apt-get install varnish=${VARNISH_VERSION}.*` reports that the version is not found
#
# varnish5:
# name: PHP ${{ matrix.php }} Legacy Varnish 5
# runs-on: ubuntu-18.04
# env:
# VARNISH_VERSION: '5.1'
# VARNISH_MODULES_VERSION: '0.14.0'
#
# strategy:
# fail-fast: false
# matrix:
# include:
# - php: '7.4'
#
# steps:
# - name: Setup PHP
# uses: shivammathur/setup-php@v2
# with:
# php-version: ${{ matrix.php }}
# tools: composer:v2
# coverage: none
#
# - name: Checkout code
# uses: actions/checkout@v2
#
# - name: Setup Varnish and Nginx
# run: |
# sh ${GITHUB_WORKSPACE}/.github/workflows/setup-varnish-legacy.sh
# sh ${GITHUB_WORKSPACE}/.github/workflows/setup-nginx.sh
#
# - name: Install composer dependencies
# run: |
# composer update --prefer-dist --prefer-stable --prefer-lowest --no-interaction --no-progress
# vendor/bin/simple-phpunit install
#
# - name: Execute tests
# run: vendor/bin/simple-phpunit -v
#
# varnish4:
# name: PHP ${{ matrix.php }} Legacy Varnish 4
# runs-on: ubuntu-18.04
# env:
# VARNISH_VERSION: '4.1'
# VARNISH_MODULES_VERSION: '0.9.1'
#
# strategy:
# fail-fast: false
# matrix:
# include:
# - php: '7.4'
#
# steps:
# - name: Setup PHP
# uses: shivammathur/setup-php@v2
# with:
# php-version: ${{ matrix.php }}
# tools: composer:v2
# coverage: none
#
# - name: Checkout code
# uses: actions/checkout@v2
#
# - name: Setup Varnish and Nginx
# run: |
# sh ${GITHUB_WORKSPACE}/.github/workflows/setup-varnish-legacy.sh
# sh ${GITHUB_WORKSPACE}/.github/workflows/setup-nginx.sh
#
# - name: Install composer dependencies
# run: |
# composer update --prefer-dist --prefer-stable --prefer-lowest --no-interaction --no-progress
# vendor/bin/simple-phpunit install
#
# - name: Execute tests
# run: vendor/bin/simple-phpunit -v
#
# lowest:
# name: PHP ${{ matrix.php }} Lowest, Varnish 3
# runs-on: ubuntu-18.04
# env:
# VARNISH_VERSION: '3.0'
# VARNISH_MODULES_VERSION: ''
# DEPENDENCIES: ''
#
# strategy:
# fail-fast: false
# matrix:
# php: ['7.2']
#
# steps:
# - name: Setup PHP
# uses: shivammathur/setup-php@v2
# with:
# php-version: ${{ matrix.php }}
# tools: composer:v2
# coverage: none
#
# - name: Checkout code
# uses: actions/checkout@v2
#
# - name: Setup Varnish and Nginx
# run: |
# sh ${GITHUB_WORKSPACE}/.github/workflows/setup-varnish-legacy.sh
# sh ${GITHUB_WORKSPACE}/.github/workflows/setup-nginx.sh
#
# - name: Install composer dependencies
# run: |
# composer update --prefer-dist --prefer-stable --prefer-lowest --no-interaction --no-progress
# vendor/bin/simple-phpunit install
#
# - name: Execute tests
# run: vendor/bin/simple-phpunit -v

coverage:
name: Code Coverage
runs-on: ubuntu-20.04

steps:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 7.4
tools: composer:v2
coverage: xdebug

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

- name: Setup Varnish and Nginx
run: |
sh ${GITHUB_WORKSPACE}/.github/workflows/setup-varnish.sh
sh ${GITHUB_WORKSPACE}/.github/workflows/setup-nginx.sh
- name: Install dependencies
run: |
composer require "friends-of-phpspec/phpspec-code-coverage:^4.3.2" --no-interaction --no-update
composer update --prefer-dist --no-interaction --no-progress
vendor/bin/simple-phpunit install
- name: Execute tests
run: vendor/bin/simple-phpunit -v --coverage-text

- name: Upload coverage
run: |
wget https://scrutinizer-ci.com/ocular.phar
php ocular.phar code-coverage:upload --format=php-clover build/coverage.xml
7 changes: 7 additions & 0 deletions .github/workflows/setup-nginx.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash

set -e
# Install NGINX
sudo apt-get remove nginx
sudo rm /usr/sbin/nginx
sh "${GITHUB_WORKSPACE}/tests/install-nginx.sh"
8 changes: 8 additions & 0 deletions .github/workflows/setup-varnish-legacy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash

set -e
echo "### Installing Legacy Varnish $VARNISH_VERSION ###"
VARNISH_VERSION=$VARNISH_VERSION bash -c 'curl -s https://packagecloud.io/install/repositories/varnishcache/varnish${VARNISH_VERSION//./}/script.deb.sh' | sudo bash
# this is broken: we don't find the version. when not specifying the version, we end up with varnish 5 from the regular ubuntu distribution
VARNISH_VERSION=$VARNISH_VERSION bash -c 'sudo apt-get install varnish=${VARNISH_VERSION}.*'
if [ "$VARNISH_MODULES_VERSION" != "" ]; then sh "${GITHUB_WORKSPACE}/tests/install-varnish-modules-legacy.sh"; fi
7 changes: 7 additions & 0 deletions .github/workflows/setup-varnish.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash

set -e
echo "### Installing Varnish $VARNISH_VERSION ###"
VARNISH_VERSION=$VARNISH_VERSION bash -c 'curl -s https://packagecloud.io/install/repositories/varnishcache/varnish${VARNISH_VERSION//./}/script.deb.sh' | sudo bash
sudo apt-get install -t focal varnish
if [ "$VARNISH_MODULES_VERSION" != "" ]; then sh "${GITHUB_WORKSPACE}/tests/install-varnish-modules.sh"; fi
94 changes: 0 additions & 94 deletions .travis.yml

This file was deleted.

14 changes: 13 additions & 1 deletion src/Test/Proxy/VarnishProxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,14 @@ public function __construct($configFile)
*/
public function start()
{
$vclPath = ((int) $this->getVarnishVersion()) >= 5 ? 'vcl_path' : 'vcl_dir';

$args = [
'-a', $this->ip.':'.$this->getPort(),
'-T', $this->ip.':'.$this->getManagementPort(),
'-f', $this->getConfigFile(),
'-n', $this->getCacheDir(),
'-p', 'vcl_dir='.$this->getConfigDir(),
'-p', $vclPath.'='.$this->getConfigDir(),

'-P', $this->pid,
];
Expand Down Expand Up @@ -171,4 +173,14 @@ public function setAllowInlineC($allowInlineC)
{
$this->allowInlineC = (bool) $allowInlineC;
}

/**
* Defaults to 4.
*
* @return int
*/
private function getVarnishVersion()
{
return getenv('VARNISH_VERSION') ?: '4.0';
}
}
3 changes: 2 additions & 1 deletion tests/Functional/Fixtures/Symfony/AppCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use FOS\HttpCache\SymfonyCache\RefreshListener;
use FOS\HttpCache\SymfonyCache\UserContextListener;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\HttpCache\HttpCache;
use Symfony\Component\HttpKernel\HttpCache\StoreInterface;
use Symfony\Component\HttpKernel\HttpCache\SurrogateInterface;
Expand Down Expand Up @@ -53,7 +54,7 @@ public function __construct(HttpKernelInterface $kernel, StoreInterface $store,
*
* {@inheritdoc}
*/
public function fetch(Request $request, $catch = false)
public function fetch(Request $request, $catch = false): Response
{
return parent::fetch($request, $catch);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Functional/Symfony/EventDispatchingHttpCacheTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class AppCache extends HttpCache implements CacheInvalidation
*
* {@inheritdoc}
*/
public function fetch(Request $request, $catch = false)
public function fetch(Request $request, $catch = false): Response
{
parent::fetch($request, $catch);
}
Expand Down
4 changes: 2 additions & 2 deletions tests/Functional/Varnish/CustomTtlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ protected function getConfigFile()
{
switch ((int) $this->getVarnishVersion()) {
case 3:
return './tests/Functional/Fixtures/varnish-3/custom_ttl.vcl';
return dirname(__DIR__).'/Fixtures/varnish-3/custom_ttl.vcl';
default:
return './tests/Functional/Fixtures/varnish/custom_ttl.vcl';
return dirname(__DIR__).'/Fixtures/varnish/custom_ttl.vcl';
}
}

Expand Down
Loading

0 comments on commit 769fe99

Please sign in to comment.