Skip to content

Commit

Permalink
Remove 'production' as the default track name for the move build step.
Browse files Browse the repository at this point in the history
This is a breaking change, which will require users to explicitly
provide the track name.
  • Loading branch information
orrc committed May 22, 2020
1 parent 76a26f7 commit 3d546a7
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 17 deletions.
Expand Up @@ -16,6 +16,7 @@
import org.kohsuke.stapler.DataBoundSetter;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.io.IOException;
import java.io.PrintStream;
import java.util.ArrayList;
Expand Down Expand Up @@ -143,13 +144,13 @@ public void setRolloutPercentage(@Nonnull String percentage) {
this.rolloutPercentage = percentage;
return;
}
this.rolloutPercentage = pct.intValue() == ApkPublisher.DescriptorImpl.defaultRolloutPercent ? null : pctStr;
this.rolloutPercentage = pct.intValue() == DescriptorImpl.defaultRolloutPercent ? null : pctStr;
}

@Nonnull
public String getRolloutPercentage() {
if (fixEmptyAndTrim(rolloutPercentage) == null) {
return String.valueOf(ApkPublisher.DescriptorImpl.defaultRolloutPercent);
return String.valueOf(DescriptorImpl.defaultRolloutPercent);
}
return rolloutPercentage;
}
Expand All @@ -174,13 +175,13 @@ public Double getRolloutPercent() {
}

@DataBoundSetter
public void setTrackName(@Nonnull String trackName) {
this.trackName = DescriptorImpl.defaultTrackName.equalsIgnoreCase(trackName) ? null : trackName;
public void setTrackName(String trackName) {
this.trackName = trackName;
}

@Nonnull
@Nullable
public String getTrackName() {
return fixEmptyAndTrim(trackName) == null ? DescriptorImpl.defaultTrackName : trackName;
return fixEmptyAndTrim(trackName);
}

private String getExpandedApplicationId() throws IOException, InterruptedException {
Expand Down Expand Up @@ -368,7 +369,6 @@ private static final class AppInfo {
@Extension
public static final class DescriptorImpl extends GooglePlayBuildStepDescriptor<Builder> {
public static final String defaultFilesPattern = "**/build/outputs/**/*.aab, **/build/outputs/**/*.apk";
public static final String defaultTrackName = ReleaseTrack.PRODUCTION.getApiValue();
public static final int defaultRolloutPercent = 100;

public String getDisplayName() {
Expand Down
Expand Up @@ -30,7 +30,7 @@
</f:radioBlock>

<f:entry title="${%Release track}" field="trackName">
<f:combobox style="width:15em" default="${descriptor.defaultTrackName}" />
<f:combobox style="width:15em" />
</f:entry>

<f:entry title="${%Rollout %}" field="rolloutPercentage"
Expand Down
Expand Up @@ -31,12 +31,13 @@

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.stream.Stream;

import static org.jenkinsci.plugins.googleplayandroidpublisher.internal.TestsHelper.assertResultWithLogLines;
import static org.jenkinsci.plugins.googleplayandroidpublisher.internal.TestsHelper.getRequestBodyForUrl;
import static org.jenkinsci.plugins.googleplayandroidpublisher.internal.TestsHelper.release;
import static org.jenkinsci.plugins.googleplayandroidpublisher.internal.TestsHelper.setUpCredentials;
import static org.jenkinsci.plugins.googleplayandroidpublisher.internal.TestsHelper.track;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
Expand Down Expand Up @@ -103,6 +104,40 @@ public void configRoundtripWorks() throws Exception {
j.assertEqualDataBoundBeans(builder, project.getBuildersList().get(0));
}

@Test
public void movingApkTrackWithoutTrackNameFails() throws Exception {
// Given a job where the track name is not provided
FreeStyleProject p = j.createFreeStyleProject();
ReleaseTrackAssignmentBuilder builder = createBuilder();
builder.setTrackName(null);
p.getBuildersList().add(builder);

// And the prerequisites are in place
setUpCredentials("test-credentials");
setUpTransportForSuccess();

// When a build occurs
// Then it should fail as the track name has not been specified
assertResultWithLogLines(j, p, Result.FAILURE, "Release track was not specified");
}

@Test
public void movingApkTrackWithEmptyTrackNameFails() throws Exception {
// Given a job where the track name is empty (e.g. saved without entering a value, or an empty parameter value)
FreeStyleProject p = j.createFreeStyleProject();
ReleaseTrackAssignmentBuilder builder = createBuilder();
builder.setTrackName("");
p.getBuildersList().add(builder);

// And the prerequisites are in place
setUpCredentials("test-credentials");
setUpTransportForSuccess();

// When a build occurs
// Then it should fail as the track name has not been specified
assertResultWithLogLines(j, p, Result.FAILURE, "Release track was not specified");
}

@Test
public void moveApkTrack_whenVersionCodeDoesNotExist_buildFails() throws Exception {
transport
Expand Down Expand Up @@ -192,10 +227,31 @@ public void movingApkTrackAsDraftSucceeds() throws Exception {
assertNull(release.getUserFraction());
}

@Test
public void movingApkTrackWithPipelineWithoutTrackNameFails() throws Exception {
// Given a Pipeline where the track name is not provided
String stepDefinition = "androidApkMove googleCredentialsId: 'test-credentials'";

// When a build occurs
// Then it should fail as the track name has not been specified
moveApkTrackWithPipelineAndAssertFailure(stepDefinition, "Release track was not specified");
}

@Test
public void movingApkTrackWithPipelineWithEmptyTrackNameFails() throws Exception {
// Given a Pipeline where the track name is empty (e.g. an empty parameter value)
String stepDefinition = "androidApkMove googleCredentialsId: 'test-credentials'";

// When a build occurs
// Then it should fail as the track name has not been specified
moveApkTrackWithPipelineAndAssertFailure(stepDefinition, "Release track was not specified");
}

@Test
public void moveApkTrackWithPipeline_succeeds() throws Exception {
String stepDefinition =
" androidApkMove googleCredentialsId: 'test-credentials',\n" +
" trackName: 'production',\n" +
" fromVersionCode: true,\n" +
" applicationId: 'org.jenkins.appId',\n" +
" versionCodes: '42'";
Expand All @@ -210,6 +266,7 @@ public void moveApkTrackWithPipeline_withRolloutPercentage() throws Exception {
// Given a step with a `rolloutPercentage` value
String stepDefinition =
"androidApkMove googleCredentialsId: 'test-credentials',\n" +
" trackName: 'production',\n" +
" fromVersionCode: true,\n" +
" applicationId: 'org.jenkins.appId',\n" +
" versionCodes: '42',\n" +
Expand All @@ -226,6 +283,7 @@ public void moveApkTrackWithPipeline_withRolloutPercent() throws Exception {
// Given a step with a deprecated `rolloutPercent` value
String stepDefinition =
"androidApkMove googleCredentialsId: 'test-credentials',\n" +
" trackName: 'production',\n" +
" fromVersionCode: true,\n" +
" applicationId: 'org.jenkins.appId',\n" +
" versionCodes: '42',\n" +
Expand All @@ -242,6 +300,7 @@ public void moveApkTrackWithPipeline_withBothRolloutFormats_usesRolloutPercentag
// Given a step with both the deprecated `rolloutPercent`, and a verbose `rolloutPercentage` value
String stepDefinition =
"androidApkMove googleCredentialsId: 'test-credentials',\n" +
" trackName: 'production',\n" +
" fromVersionCode: true,\n" +
" applicationId: 'org.jenkins.appId',\n" +
" versionCodes: '42',\n" +
Expand All @@ -259,6 +318,7 @@ public void uploadingApkWithPipelineAsDraftSucceeds() throws Exception {
// Given a step with the rollout percentage set to zero
String stepDefinition =
"androidApkMove googleCredentialsId: 'test-credentials',\n" +
" trackName: 'production',\n" +
" fromVersionCode: true,\n" +
" applicationId: 'org.jenkins.appId',\n" +
" versionCodes: '42',\n" +
Expand All @@ -279,7 +339,27 @@ public void uploadingApkWithPipelineAsDraftSucceeds() throws Exception {
assertNull(release.getUserFraction());
}

private void moveApkTrackWithPipelineAndAssertSuccess(String stepDefinition, String... expectedLines) throws Exception {
private void moveApkTrackWithPipelineAndAssertFailure(
String stepDefinition, String... expectedLogLines
) throws Exception {
moveApkTrackWithPipelineAndAssertResult(stepDefinition, Result.FAILURE, expectedLogLines);
}

private void moveApkTrackWithPipelineAndAssertSuccess(
String stepDefinition, String... expectedLogLines
) throws Exception {
String[] commonLogLines = {
"Assigning 1 version(s) with application ID org.jenkins.appId to production release track",
"Changes were successfully applied to Google Play"
};
String[] allExpectedLogLines = Stream.concat(Arrays.stream(commonLogLines), Arrays.stream(expectedLogLines))
.toArray(String[]::new);
moveApkTrackWithPipelineAndAssertResult(stepDefinition, Result.SUCCESS, allExpectedLogLines);
}

private void moveApkTrackWithPipelineAndAssertResult(
String stepDefinition, Result expectedResult, String... expectedLogLines
) throws Exception {
WorkflowJob p = j.createProject(WorkflowJob.class);
p.setDefinition(new CpsFlowDefinition("" +
"node {\n" +
Expand All @@ -290,13 +370,7 @@ private void moveApkTrackWithPipelineAndAssertSuccess(String stepDefinition, Str
TestsHelper.setUpCredentials("test-credentials");
setUpTransportForSuccess();

String[] commonLines = {
"Assigning 1 version(s) with application ID org.jenkins.appId to production release track",
"Changes were successfully applied to Google Play"
};
String[] allExpectedLogLines = Stream.concat(Arrays.stream(commonLines), Arrays.stream(expectedLines))
.toArray(String[]::new);
TestsHelper.assertResultWithLogLines(j, p, Result.SUCCESS, allExpectedLogLines);
TestsHelper.assertResultWithLogLines(j, p, expectedResult, expectedLogLines);
}

@Test
Expand Down

0 comments on commit 3d546a7

Please sign in to comment.