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

Move from Travis CI (no longer free) to Github Actions #302

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
101 changes: 101 additions & 0 deletions .github/workflows/php.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
name: PHP Build

on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]

permissions:
contents: read

env:
SPOT_DB_NAME: spot_test
MYSQL_PWD: ${{ secrets.SPOT_DB_PASSWORD }}
PGPASSWORD: ${{ secrets.SPOT_DB_PASSWORD }}
SPOT_DB_HOSTNAME: 127.0.0.1

jobs:
build:

runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
php: ['5.4', '5.5', '5.6', '7.0']
type: ['mysql', 'pgsql', 'sqlite']

services:
mysql:
image: ${{ (matrix.type == 'mysql') && 'mysql:5.6' || '' }}
env:
# The MySQL docker container requires these environment variables to be set
# so we can create and migrate the test database.
# See: https://hub.docker.com/_/mysql
MYSQL_DATABASE: ${{ env.SPOT_DB_NAME }}
MYSQL_ROOT_PASSWORD: ${{ env.MYSQL_PWD }}
ports:
# Opens port 3306 on service container and host
# https://docs.github.com/en/actions/using-containerized-services/about-service-containers
- 3306:3306
# Before continuing, verify the mysql container is reachable from the ubuntu host
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
postgres:
image: ${{ (matrix.type == 'pgsql') && 'postgres' || '' }}
env:
# Provide the password for postgres
POSTGRES_PASSWORD: ${{ env.PGPASSWORD }}
ports:
- 5432:5432
# Set health checks to wait until postgres has started
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5

steps:

- name: Set up common environment variables
run: |
echo "SPOT_DB_TYPE=${{ matrix.type }}" >> $GITHUB_ENV

# Has to be a different step othwerwise $TYPE is not yet available
- name: Set up database specific environment variables
run: |
if [[ "$SPOT_DB_TYPE" == "mysql" ]]; then
mysql -e "create database IF NOT EXISTS ${{ env.SPOT_DB_NAME }};" -uroot -h ${{ env.SPOT_DB_HOSTNAME }};
echo "SPOT_DB_DSN=mysql://root:${{ env.MYSQL_PWD }}@${{ env.SPOT_DB_HOSTNAME }}/${{ env.SPOT_DB_NAME }}" >> $GITHUB_ENV
elif [[ "$SPOT_DB_TYPE" == "pgsql" ]]; then
psql -c 'create database ${{ env.SPOT_DB_NAME }};' -U postgres -h ${{ env.SPOT_DB_HOSTNAME }};
echo "SPOT_DB_DSN=pgsql://postgres:${{ env.PGPASSWORD }}@${{ env.SPOT_DB_HOSTNAME }}/${{ env.SPOT_DB_NAME }}" >> $GITHUB_ENV
elif [[ "$SPOT_DB_TYPE" == "sqlite" ]]; then
echo "SPOT_DB_DSN=sqlite::memory" >> $GITHUB_ENV
fi

- uses: actions/checkout@v4

- name: Install PHP ${{ matrix.php }}
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}

- name: Check PHP ${{ matrix.php }}
run: php -v

- name: Validate composer.json and composer.lock
run: composer validate --strict

- name: Cache Composer packages
id: composer-cache
uses: actions/cache@v4
with:
path: vendor
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-php-

- name: Install dependencies
run: composer install --no-progress

# Add a test script to composer.json, for instance: "test": "vendor/bin/phpunit"
# Docs: https://getcomposer.org/doc/articles/scripts.md
- name: Run ${{ matrix.type }} test suite
run: composer run-script test_$SPOT_DB_TYPE
38 changes: 0 additions & 38 deletions .travis.yml

This file was deleted.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Spot DataMapper ORM v2.0 [![Build Status](https://travis-ci.org/spotorm/spot2.svg)](https://travis-ci.org/spotorm/spot2)
Spot DataMapper ORM v2.0 [![Build Status](https://github.com/spotorm/spot2/actions/workflows/php.yml/badge.svg)](https://github.com/spotorm/spot2/actions/workflows/php.yml)
========================
Spot v2.x is built on the [Doctrine
DBAL](http://www.doctrine-project.org/projects/dbal.html), and targets PHP
Expand Down
5 changes: 5 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,10 @@
"psr-4": {
"SpotTest\\": "tests/"
}
},
"scripts": {
"test_mysql": "vendor/bin/phpunit --configuration phpunit_mysql.xml --coverage-text",
"test_pgsql": "vendor/bin/phpunit --configuration phpunit_pgsql.xml --coverage-text",
"test_sqlite": "vendor/bin/phpunit --configuration phpunit_sqlite.xml --coverage-text"
}
}