addon/Jenkinsfile

99 lines
2.4 KiB
Text
Raw Normal View History

2025-03-08 09:08:16 +01:00
@Library('jenkins-lib')
2025-03-08 09:11:58 +01:00
import dev.romanjaros.jenkins.utils.ReleaseUtils
def SKIP = "skip"
properties([parameters([
choice(
name: 'RELEASE',
choices: [SKIP, 'patch', 'minor', 'major'],
2025-03-08 09:11:58 +01:00
description: 'Release new version'
),
])])
def outputFolder = "CzechQuests"
2025-03-08 09:08:16 +01:00
def tocFiles = [
2025-03-08 09:11:58 +01:00
"classic_era": "CzechQuests_Vanilla.toc",
"retail" : "CzechQuests_Mainline.toc"
2025-03-08 09:08:16 +01:00
]
def readToCVersion = { ->
2025-03-08 09:11:58 +01:00
return sh(
script: "grep '## Version:' ${tocFiles['classic_era']} | cut -d ' ' -f 3",
2025-03-08 09:11:58 +01:00
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)
}
2025-03-08 15:58:27 +01:00
def createZipFile = { String game ->
def tocFile = tocFiles[game]
2025-03-08 09:11:58 +01:00
// 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 \\;"
// get version
def currentVersion = readToCVersion()
2025-03-08 09:11:58 +01:00
def newVersion = ReleaseUtils.increaseVersion(currentVersion, params.RELEASE)
// create zip
def zipFileName = "czech-quests-$game-v${newVersion}.zip"
zip zipFile: zipFileName, archive: false, dir: outputFolder
// remove build folder
sh "rm -r $outputFolder"
// save version
writeToCVersion(tocFile, currentVersion, newVersion)
2025-03-08 15:58:27 +01:00
}
2025-03-08 09:11:58 +01:00
def pushToGit = { ->
def version = readToCVersion()
2025-03-08 15:58:27 +01:00
def tag = "v$version"
2025-03-08 09:11:58 +01:00
sh "git checkout ${BRANCH_NAME}"
2025-03-08 15:58:27 +01:00
sh "git add *.toc"
sh "git commit -m 'Release $tag'"
2025-03-08 09:11:58 +01:00
sh "git push"
2025-03-08 15:58:27 +01:00
sh "git tag $tag"
sh "git push origin $tag"
}
def uploadToForgejo = { ->
def version = readToCVersion()
2025-03-08 15:58:27 +01:00
ForgejoRelease('czech-quests', 'addon', version)
2025-03-08 09:11:58 +01:00
}
MasterJob [:], { ->
def version = params.RELEASE
if (version == SKIP) {
2025-03-08 09:11:58 +01:00
currentBuild.result = 'SUCCESS'
return
}
2025-03-08 09:08:16 +01:00
checkout scm
stageWhen('build') {
createZipFile("classic_era")
createZipFile("retail")
2025-03-08 15:58:27 +01:00
forgejoGit()
pushToGit()
2025-03-08 09:11:58 +01:00
}
2025-03-08 09:08:16 +01:00
2025-03-08 15:58:27 +01:00
stageWhen('release') {
uploadToForgejo()
2025-03-08 09:08:16 +01:00
}
}