addon/Jenkinsfile
Roman Jaroš ce3d4ed426
All checks were successful
forgejo/Czech Quests/addon/pipeline/head This commit looks good
Remove GAME parameter from Jenkins and set same versions
2025-03-08 16:31:11 +01:00

104 lines
No EOL
2.5 KiB
Groovy

@Library('jenkins-lib')
import dev.romanjaros.jenkins.utils.ReleaseUtils
def SKIP = "skip"
properties([parameters([
choice(
name: 'RELEASE',
choices: [SKIP, 'patch', 'minor', 'major'],
description: 'Next new version'
),
])])
def outputFolder = "CzechQuests"
def tocFiles = [
"classic_era": "CzechQuests_Vanilla.toc",
"retail" : "CzechQuests_Mainline.toc"
]
def readToCVersion = { ->
return sh(
script: "grep '## Version:' ${tocFiles['classic_era']} | cut -d ' ' -f 3",
returnStdout: true
).trim()
}
def writeToCVersion = { String tocFile, String current, String next ->
def content = readFile(file: tocFile)
content = content.replace("## Version: $current", "## Version: $next")
writeFile(file: tocFile, text: content)
}
def increaseVersion = { ->
def currentVersion = readToCVersion()
def newVersion = ReleaseUtils.increaseVersion(currentVersion, params.RELEASE)
writeToCVersion(tocFiles['classic_era'], currentVersion, "v$newVersion")
writeToCVersion(tocFiles['retail'], currentVersion, "v$newVersion")
}
def createZipFile = { String game ->
def tocFile = tocFiles[game]
def version = readToCVersion()
// prepare output folder
sh "mkdir -p $outputFolder"
// copy toc file
sh "cp $tocFile $outputFolder"
// copy files
sh "find . -name '*.lua' -exec rsync -av {} $outputFolder \\;"
sh "find . -name '*.tga' -exec rsync -av {} $outputFolder \\;"
sh "find . -name '*.ttf' -exec rsync -av {} $outputFolder \\;"
// create zip
def zipFileName = "czech-quests-$game-v${version}.zip"
zip zipFile: zipFileName, archive: false, dir: outputFolder
// remove build folder
sh "rm -r $outputFolder"
}
def pushToGit = { ->
def version = readToCVersion()
def tag = "v$version"
sh "git checkout ${BRANCH_NAME}"
sh "git add *.toc"
sh "git commit -m 'Release $tag'"
sh "git push"
sh "git tag $tag"
sh "git push origin $tag"
}
def uploadToForgejo = { ->
def version = readToCVersion()
ForgejoRelease('czech-quests', 'addon', version)
}
MasterJob [:], { ->
def version = params.RELEASE
if (version == SKIP) {
currentBuild.result = 'SUCCESS'
return
}
checkout scm
stageWhen("version") {
increaseVersion()
}
stageWhen('build') {
createZipFile("classic_era")
createZipFile("retail")
forgejoGit()
pushToGit()
}
stageWhen('release') {
uploadToForgejo()
}
}