feat: add BranchStrategy class

Mirrors company BasePipeline pattern. Static methods determine
what pipeline stages run per branch:
- PR-*: test only
- feature/*: test + build/push + helm bump + git push
- develop/main/release/hotfix: test + build/push only

imageTag() returns branch-appropriate tag format:
release/x.y.z -> x.y.z, others -> <prefix>-<random8>
This commit is contained in:
2026-04-26 13:55:58 +07:00
parent 10c2f73587
commit 2e3a68421b

View File

@@ -0,0 +1,31 @@
package vn.fireflylab.pipeline
class BranchStrategy implements Serializable {
static boolean isPR(String branch) { branch ==~ /^PR-\d+$/ }
static boolean isFeature(String branch) { branch ==~ /^feature\/.+/ }
static boolean isDevelop(String branch) { branch == 'develop' }
static boolean isMain(String branch) { branch == 'main' }
static boolean isRelease(String branch) { branch ==~ /^release\/\d+\.\d+\.\d+$/ }
static boolean isHotfix(String branch) { branch ==~ /^hotfix\/.+/ }
// Build + push on all branches except PRs
static boolean shouldBuildImage(String branch) {
return !isPR(branch)
}
// Helm bump + git commit/push only on feature branches
static boolean shouldBumpChart(String branch) {
return isFeature(branch)
}
static String imageTag(String branch) {
if (isRelease(branch)) return branch.replaceFirst('release/', '')
def shortId = UUID.randomUUID().toString().take(8)
if (isMain(branch)) return "main-${shortId}"
if (isDevelop(branch)) return "dev-${shortId}"
if (isHotfix(branch)) return "hotfix-${shortId}"
// feature/* and anything else: sanitize branch name + random suffix
return "${branch.replaceAll('[^a-zA-Z0-9._-]', '-')}-${shortId}"
}
}