Commit be34b4d3 authored by Andrew Nicols's avatar Andrew Nicols

Major refactor

parent 74e90d7a
@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
);
package org.moodle.ci;
class Target {
protected String url
protected String credentialsId
protected String branch
}
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")
}
}
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;
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",
......
package org.moodle.ci.branches;
package org.moodle.ci.versions;
class Version {
protected String name
class Branch {
protected String defaultBranch
protected String[] supportedPHPVersions
......
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
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
}
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment