Skip to content
This repository has been archived by the owner on Nov 19, 2024. It is now read-only.

Commit

Permalink
Merge pull request #672 from jenkinsci/use-id-to-select-reference-action
Browse files Browse the repository at this point in the history
Use the correct ID of the action when comparing with reference build
  • Loading branch information
uhafner authored May 10, 2023
2 parents af39962 + 22a5917 commit d4f72fe
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,7 @@ public String formatDelta(final Baseline baseline, final Metric metric) {
*
* @return {@code true} if the trend is positive, {@code false} otherwise
*/
@SuppressWarnings("unused") // Called by jelly view
public boolean isPositiveTrend(final Baseline baseline, final Metric metric) {
var delta = getDelta(baseline, metric);
if (delta.isPresent()) {
Expand Down Expand Up @@ -581,7 +582,7 @@ NavigableSet<Metric> getMetricsForSummary() {
}

/**
* Renders the reference build as HTML link.
* Renders the reference build as HTML-link.
*
* @return the reference build
* @see #getReferenceBuild()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ CoverageBuildAction publishAction(final String id, final String optionalName, fi
throws InterruptedException {
FilteredLog log = new FilteredLog("Errors while reporting code coverage results:");

Optional<CoverageBuildAction> possibleReferenceResult = getReferenceBuildAction(build, log);
Optional<CoverageBuildAction> possibleReferenceResult = getReferenceBuildAction(build, id, log);

List<FileNode> filesToStore;
CoverageBuildAction action;
Expand Down Expand Up @@ -194,7 +194,7 @@ private boolean hasLineCoverageSet(final Value value) {
return ((edu.hm.hafner.coverage.Coverage) value).isSet();
}

private Optional<CoverageBuildAction> getReferenceBuildAction(final Run<?, ?> build, final FilteredLog log) {
private Optional<CoverageBuildAction> getReferenceBuildAction(final Run<?, ?> build, final String id, final FilteredLog log) {
log.logInfo("Obtaining action of reference build");

ReferenceFinder referenceFinder = new ReferenceFinder();
Expand All @@ -204,7 +204,7 @@ private Optional<CoverageBuildAction> getReferenceBuildAction(final Run<?, ?> bu
if (reference.isPresent()) {
Run<?, ?> referenceBuild = reference.get();
log.logInfo("-> Using reference build '%s'", referenceBuild);
previousResult = getPreviousResult(reference.get());
previousResult = getPreviousResult(id, reference.get());
if (previousResult.isPresent()) {
Run<?, ?> fallbackBuild = previousResult.get().getOwner();
if (!fallbackBuild.equals(referenceBuild)) {
Expand All @@ -214,7 +214,7 @@ private Optional<CoverageBuildAction> getReferenceBuildAction(final Run<?, ?> bu
}
}
else {
previousResult = getPreviousResult(build.getPreviousBuild());
previousResult = getPreviousResult(id, build.getPreviousBuild());
previousResult.ifPresent(coverageBuildAction ->
log.logInfo("-> No reference build defined, falling back to previous build: '%s'",
coverageBuildAction.getOwner().getDisplayName()));
Expand All @@ -232,11 +232,13 @@ private Optional<CoverageBuildAction> getReferenceBuildAction(final Run<?, ?> bu
return Optional.of(referenceAction);
}

private Optional<CoverageBuildAction> getPreviousResult(@CheckForNull final Run<?, ?> startSearch) {
private Optional<CoverageBuildAction> getPreviousResult(final String id, @CheckForNull final Run<?, ?> startSearch) {
for (Run<?, ?> build = startSearch; build != null; build = build.getPreviousBuild()) {
CoverageBuildAction action = build.getAction(CoverageBuildAction.class);
if (action != null) {
return Optional.of(action);
List<CoverageBuildAction> actions = build.getActions(CoverageBuildAction.class);
for (CoverageBuildAction action : actions) {
if (action.getUrlName().equals(id)) {
return Optional.of(action);
}
}
}
return Optional.empty();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ void shouldComputeDeltaInFreestyleJob() {
Run<?, ?> firstBuild = buildSuccessfully(project);
verifyFirstBuild(firstBuild);

// update parser pattern to pick only the coding style results
// update the parser pattern to pick only the coding style results
project.getPublishersList().get(CoverageRecorder.class).getTools().get(0).setPattern(JACOCO_CODING_STYLE_FILE);

Run<?, ?> secondBuild = buildSuccessfully(project);
Expand All @@ -48,7 +48,24 @@ void shouldComputeDeltaInPipeline() {
Run<?, ?> firstBuild = buildSuccessfully(job);
verifyFirstBuild(firstBuild);

// update parser pattern to pick only the codingstyle results
computeDeltaInSecondBuild(job, firstBuild);
}

@Test
void shouldSelectResultByIdInReferenceBuild() {
WorkflowJob job = createPipelineWithWorkspaceFiles(JACOCO_ANALYSIS_MODEL_FILE, JACOCO_CODING_STYLE_FILE, "mutations.xml");

// Create a build with two different actions
setPipelineScript(job,
"recordCoverage tools: [[parser: '" + Parser.PIT.name() + "', pattern: '**/mutations.xml']], id: 'pit'\n"
+ "recordCoverage tools: [[parser: '" + Parser.JACOCO.name() + "', pattern: '**/jacoco*xml']]\n");

Run<?, ?> firstBuild = buildSuccessfully(job);

computeDeltaInSecondBuild(job, firstBuild);
}

private void computeDeltaInSecondBuild(final WorkflowJob job, final Run<?, ?> firstBuild) {
setPipelineScript(job,
"recordCoverage tools: [[parser: 'JACOCO', pattern: '" + JACOCO_CODING_STYLE_FILE + "']]");

Expand Down Expand Up @@ -119,8 +136,8 @@ private void verifyDeltaComputation(final Run<?, ?> firstBuild, final Run<?, ?>
}

/**
* Verifies the calculated modified lines coverage including the modified lines coverage delta and the code delta. This makes sure
* these metrics are set properly even if there are no code changes.
* Verifies the calculated modified lines coverage including the modified lines coverage delta and the code delta.
* This makes sure these metrics are set properly even if there are no code changes.
*
* @param action
* The created Jenkins action
Expand Down

0 comments on commit d4f72fe

Please sign in to comment.