We are trying to move CI from Jenkins to Github actions for a Maven project. Maven repositories allow to push a POM version exactly ONCE, unless the version ends in -SNAPSHOT.
So in our current flow we distinguish between push to develop, where we push to the Maven repository only if the project version ends with -SNAPSHOT and push to main where we only push to Maven if it NOT ends with -SNAPSHOT.
In Jenkins it looks like this:
stage("on Merge to develop") {
when {
anyOf {
branch "develop"
}
expression {
return env.POM_VERSION ==~ /.*-SNAPSHOT/
}
not {
changeRequest()
}
}
steps {
echo "======== Merge into Develop ========"
}
}
stage("on publish release (merge to main)") {
when {
anyOf {
branch "master"
branch "main"
}
not {
expression {
return env.POM_VERSION ==~ /.*-SNAPSHOT/
}
}
not {
changeRequest()
}
}
steps {
echo "======== Merge into Master & PUSH ========"
}
}
In GitHub actions, we know how to run an action on a specific branch, but how do we:
- get the POM version into an env (or other variable)?
- conditionally run the step based on the POM version?
Of course - if there is a better approach, we remodel our flow