diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml new file mode 100644 index 0000000..f62a835 --- /dev/null +++ b/.github/workflows/php.yml @@ -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 diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 54eaca7..0000000 --- a/.travis.yml +++ /dev/null @@ -1,38 +0,0 @@ -# see http://about.travis-ci.org/docs/user/languages/php/ for more hints -language: php - -sudo: false - -cache: - directories: - - $HOME/.composer/cache - -php: - - 5.4 - - 5.5 - - 5.6 - - 7.0 - - 7.1 - - hhvm - -matrix: - allow_failures: - - php: hhvm - - php: 7.1 - -env: - - TYPE=mysql DSN=mysql://root@localhost/spot_test - - TYPE=pgsql DSN=pgsql://postgres@localhost/spot_test" - - TYPE=sqlite DSN=sqlite::memory - -install: - - composer install - -# execute any number of scripts before the test run, custom env's are available as variables -before_script: - - if [[ "$TYPE" == "mysql" ]]; then mysql -e "create database IF NOT EXISTS spot_test;" -uroot; fi - - if [[ "$TYPE" == "pgsql" ]]; then psql -c 'create database spot_test;' -U postgres; fi - -# omitting "script:" will default to phpunit -# use the $TYPE env variable to determine the phpunit.xml to use -script: vendor/bin/phpunit --configuration phpunit_$TYPE.xml --coverage-text diff --git a/README.md b/README.md index 8eabb8c..17ce00c 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/composer.json b/composer.json index 1be286f..d6ce6e5 100644 --- a/composer.json +++ b/composer.json @@ -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" } }