addon/Jenkinsfile
Roman Jaroš 53c5c1dc9f
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:16:27 +01:00

99 lines
No EOL
2.4 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: 'Release 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 createZipFile = { String game ->
def tocFile = tocFiles[game]
// 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()
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)
}
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('build') {
createZipFile("classic_era")
createZipFile("retail")
forgejoGit()
pushToGit()
}
stageWhen('release') {
uploadToForgejo()
}
}