diff --git a/jobs/phpunit/master/Jenkinsfile b/jobs/phpunit/master/Jenkinsfile deleted file mode 100644 index f7122abd8864b185b9c6fe3431bb9f45381b2bc9..0000000000000000000000000000000000000000 --- a/jobs/phpunit/master/Jenkinsfile +++ /dev/null @@ -1,14 +0,0 @@ -@Library('ci') - -def branch = new org.moodle.ci.branches.Master() -def Util = new org.moodle.ci.Util() -def Repo = new org.moodle.ci.repositories.integration() - -Util.runJob( - "phpunit", - Repo.getUrl(), - Repo.getBranch(), - Util.getDefaultRunCombinations(branch), - false, - false -); diff --git a/src/org/moodle/ci/Target.groovy b/src/org/moodle/ci/Target.groovy deleted file mode 100644 index 6e323ad3c90d295891979ee1bc95c128e200b64e..0000000000000000000000000000000000000000 --- a/src/org/moodle/ci/Target.groovy +++ /dev/null @@ -1,9 +0,0 @@ -package org.moodle.ci; - -class Target { - protected String url - - protected String credentialsId - - protected String branch -} diff --git a/src/org/moodle/ci/Task.groovy b/src/org/moodle/ci/Task.groovy new file mode 100644 index 0000000000000000000000000000000000000000..8c5aef7ead1b647d8fa418e613ad0e9fef159359 --- /dev/null +++ b/src/org/moodle/ci/Task.groovy @@ -0,0 +1,85 @@ +package org.moodle.ci; + +import org.moodle.ci.repositories.Repository +import org.moodle.ci.versions.Version + +class Task { + protected Repository repository + + protected Version moodleVersion + + protected String url + + protected String credentialsId + + protected String branch + + protected String database = 'pgsql' + + protected String phpVersion + + protected String task = 'phpunit' + + protected Boolean notify = false + + protected String pathToRunner + + def getUrl() { + if (url) { + return url + } else if (repository) { + return repository.url + } + + throw new Exception('No repository specified.') + } + + def getCredentialsId() { + if (credentialsId) { + return credentialsId + } else if (repository && repository.credentialsId) { + return repository.credentialsId + } + + return null + } + + def getBranch() { + if (branch) { + return branch + } else if (moodleVersion) { + return moodleVersion.defaultBranch + } + + throw new Exception('No Pull URL set') + } + + def getPhpVersion() { + if (phpVersion) { + return phpVersion + } else if (moodleVersion) { + return moodleVersion.getHighestSupportedVersion() + } + + throw new Exception("I don't know what PHP Version to test against") + } + + def getPathToRunner() { + if (pathToRunner) { + if (!fileExists(pathToRunner)) { + throw new Exception("Unable to find job runner at ${pathToRunner}") + } + + return pathToRunner + } else if (moodleVersion) { + runner = "${env.PATHTORUNNER}/${moodleVersion.name}/run.sh" + if (!fileExists(runner)) { + runner = "${env.PATHTORUNNER}/master/run.sh" + } + + return runner + } + + throw new Exception("Unable to determine path to script runner. Either a moodleVersion or a pathToRunner must be provided") + } +} diff --git a/src/org/moodle/ci/Util.groovy b/src/org/moodle/ci/Util.groovy deleted file mode 100644 index a6b0a559d6ba7d2ce25dec101870addb8bae415c..0000000000000000000000000000000000000000 --- a/src/org/moodle/ci/Util.groovy +++ /dev/null @@ -1,91 +0,0 @@ -package org.moodle.ci; - -def getDefaultRunCombinations(branch) { - def php = branch.getPhpVersions() - def db = branch.getDatabases() - def combinations = [:] - - for (int i = 0; i < db.size(); i++) { - combinations[i] = [ - "db": db[i], - "php": php[php.size() - 1] - ] - } - - return combinations; -} - -def getHighestSupportedVersion(branch) { - return branch[branch.size() - 1] -} - -def getLowestSupportedVersion(branch) { - return branch[0] -} - -def runTask( - String task, - String repo, - String branch, - String phpversion, - String database, - Boolean notify, - Boolean publish - ) { - - node('docker') { - stage("Git Checkout") { - echo "Starting ${task} on ${phpversion}/${database} from {$repo} ${branch}" - - checkout( - [ - $class: 'GitSCM', - branches: [ - [ - name: "${branch}" - ] - ], - doGenerateSubmoduleConfigurations: false, - extensions: [ - [ - $class: 'CloneOption', - depth: 0, - noTags: false, - reference: "${env.HOME}/caches/integration.git", - shallow: false - ], - [ - $class: 'RelativeTargetDirectory', - relativeTargetDir: 'moodle' - ] - ], - submoduleCfg: [], - userRemoteConfigs: [ - [ - url: "${repo}" - ] - ] - ] - ) - } - - stage("Run ${task}") { - withEnv([ - "PHP_VERSION=${phpversion}", - "DBTYPE=${database}", - "TASK=${task}" - ]) { - sh '$HOME/scripts/runner/master/run.sh' - } - } - - stage("Post") { - junit allowEmptyResults: true, testResults: '$BUILD_ID/*.junit/*.xml,$BUILD_ID/*.junit' - archiveArtifacts allowEmptyArchive: true, artifacts: '$BUILD_ID/**' - cleanWs deleteDirs: true, notFailBuild: true - } - } -} - - -return this; diff --git a/src/org/moodle/ci/branches/Master.groovy b/src/org/moodle/ci/versions/Master.groovy similarity index 76% rename from src/org/moodle/ci/branches/Master.groovy rename to src/org/moodle/ci/versions/Master.groovy index e92ba763994ac6de006d4c7ce7bc6b4d9189b10f..b535afbfbec9fdf83fa6f7622208fa7317e767f6 100644 --- a/src/org/moodle/ci/branches/Master.groovy +++ b/src/org/moodle/ci/versions/Master.groovy @@ -1,7 +1,8 @@ -package org.moodle.ci.branches; +package org.moodle.ci.versions; -class Master extends Branch { +class Master extends Version { Master() { + this.name = "master" this.defaultBranch = "master" this.supportedPHPVersions = [ "7.0", diff --git a/src/org/moodle/ci/branches/Branch.groovy b/src/org/moodle/ci/versions/Version.groovy similarity index 88% rename from src/org/moodle/ci/branches/Branch.groovy rename to src/org/moodle/ci/versions/Version.groovy index 9a0ac4b34d0622b362149e2f3ad39cd854455c6a..e6aaaf2935c023dcf800df02a2e368e3d9d6871e 100644 --- a/src/org/moodle/ci/branches/Branch.groovy +++ b/src/org/moodle/ci/versions/Version.groovy @@ -1,6 +1,8 @@ -package org.moodle.ci.branches; +package org.moodle.ci.versions; + +class Version { + protected String name -class Branch { protected String defaultBranch protected String[] supportedPHPVersions diff --git a/vars/baseCheckout.groovy b/vars/baseCheckout.groovy deleted file mode 100644 index 5ec31399fd3c4598447c451d604f5533e593a29d..0000000000000000000000000000000000000000 --- a/vars/baseCheckout.groovy +++ /dev/null @@ -1,41 +0,0 @@ -def call() { - pipeline { - agent { - label 'docker' - } - - stages { - stage("Git Checkout") { - steps { - checkout( - [ - $class: 'GitSCM', - branches: [ - [ - name: "master" - ] - ], - doGenerateSubmoduleConfigurations: false, - extensions: [ - [ - $class: 'CloneOption', - depth: 0, - noTags: false, - shallow: true - ] - ], - submoduleCfg: [], - userRemoteConfigs: [ - [ - url: "https://github.com/moodle/moodle.git" - ] - ] - ] - ) - } - } - } - } -} - -return this diff --git a/vars/runTask.groovy b/vars/runTask.groovy index 98a12ffb820cb4418dcd4cb7701f580da6786bf5..7a6c0bafc966c088b6cb2730577eb54cf9892ac1 100644 --- a/vars/runTask.groovy +++ b/vars/runTask.groovy @@ -1,13 +1,13 @@ -def call(String task, org.moodle.ci.Target Target, String phpversion, String database, Boolean notify) { +def call(org.moodle.ci.Task task) { pipeline { agent { label 'docker' } environment { - PHP_VERSION = "${phpversion}" - DBTYPE = "${database}" - TESTTORUN = "${task}" + PHP_VERSION = "${task.phpVersion}" + DBTYPE = "${task.database}" + TESTTORUN = "${task.task}" PATHTORUNNER = "${HOME}/scripts/runner" } @@ -19,7 +19,7 @@ def call(String task, org.moodle.ci.Target Target, String phpversion, String dat $class: 'GitSCM', branches: [ [ - name: "${Target.branch}" + name: "${task.branch}" ] ], doGenerateSubmoduleConfigurations: false, @@ -39,8 +39,8 @@ def call(String task, org.moodle.ci.Target Target, String phpversion, String dat submoduleCfg: [], userRemoteConfigs: [ [ - url: "${Target.url}", - credentialsId: "${Target.credentialsId}" + url: "${task.url}", + credentialsId: "${task.credentialsId}" ] ] ] @@ -48,24 +48,9 @@ def call(String task, org.moodle.ci.Target Target, String phpversion, String dat } } - stage("Detect Moodle Version") { - steps { - script { - moodleversion = sh ( - script: 'grep "\\$branch" moodle/version.php | sed "s/^[^\']*\'\\([^\']*\\).*\$/\\1/"', - returnStdout: true - ).trim() - runner = "${env.PATHTORUNNER}/${moodleversion}" - if (!fileExists(runner)) { - runner = "${env.PATHTORUNNER}/master" - } - } - } - } - stage("Run Task") { steps { - sh "${runner}/run.sh" + sh task.pathToRunner } }