From 64b21f65ffd545d43d276eaa8c938e14517a8bb6 Mon Sep 17 00:00:00 2001 From: Benjamin Morel Date: Fri, 16 Nov 2018 16:32:02 +0100 Subject: [PATCH] Autogenerate the Travis CI build matrix with a script --- .travis.yml | 310 ++++++++++++++----------------------- travis-matrix-builder.php | 314 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 425 insertions(+), 199 deletions(-) create mode 100644 travis-matrix-builder.php diff --git a/.travis.yml b/.travis.yml index 49fb1d6f77b..eb9892d7146 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,20 +3,9 @@ sudo: false dist: trusty cache: - directories: - - vendor - - $HOME/.composer/cache - -php: - - 7.1 - - 7.2 - - 7.3 - - nightly - -env: - - DB=sqlite - - DB=mysql - - DB=mysqli + directories: + - vendor + - $HOME/.composer/cache before_install: - | @@ -51,44 +40,31 @@ after_script: travis_retry php ocular.phar code-coverage:upload --format=php-clover clover.xml fi -jobs: +matrix: allow_failures: - php: nightly - env: DB=pgsql POSTGRESQL_VERSION=11.0 + - php: 7.3 + env: DB=ibm_db2 - exclude: - - php: 7.1 - env: DB=sqlite - - php: 7.1 - env: DB=mysql - - php: 7.1 - env: DB=mysqli - - php: 7.2 - env: DB=sqlite - - php: 7.2 - env: DB=mysql - - php: 7.2 - env: DB=mysqli +jobs: + allow_failures: + - php: nightly + - env: DB=pgsql POSTGRESQL_VERSION=11.0 + - php: 7.3 + env: DB=ibm_db2 include: - - stage: Test - php: 7.1 - env: DB=sqlite COVERAGE=yes - - - stage: Test - php: 7.1 - env: DB=mysql COVERAGE=yes - - - stage: Test - php: 7.1 - env: DB=mysqli COVERAGE=yes - +# BEGIN TEST BUILD MATRIX - DO NOT EDIT BELOW ▼▼▼ USE THE TRAVIS MATRIX BUILDER SCRIPT - stage: Test php: 7.1 env: DB=mysql MYSQL_VERSION=5.7 COVERAGE=yes sudo: required before_script: - bash ./tests/travis/install-mysql-5.7.sh + - stage: Test + php: 7.2 + env: DB=mysql - stage: Test php: 7.2 env: DB=mysql MYSQL_VERSION=5.7 @@ -107,13 +83,15 @@ jobs: sudo: required before_script: - bash ./tests/travis/install-mysql-5.7.sh - - stage: Test php: 7.1 env: DB=mysqli MYSQL_VERSION=5.7 COVERAGE=yes sudo: required before_script: - bash ./tests/travis/install-mysql-5.7.sh + - stage: Test + php: 7.2 + env: DB=mysqli - stage: Test php: 7.2 env: DB=mysqli MYSQL_VERSION=5.7 @@ -132,101 +110,84 @@ jobs: sudo: required before_script: - bash ./tests/travis/install-mysql-5.7.sh - - stage: Test php: 7.1 - env: DB=mariadb MARIADB_VERSION=10.0 COVERAGE=yes + env: DB=mariadb MARIADB_VERSION=10.3 COVERAGE=yes addons: - mariadb: 10.0 + mariadb: 10.3 - stage: Test php: 7.2 env: DB=mariadb MARIADB_VERSION=10.0 addons: mariadb: 10.0 - - stage: Test - php: nightly - env: DB=mariadb MARIADB_VERSION=10.0 - addons: - mariadb: 10.0 - - - stage: Test - php: 7.1 - env: DB=mariadb MARIADB_VERSION=10.1 COVERAGE=yes - addons: - mariadb: 10.1 - stage: Test php: 7.2 env: DB=mariadb MARIADB_VERSION=10.1 addons: mariadb: 10.1 - stage: Test - php: nightly - env: DB=mariadb MARIADB_VERSION=10.1 - addons: - mariadb: 10.1 - - - stage: Test - php: 7.1 - env: DB=mariadb MARIADB_VERSION=10.2 COVERAGE=yes + php: 7.2 + env: DB=mariadb MARIADB_VERSION=10.2 addons: mariadb: 10.2 - stage: Test php: 7.2 - env: DB=mariadb MARIADB_VERSION=10.2 + env: DB=mariadb MARIADB_VERSION=10.3 addons: - mariadb: 10.2 + mariadb: 10.3 + - stage: Test + php: 7.3 + env: DB=mariadb MARIADB_VERSION=10.3 + addons: + mariadb: 10.3 - stage: Test php: nightly - env: DB=mariadb MARIADB_VERSION=10.2 + env: DB=mariadb MARIADB_VERSION=10.3 addons: - mariadb: 10.2 - + mariadb: 10.3 - stage: Test php: 7.1 - env: DB=mariadb.mysqli MARIADB_VERSION=10.2 COVERAGE=yes + env: DB=mariadb.mysqli MARIADB_VERSION=10.3 COVERAGE=yes addons: - mariadb: 10.2 + mariadb: 10.3 - stage: Test php: 7.2 - env: DB=mariadb.mysqli MARIADB_VERSION=10.2 + env: DB=mariadb.mysqli MARIADB_VERSION=10.0 addons: - mariadb: 10.2 + mariadb: 10.0 - stage: Test - php: nightly + php: 7.2 + env: DB=mariadb.mysqli MARIADB_VERSION=10.1 + addons: + mariadb: 10.1 + - stage: Test + php: 7.2 env: DB=mariadb.mysqli MARIADB_VERSION=10.2 addons: mariadb: 10.2 - - stage: Test php: 7.2 - env: DB=mariadb MARIADB_VERSION=10.3 + env: DB=mariadb.mysqli MARIADB_VERSION=10.3 addons: - mariadb: 10.3 - + mariadb: 10.3 - stage: Test php: 7.3 - env: DB=mariadb MARIADB_VERSION=10.3 - addons: - mariadb: 10.3 - - - stage: Test - php: 7.2 env: DB=mariadb.mysqli MARIADB_VERSION=10.3 addons: - mariadb: 10.3 + mariadb: 10.3 - stage: Test - php: 7.3 + php: nightly env: DB=mariadb.mysqli MARIADB_VERSION=10.3 addons: - mariadb: 10.3 - + mariadb: 10.3 - stage: Test php: 7.1 - env: DB=pgsql POSTGRESQL_VERSION=9.2 COVERAGE=yes + env: DB=pgsql POSTGRESQL_VERSION=11.0 COVERAGE=yes + sudo: required services: - - postgresql - addons: - postgresql: "9.2" + - docker + before_script: + - bash ./tests/travis/install-postgres-11.sh - stage: Test php: 7.2 env: DB=pgsql POSTGRESQL_VERSION=9.2 @@ -234,21 +195,6 @@ jobs: - postgresql addons: postgresql: "9.2" - - stage: Test - php: nightly - env: DB=pgsql POSTGRESQL_VERSION=9.2 - services: - - postgresql - addons: - postgresql: "9.2" - - - stage: Test - php: 7.1 - env: DB=pgsql POSTGRESQL_VERSION=9.3 COVERAGE=yes - services: - - postgresql - addons: - postgresql: "9.3" - stage: Test php: 7.2 env: DB=pgsql POSTGRESQL_VERSION=9.3 @@ -256,21 +202,6 @@ jobs: - postgresql addons: postgresql: "9.3" - - stage: Test - php: nightly - env: DB=pgsql POSTGRESQL_VERSION=9.3 - services: - - postgresql - addons: - postgresql: "9.3" - - - stage: Test - php: 7.1 - env: DB=pgsql POSTGRESQL_VERSION=9.4 COVERAGE=yes - services: - - postgresql - addons: - postgresql: "9.4" - stage: Test php: 7.2 env: DB=pgsql POSTGRESQL_VERSION=9.4 @@ -278,21 +209,6 @@ jobs: - postgresql addons: postgresql: "9.4" - - stage: Test - php: nightly - env: DB=pgsql POSTGRESQL_VERSION=9.4 - services: - - postgresql - addons: - postgresql: "9.4" - - - stage: Test - php: 7.1 - env: DB=pgsql POSTGRESQL_VERSION=9.5 COVERAGE=yes - services: - - postgresql - addons: - postgresql: "9.5" - stage: Test php: 7.2 env: DB=pgsql POSTGRESQL_VERSION=9.5 @@ -300,21 +216,6 @@ jobs: - postgresql addons: postgresql: "9.5" - - stage: Test - php: nightly - env: DB=pgsql POSTGRESQL_VERSION=9.5 - services: - - postgresql - addons: - postgresql: "9.5" - - - stage: Test - php: 7.1 - env: DB=pgsql POSTGRESQL_VERSION=9.6 COVERAGE=yes - services: - - postgresql - addons: - postgresql: "9.6" - stage: Test php: 7.2 env: DB=pgsql POSTGRESQL_VERSION=9.6 @@ -322,24 +223,6 @@ jobs: - postgresql addons: postgresql: "9.6" - - stage: Test - php: nightly - env: DB=pgsql POSTGRESQL_VERSION=9.6 - services: - - postgresql - addons: - postgresql: "9.6" - - - stage: Test - php: 7.1 - env: DB=pgsql POSTGRESQL_VERSION=10.0 COVERAGE=yes - sudo: required - services: - - postgresql - addons: - postgresql: "9.6" - before_script: - - bash ./tests/travis/install-postgres-10.sh - stage: Test php: 7.2 env: DB=pgsql POSTGRESQL_VERSION=10.0 @@ -350,25 +233,6 @@ jobs: postgresql: "9.6" before_script: - bash ./tests/travis/install-postgres-10.sh - - stage: Test - php: nightly - env: DB=pgsql POSTGRESQL_VERSION=10.0 - sudo: required - services: - - postgresql - addons: - postgresql: "9.6" - before_script: - - bash ./tests/travis/install-postgres-10.sh - - - stage: Test - php: 7.1 - env: DB=pgsql POSTGRESQL_VERSION=11.0 - sudo: required - services: - - docker - before_script: - - bash ./tests/travis/install-postgres-11.sh - stage: Test php: 7.2 env: DB=pgsql POSTGRESQL_VERSION=11.0 @@ -393,14 +257,26 @@ jobs: - docker before_script: - bash ./tests/travis/install-postgres-11.sh - - stage: Test + php: 7.1 + env: DB=sqlite COVERAGE=yes + - stage: Test + php: 7.2 + env: DB=sqlite + - stage: Test + php: 7.3 + env: DB=sqlite + - stage: Test + php: nightly + env: DB=sqlite + - stage: Test + php: 7.1 env: DB=sqlsrv COVERAGE=yes sudo: required services: - docker before_script: - - bash ./tests/travis/install-mssql-$DB.sh + - bash ./tests/travis/install-mssql-sqlsrv.sh - bash ./tests/travis/install-mssql.sh - stage: Test php: 7.2 @@ -409,7 +285,7 @@ jobs: services: - docker before_script: - - bash ./tests/travis/install-mssql-$DB.sh + - bash ./tests/travis/install-mssql-sqlsrv.sh - bash ./tests/travis/install-mssql.sh - stage: Test php: 7.3 @@ -418,9 +294,17 @@ jobs: services: - docker before_script: - - bash ./tests/travis/install-mssql-$DB.sh + - bash ./tests/travis/install-mssql-sqlsrv.sh + - bash ./tests/travis/install-mssql.sh + - stage: Test + php: nightly + env: DB=sqlsrv + sudo: required + services: + - docker + before_script: + - bash ./tests/travis/install-mssql-sqlsrv.sh - bash ./tests/travis/install-mssql.sh - - stage: Test php: 7.1 env: DB=pdo_sqlsrv COVERAGE=yes @@ -428,7 +312,7 @@ jobs: services: - docker before_script: - - bash ./tests/travis/install-mssql-$DB.sh + - bash ./tests/travis/install-mssql-pdo_sqlsrv.sh - bash ./tests/travis/install-mssql.sh - stage: Test php: 7.2 @@ -437,7 +321,7 @@ jobs: services: - docker before_script: - - bash ./tests/travis/install-mssql-$DB.sh + - bash ./tests/travis/install-mssql-pdo_sqlsrv.sh - bash ./tests/travis/install-mssql.sh - stage: Test php: 7.3 @@ -446,17 +330,26 @@ jobs: services: - docker before_script: - - bash ./tests/travis/install-mssql-$DB.sh + - bash ./tests/travis/install-mssql-pdo_sqlsrv.sh - bash ./tests/travis/install-mssql.sh - - stage: Test + php: nightly + env: DB=pdo_sqlsrv + sudo: required + services: + - docker + before_script: + - bash ./tests/travis/install-mssql-pdo_sqlsrv.sh + - bash ./tests/travis/install-mssql.sh + - stage: Test + php: 7.1 env: DB=ibm_db2 COVERAGE=yes sudo: required services: - docker before_script: - bash ./tests/travis/install-db2.sh - - bash ./tests/travis/install-db2-$DB.sh + - bash ./tests/travis/install-db2-ibm_db2.sh - stage: Test php: 7.2 env: DB=ibm_db2 @@ -465,7 +358,26 @@ jobs: - docker before_script: - bash ./tests/travis/install-db2.sh - - bash ./tests/travis/install-db2-$DB.sh + - bash ./tests/travis/install-db2-ibm_db2.sh + - stage: Test + php: 7.3 + env: DB=ibm_db2 + sudo: required + services: + - docker + before_script: + - bash ./tests/travis/install-db2.sh + - bash ./tests/travis/install-db2-ibm_db2.sh + - stage: Test + php: nightly + env: DB=ibm_db2 + sudo: required + services: + - docker + before_script: + - bash ./tests/travis/install-db2.sh + - bash ./tests/travis/install-db2-ibm_db2.sh +# END TEST BUILD MATRIX - DO NOT EDIT ABOVE ▲▲▲ - stage: Test php: 7.1 diff --git a/travis-matrix-builder.php b/travis-matrix-builder.php new file mode 100644 index 00000000000..3ab74c33175 --- /dev/null +++ b/travis-matrix-builder.php @@ -0,0 +1,314 @@ + [ + 'MYSQL_VERSION' => [ + null, + '5.7' + ] + ], + 'mysqli' => [ + 'MYSQL_VERSION' => [ + null, + '5.7' + ] + ], + 'mariadb' => [ + 'MARIADB_VERSION' => [ + '10.0', + '10.1', + '10.2', + '10.3', + ] + ], + 'mariadb.mysqli' => [ + 'MARIADB_VERSION' => [ + '10.0', + '10.1', + '10.2', + '10.3', + ] + ], + 'pgsql' => [ + 'POSTGRESQL_VERSION' => [ + '9.2', + '9.3', + '9.4', + '9.5', + '9.6', + '10.0', + '11.0' + ] + ], + 'sqlite' => [], + 'sqlsrv' => [], + 'pdo_sqlsrv' => [], + 'ibm_db2' => [], +]; + +/** + * The additional Travis job parameters for specific environment variables. + * The keys are expected to be single KEY=VALUE pairs to be matched against the env string built in the matrix. + */ + +$additionalJobParams = [ + 'MYSQL_VERSION=5.7' => [ + 'sudo' => 'required', + 'before_script' => ['bash ./tests/travis/install-mysql-5.7.sh'] + ], + 'POSTGRESQL_VERSION=10.0' => [ + 'sudo' => 'required', + 'services' => ['postgresql'], + 'addons' => ['postgresql' => '"9.6"'], + 'before_script' => ['bash ./tests/travis/install-postgres-10.sh'] + ], + 'POSTGRESQL_VERSION=11.0' => [ + 'sudo' => 'required', + 'services' => ['docker'], + 'before_script' => ['bash ./tests/travis/install-postgres-11.sh'] + ], + 'DB=sqlsrv' => [ + 'sudo' => 'required', + 'services' => ['docker'], + 'before_script' => [ + 'bash ./tests/travis/install-mssql-sqlsrv.sh', + 'bash ./tests/travis/install-mssql.sh' + ] + ], + 'DB=pdo_sqlsrv' => [ + 'sudo' => 'required', + 'services' => ['docker'], + 'before_script' => [ + 'bash ./tests/travis/install-mssql-pdo_sqlsrv.sh', + 'bash ./tests/travis/install-mssql.sh' + ] + ], + 'DB=ibm_db2' => [ + 'sudo' => 'required', + 'services' => ['docker'], + 'before_script' => [ + 'bash ./tests/travis/install-db2.sh', + 'bash ./tests/travis/install-db2-ibm_db2.sh' + ] + ] +]; + +foreach (['10.0', '10.1', '10.2', '10.3'] as $mariadbVersion) { + $additionalJobParams['MARIADB_VERSION=' . $mariadbVersion] = [ + 'addons' => ['mariadb' => $mariadbVersion], + ]; +} + +foreach (['9.2', '9.3', '9.4', '9.5', '9.6'] as $pgsqlVersion) { + $additionalJobParams['POSTGRESQL_VERSION=' . $pgsqlVersion] = [ + 'services' => ['postgresql'], + 'addons' => ['postgresql' => '"' . $pgsqlVersion . '"'], + ]; +} + + +/* Generate jobs */ + +$jobs = []; + +foreach ($dbs as $db => $versions) { + if (empty($versions)) { + $baseEnvs = [[]]; + } elseif (count($versions) === 1) { + $baseEnvs = []; + + foreach ($versions as $versionEnvName => $versionValues) { // single iteration + foreach ($versionValues as $versionValue) { + if ($versionValue === null) { + $baseEnvs[] = []; + } else { + $baseEnvs[] = [$versionEnvName => $versionValue]; + } + } + } + } else { + echo "Error: this script does not currently support multiple environment variables per database driver.\n"; + exit(1); + } + + foreach ($phpVersions as $phpVersion) { + foreach ($baseEnvs as $baseEnvKey => $baseEnv) { + $env = ['DB' => $db]; + + $isLatestVersion = ($baseEnvKey === count($baseEnvs) - 1); + + foreach ($baseEnv as $envName => $envValue) { // at most one iteration + $env[$envName] = $envValue; + } + + if ($phpVersion !== $latestStablePhpVersion && ! $isLatestVersion) { + // not the latest stable PHP version: only test the latest platform version + continue; + } + + if ($phpVersion === $coveragePhpVersion) { + $env['COVERAGE'] = 'yes'; + } + + $env = envArrayToString($env); + + $job = [ + 'stage' => 'Test', + 'php' => $phpVersion, + 'env' => $env + ]; + + foreach ($additionalJobParams as $jobEnvKeyValuePair => $jobParams) { + if (strpos($env, $jobEnvKeyValuePair) !== false) { + $job += $jobParams; + } + } + + $jobs[] = $job; + } + } +} + + +/* Write jobs to the Travis config file in YAML format */ + +$travisYAML = file_get_contents($travisConfigFileName); + +if ($travisYAML === false) { + echo "Error: could not read Travis config file.\n"; + exit(1); +} + +$startPos = strpos($travisYAML, $beginBuildMatrixString); + +if ($startPos === false) { + echo "Error: could not find the $beginBuildMatrixString string in the Travis config file.\n"; + exit(1); +} + +$startPos = strpos($travisYAML, "\n", $startPos); + +if ($startPos === false) { + echo "Error: no further content after the $beginBuildMatrixString line.\n"; + exit(1); +} + +$endPos = strpos($travisYAML, $endBuildMatrixString, $startPos); + +if ($endPos === false) { + echo "Error: could not find the $endBuildMatrixString string in the Travis config file.\n"; + exit(1); +} + +$resultYAML = substr($travisYAML, 0, $startPos + 1); +$resultYAML .= arrayToYAML($jobs, 2); +$resultYAML .= substr($travisYAML, $endPos); + +$result = file_put_contents($travisConfigFileName, $resultYAML); + +if ($result === false) { + echo "Error: could not write the $travisConfigFileName file.\n"; + exit(1); +} + +echo "Successfully written the $travisConfigFileName file.\n"; + + +/* Utility functions */ + +function envArrayToString(array $env) : string +{ + $result = []; + + foreach ($env as $key => $value) { + $result[] = "$key=$value"; + } + + return implode(' ', $result); +} + +function arrayToYAML(array $array, int $level = 0, $indentFirst = true) : string +{ + $result = ''; + + $first = true; + + foreach ($array as $key => $value) { + if (! ($first && ! $indentFirst)) { + $result .= str_repeat(' ', $level * 2); + } + + if (is_int($key)) { + $result .= '- '; + } else { + $result .= $key . ': '; + } + + if (is_array($value)) { + if (! is_int($key)) { + $result .= "\n"; + } + + $result .= arrayToYAML($value, $level + 1, ! is_int($key)); + } else { + $result .= $value . "\n"; + } + + $first = false; + } + + return $result; +}