Skip to content

Commit 6a89b5c

Browse files
committed
Set up github workflows for multiple php versions
Run this alongside Travis CI
1 parent 9bf6637 commit 6a89b5c

File tree

7 files changed

+105
-0
lines changed

7 files changed

+105
-0
lines changed

.dockerignore

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
.git/
2+
.github/
3+
validation/
4+
vendor/
5+
docs/
6+
tools/
7+
**/.DS_Store
8+
**/.idea
9+
**/composer.lock
10+
tests/output
11+
.phpunit.result.cache
12+
**/*.ast
13+
**/.*.swp
14+
**/.*.swo
15+
**/Dockerfile
16+
.dockerignore

.gitattributes

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
/tests/cases/**/*.php text eol=lf
44

55
/.vscode export-ignore
6+
/ci export-ignore
67
/docs export-ignore
78
/experiments export-ignore
89
/php-langspec export-ignore
@@ -17,3 +18,4 @@
1718
/Contributing.md export-ignore
1819
/README.md export-ignore
1920
/phpunit.xml export-ignore
21+
/.dockerignore export-ignore

.github/workflows/main.yml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Runs tolerant-php-parser's tests
2+
name: CI
3+
4+
# Controls when the action will run.
5+
on:
6+
# Triggers the workflow on push or pull request events but only for the main branch
7+
push:
8+
branches: [ main ]
9+
pull_request:
10+
branches: [ main ]
11+
12+
# Allows you to run this workflow manually from the Actions tab
13+
workflow_dispatch:
14+
15+
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
16+
jobs:
17+
# This workflow contains a single job called "build"
18+
build:
19+
# The type of runner that the job will run on
20+
runs-on: ubuntu-latest
21+
22+
# See https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions#using-environment-variables-in-a-matrix
23+
strategy:
24+
fail-fast: false
25+
matrix:
26+
include:
27+
# NOTE: If this is not quoted, the yaml parser will convert numbers such as 8.0 to the number 8,
28+
# and the docker image `php:8` is the latest minor version of php 8.x (8.1).
29+
- PHP_VERSION: '7.2'
30+
- PHP_VERSION: '7.3'
31+
- PHP_VERSION: '7.4'
32+
- PHP_VERSION: '8.0'
33+
- PHP_VERSION: '8.1'
34+
- PHP_VERSION: '8.2.0beta2'
35+
36+
# Steps represent a sequence of tasks that will be executed as part of the job
37+
steps:
38+
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
39+
- uses: actions/checkout@v2
40+
41+
# Runs a single command using the runners shell
42+
- name: Build and test in docker
43+
run: bash ci/run_tests_dockerized ${{ matrix.PHP_VERSION }}

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ tests/output
66
*.ast
77
.*.swp
88
.*.swo
9+
.phpunit.result.cache

ci/Dockerfile

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
ARG PHP_VERSION
2+
FROM php:$PHP_VERSION
3+
RUN curl https://getcomposer.org/download/latest-2.x/composer.phar -o /usr/bin/composer.phar && chmod a+x /usr/bin/composer.phar
4+
WORKDIR /tolerant-php-parser
5+
RUN apt-get update && apt-get install -y unzip && apt-get clean
6+
ARG COMPOSER_OPTIONS
7+
ENV COMPOSER_OPTIONS=$COMPOSER_OPTIONS
8+
9+
ADD composer.json ./
10+
RUN composer.phar install $COMPOSER_OPTIONS && composer.phar clear-cache
11+
12+
ADD . .

ci/run_tests

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/usr/bin/env bash
2+
# This runs the tests that have been set up in GitHub Workflows so far
3+
4+
# -x Exit immediately if any command fails
5+
# -e Echo all commands being executed.
6+
set -xe
7+
php -d short_open_tag=0 ./vendor/bin/phpunit --testsuite invariants
8+
php -d short_open_tag=0 ./vendor/bin/phpunit --testsuite grammar
9+
php -d short_open_tag=0 ./vendor/bin/phpunit --testsuite api

ci/run_tests_dockerized

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/usr/bin/env bash
2+
if [ $# != 1 ]; then
3+
echo "Usage: $0 PHP_VERSION" 1>&2
4+
echo "e.g. $0 8.0" 1>&2
5+
echo "The PHP_VERSION is the version of the php docker image to use" 1>&2
6+
echo "This runs the tests that have been set up in GitHub Workflows so far" 1>&2
7+
exit 1
8+
fi
9+
# -x Exit immediately if any command fails
10+
# -e Echo all commands being executed.
11+
# -u fail for undefined variables
12+
set -xeu
13+
PHP_VERSION=$1
14+
COMPOSER_OPTIONS=""
15+
# lexicographic comparison
16+
if [ "$PHP_VERSION" > "8.1" ]; then
17+
COMPOSER_OPTIONS="--ignore-platform-reqs"
18+
fi
19+
20+
DOCKER_IMAGE="tolerant-php-parser-test-runner:$PHP_VERSION"
21+
docker build --build-arg="PHP_VERSION=$PHP_VERSION" --build-arg="COMPOSER_OPTIONS=$COMPOSER_OPTIONS" --tag="$DOCKER_IMAGE" -f ci/Dockerfile .
22+
docker run --rm $DOCKER_IMAGE ci/run_tests

0 commit comments

Comments
 (0)