Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing an error when reimplementing from "Deploy to D" to WIP, it was using a release branch but trying to commit master branch #951

Merged
merged 6 commits into from
Oct 20, 2022
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Changelog

## Unreleased
- Fixing an error when reimplementing from Deploy to D to WIP, it was using a release branch but trying to commit master branch ([#951](https://github.com/opendevstack/ods-jenkins-shared-library/pull/951))
- Prevent Jenkins nonCPS error after reporting bug ([#776](https://github.com/opendevstack/ods-jenkins-shared-library/pull/776))
- Fixed the Developer Preview fails because "Duplicated Tests"
- Throw exception when two coded tests are linked to the same test issue (https://github.com/opendevstack/ods-jenkins-shared-library/pull/737)
Expand Down
4 changes: 2 additions & 2 deletions src/org/ods/orchestration/FinalizeStage.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ class FinalizeStage extends Stage {
messageToCommit
)

if (project.isWorkInProgress) {
if (project.gitReleaseBranch == MASTER_BRANCH) {
git.pushRef(MASTER_BRANCH)
} else {
// We don't need to merge, we simply commit the env file.
Expand All @@ -263,7 +263,7 @@ class FinalizeStage extends Stage {
)
git.pushRef(MASTER_BRANCH)
git.switchToExistingBranch(project.gitReleaseBranch)
if (!git.remoteTagExists(project.targetTag)) {
if (!project.isWorkInProgress && !git.remoteTagExists(project.targetTag)) {
git.createTag(project.targetTag)
}
// To overwrite the existing tag (if redeploy)
Expand Down
128 changes: 128 additions & 0 deletions test/groovy/org/ods/orchestration/FinalizeStageSpec.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
package org.ods.orchestration

import org.ods.PipelineScript
import org.ods.orchestration.scheduler.LeVADocumentScheduler
import org.ods.orchestration.usecase.JiraUseCase
import org.ods.orchestration.util.MROPipelineUtil
import org.ods.orchestration.util.Project
import org.ods.services.GitService
import org.ods.services.ServiceRegistry
import org.ods.util.ILogger
import org.ods.util.IPipelineSteps
import org.ods.util.Logger
import org.ods.util.PipelineSteps
import util.SpecHelper

import static util.FixtureHelper.createProject

class FinalizeStageSpec extends SpecHelper {
Project project
FinalizeStage finalStage
IPipelineSteps steps
PipelineScript script
MROPipelineUtil util
JiraUseCase jira
GitService gitService
LeVADocumentScheduler levaDocScheduler
ILogger logger

def setup() {
script = new PipelineScript()
steps = Mock(PipelineSteps)
levaDocScheduler = Mock(LeVADocumentScheduler)
project = Spy(createProject())
util = Mock(MROPipelineUtil)
gitService = Mock(GitService)
jira = Mock(JiraUseCase)
logger = new Logger(script, true)
createService()
for (repo in project.data.metadata.repositories) {
repo.data.git = [:]
repo.data.git.createdExecutionCommit = 'd240853866f20fc3e536cb3bca86c86c54b723ce'

}
project.gitData.createdExecutionCommit = 'd240853866f20fc3e536cb3bca86c86c54b723ce'
finalStage = Spy(new FinalizeStage(script, project, project.data.metadata.repositories))
}

ServiceRegistry createService() {
def registry = ServiceRegistry.instance

registry.add(PipelineSteps, steps)
registry.add(MROPipelineUtil, util)
registry.add(JiraUseCase, jira)
registry.add(Logger, logger)

return registry
}

def "pushToMasterWhenWIPandNoReleaseBranch"(){
given:
Map buildParams = [ : ]
buildParams.version = "WIP"
buildParams.changeId = "1.0.0"
buildParams.targetEnvironmentToken = "D"
project.buildParams.version = 'WIP'
project.setGitReleaseBranch('master')

when:
finalStage.recordAndPushEnvStateForReleaseManager(steps, logger, gitService)

then:
1 * gitService.pushRef('master')
}

def "pushToReleaseAndMasterWhenWipAndReleaseBranch"(){
given:
Map buildParams = [ : ]
buildParams.version = "WIP"
buildParams.changeId = "1.0.0"
buildParams.targetEnvironmentToken = "D"
project.buildParams.version = "WIP"
project.setGitReleaseBranch('release/1.0.0')

when:
finalStage.recordAndPushEnvStateForReleaseManager(steps, logger, gitService)

then:
1 * gitService.pushRef('master')
0 * gitService.createTag(project.targetTag)
1 * gitService.pushForceBranchWithTags(project.gitReleaseBranch)
}

def "pushToReleaseAndTag"(){
given:
Map buildParams = [ : ]
buildParams.version = "1.0.0"
buildParams.changeId = "1.0.0"
buildParams.targetEnvironmentToken = "D"
project.gitData.targetTag = "1.0.0"
gitService.remoteTagExists(project.targetTag) >> false

when:
finalStage.recordAndPushEnvStateForReleaseManager(steps, logger, gitService)

then:
1 * gitService.pushRef('master')
1 * gitService.createTag(project.targetTag)
1 * gitService.pushForceBranchWithTags(project.gitReleaseBranch)
}

def "pushToReleaseWithExistingTag"(){
given:
Map buildParams = [ : ]
buildParams.version = "1.0.0"
buildParams.changeId = "1.0.0"
buildParams.targetEnvironmentToken = "D"
project.gitData.targetTag = "1.0.0"
gitService.remoteTagExists(project.targetTag) >> true

when:
finalStage.recordAndPushEnvStateForReleaseManager(steps, logger, gitService)

then:
1 * gitService.pushRef('master')
0 * gitService.createTag(project.targetTag)
1 * gitService.pushForceBranchWithTags(project.gitReleaseBranch)
}
}