Files
86Box-fork/.ci/Jenkinsfile
2021-11-18 20:32:23 -03:00

258 lines
6.8 KiB
Groovy

/*
* 86Box A hypervisor and IBM PC system emulator that specializes in
* running old operating systems and software designed for IBM
* PC systems and compatibles from 1981 through fairly recent
* system designs based on the PCI bus.
*
* This file is part of the 86Box distribution.
*
* Jenkins build pipeline definition.
*
*
*
* Authors: RichardG, <richardg867@gmail.com>
*
* Copyright 2021 RichardG.
*/
def osArchs = [
'Windows': ['32', '64'],
'Linux': ['x86', 'x86_64', 'arm32', 'arm64']
]
def archNames = [
'32': 'x86 (32-bit)',
'x86': 'x86 (32-bit)',
'64': 'x64 (64-bit)',
'x86_64': 'x64 (64-bit)',
'arm32': 'ARM (32-bit)',
'arm64': 'ARM (64-bit)'
]
def dynarecNames = [
'ODR': 'Old Recompiler (recommended)',
'NDR': 'New Recompiler (beta)',
'NoDR': 'No Dynamic Recompiler'
]
def dynarecArchs = [
'32': ['ODR', 'NDR'],
'x86': ['ODR', 'NDR'],
'64': ['ODR', 'NDR'],
'x86_64': ['ODR', 'NDR'],
'arm32': ['NDR'],
'ARM32': ['NDR'],
'arm64': ['NDR'],
'ARM64': ['NDR']
]
def dynarecFlags = [
'ODR': '-D NEW_DYNAREC=OFF',
'NDR': '-D NEW_DYNAREC=ON',
'NoDR': '-D DYNAREC=OFF'
]
def dynarecSlugs = [
'ODR': '',
'NDR': '-NDR',
'NoDR': ''
]
def presets = [
'Regular',
'Debug'
]
def presetSlugs = [
'Regular': '',
'Debug': '-Debug',
'Dev': '-Dev'
]
def presetFlags = [
'Regular': '--preset=regular',
'Debug': '--preset=debug',
'Dev': '--preset=experimental -D VNC=OFF'
]
def anyFailure = false
def gitClone() {
if (env.GIT_COMMIT == null)
env.GIT_COMMIT = 'master'
println "[-] Using git tag [${env.GIT_COMMIT}]"
def scmVars = checkout scm: [$class: 'GitSCM',
branches: [[name: env.GIT_COMMIT]],
userRemoteConfigs: [[url: 'https://github.com/86Box/86Box.git']]]
env.GIT_COMMIT = scmVars.GIT_COMMIT
}
def removeDir(dir) {
if (isUnix())
sh "rm -rf \"$dir\" || exit 0"
else
bat "if exist \"$dir\" rd /s /q \"$dir\" & exit /b 0"
}
def runBuild(args) {
if (isUnix())
sh "chmod u+x \"$WORKSPACE/.ci/build.sh\" && exec \"$WORKSPACE/.ci/build.sh\" $args"
else
bat "C:\\msys64\\msys2_shell.cmd -msys2 -defterm -here -no-start -c 'exec \"\$(cygpath -u \\'%WORKSPACE%\\')\"/.ci/build.sh $args'"
}
pipeline {
agent none
parameters {
string(name: 'BUILD_TYPE',
defaultValue: 'beta', /* !!! CHANGE HERE !!! for build type */
description: "Build type to pass on to CMake. Don't change this, you should instead change the default value on .ci/Jenkinsfile")
}
environment {
DISCORD_WEBHOOK_URL = credentials('discord-webhook-url')
}
stages {
stage('Source Tarball') {
agent none
steps {
script {
/* Run a dummy git clone on any node to try and save the latest commit regardless of executor status.
This avoids a timing issue where HEAD changes between polling and the nodes being available below.
I talked to a few people, and we reached the conclusion that reading the polled commit from within
the pipeline is not really possible (maybe short of switching to a multi-branch pipeline), so we
have to live with this hack, which shortens but doesn't fully eliminate the timing issue's window. */
node {
/* Ignore exceptions as this is not really critical. */
try {
gitClone()
} catch (e) {}
try {
cleanWs()
} catch (e) {}
}
/* Create source tarball. */
node('Linux') {
try {
/* Run git clone. */
gitClone()
/* Switch to temp directory. */
dir(WORKSPACE_TMP) {
/* Clean output directory of potential stale old builds. */
removeDir('output')
/* Switch to output directory. */
dir('output') {
/* Run source tarball creation process. */
def packageName = "${env.JOB_BASE_NAME}-Source-b${env.BUILD_NUMBER}"
runBuild("-s \"$packageName\"")
/* Archive resulting artifacts. */
archiveArtifacts artifacts: "$packageName*"
}
}
} catch (e) {
/* Mark that a failure occurred. */
anyFailure = true
/* Force this stage to fail. */
catchError(buildResult: 'SUCCESS', stageResult: 'FAILURE') {
throw e;
}
}
}
/* Build here to avoid creating a redundant parent stage on the stage view. */
osArchs.each { os, thisOsArchs ->
thisOsArchs.each { arch ->
def thisArchDynarecs = dynarecArchs[arch]
if (!thisArchDynarecs)
thisArchDynarecs = ['NoDR']
thisArchDynarecs.each { dynarec ->
presets.each { preset ->
node(os) {
stage("$os $arch $dynarec $preset") {
try {
/* Run git clone. */
gitClone()
/* Switch to temp directory. */
dir(WORKSPACE_TMP) {
/* Clean output directory of potential stale old builds. */
removeDir('output')
/* Switch to output directory. */
dir('output') {
def packageName = "${env.JOB_BASE_NAME}${dynarecSlugs[dynarec]}${presetSlugs[preset]}-$os-$arch-b${env.BUILD_NUMBER}"
dir(dynarecNames[dynarec]) {
dir("$os - ${archNames[arch]}") {
/* Run build process. */
runBuild("-b \"$packageName\" \"$arch\" ${presetFlags[preset]} ${dynarecFlags[dynarec]} -D \"BUILD_TYPE=$BUILD_TYPE\" -D \"EMU_BUILD=build ${env.BUILD_NUMBER}\" -D \"EMU_BUILD_NUM=${env.BUILD_NUMBER}\"")
}
}
/* Archive resulting artifacts. */
archiveArtifacts artifacts: "**/**/$packageName*"
}
}
} catch (e) {
/* Mark that a failure occurred. */
anyFailure = true
/* Force this stage to fail. */
catchError(buildResult: 'SUCCESS', stageResult: 'FAILURE') {
throw e;
}
}
}
}
}
}
}
}
}
}
}
}
post {
always {
script {
if (anyFailure) {
println "[!] Failing build because a build stage failed"
currentBuild.result = 'FAILURE'
}
if (!env.JOB_BASE_NAME.contains("TestBuildPleaseIgnore")) {
try {
/* Notify Discord. */
def result = currentBuild.currentResult.toLowerCase()
discordSend webhookURL: DISCORD_WEBHOOK_URL,
title: "${env.JOB_BASE_NAME} #${env.BUILD_NUMBER}",
link: env.BUILD_URL,
result: currentBuild.currentResult,
description: "**Status:** ${result}\n\u2060", /* word joiner character forces a blank line */
enableArtifactsList: false,
showChangeset: true
/* Notify IRC, which needs a node for whatever reason. */
node {
ircNotify()
}
} catch (e) {
/* Force this stage to fail. */
catchError(buildResult: currentBuild.result, stageResult: 'FAILURE') {
throw e;
}
}
}
}
}
}
}