/*
 * 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 gitClone() {
	cleanWs()
	def scmVars = git url: 'https://github.com/richardg867/86Box.git',
					  branch: 'cleanup30'
	env.GIT_COMMIT = scmVars.GIT_COMMIT
}

def windowsBuild() {
	bat 'C:\\msys64\\msys2_shell.cmd -msys2 -defterm -here -no-start -c "exec .ci/build.sh"'
}

def unixBuild() {
	sh 'chmod u+x .ci/build.sh && .ci/build.sh'
}

def saveArtifacts() {
	archiveArtifacts artifacts: "${env.JOB_BASE_NAME}-*"
}

pipeline {
	agent any

	parameters {
		choice(name: 'BUILD_TYPE',
		       choices: ['beta', 'none', 'alpha', 'beta', 'release'], // duplicated on purpose, first is default
		       description: 'Build type to pass on to CMake. This may affect the UI icon and feature set.')
	}

	stages {
		stage('Build Windows') {
			steps {
				node('windows') {
					gitClone()
					windowsBuild()
					saveArtifacts()
				}
			}
		}

		stage('Build Linux') {
			steps {
				node('debian') {
					gitClone()
					unixBuild()
					saveArtifacts()
				}
			}
		}
	}
}
