Fix detection of latest GA for SDKMAN

Fixes gh-24475
pull/24789/head
Madhura Bhave 4 years ago
parent 60f526add0
commit 822ae0daf7

@ -64,8 +64,7 @@ public class PublishToSdkmanCommand implements Command {
String version = nonOptionArgs.get(2); String version = nonOptionArgs.get(2);
boolean makeDefault = false; boolean makeDefault = false;
if (nonOptionArgs.size() == 4) { if (nonOptionArgs.size() == 4) {
String releaseBranch = nonOptionArgs.get(3); makeDefault = Boolean.parseBoolean(nonOptionArgs.get(3));
makeDefault = ("master".equals(releaseBranch));
} }
this.service.publish(version, makeDefault); this.service.publish(version, makeDefault);
} }

@ -78,7 +78,7 @@ public class SdkmanService {
private void makeDefault(String version) { private void makeDefault(String version) {
logger.debug("Making this version the default"); logger.debug("Making this version the default");
Request request = new Request(version); Request request = new Request(version);
RequestEntity<Request> requestEntity = RequestEntity.post(URI.create(SDKMAN_URL + "default")) RequestEntity<Request> requestEntity = RequestEntity.put(URI.create(SDKMAN_URL + "default"))
.header(CONSUMER_KEY_HEADER, this.properties.getConsumerKey()) .header(CONSUMER_KEY_HEADER, this.properties.getConsumerKey())
.header(CONSUMER_TOKEN_HEADER, this.properties.getConsumerToken()) .header(CONSUMER_TOKEN_HEADER, this.properties.getConsumerToken())
.contentType(MediaType.APPLICATION_JSON).body(request); .contentType(MediaType.APPLICATION_JSON).body(request);

@ -51,42 +51,36 @@ class PublishToSdkmanCommandTests {
@Test @Test
void runWhenReleaseTypeNotSpecifiedShouldThrowException() throws Exception { void runWhenReleaseTypeNotSpecifiedShouldThrowException() throws Exception {
Assertions.assertThatIllegalStateException() Assertions.assertThatIllegalStateException()
.isThrownBy(() -> this.command.run(new DefaultApplicationArguments("publishGradlePlugin"))); .isThrownBy(() -> this.command.run(new DefaultApplicationArguments("publishToSdkman")));
} }
@Test @Test
void runWhenVersionNotSpecifiedShouldThrowException() throws Exception { void runWhenVersionNotSpecifiedShouldThrowException() throws Exception {
Assertions.assertThatIllegalStateException() Assertions.assertThatIllegalStateException()
.isThrownBy(() -> this.command.run(new DefaultApplicationArguments("publishGradlePlugin", "RELEASE"))); .isThrownBy(() -> this.command.run(new DefaultApplicationArguments("publishToSdkman", "RELEASE")));
} }
@Test @Test
void runWhenReleaseTypeMilestoneShouldDoNothing() throws Exception { void runWhenReleaseTypeMilestoneShouldDoNothing() throws Exception {
this.command.run(new DefaultApplicationArguments("publishGradlePlugin", "M", "1.2.3")); this.command.run(new DefaultApplicationArguments("publishToSdkman", "M", "1.2.3"));
verifyNoInteractions(this.service); verifyNoInteractions(this.service);
} }
@Test @Test
void runWhenReleaseTypeRCShouldDoNothing() throws Exception { void runWhenReleaseTypeRCShouldDoNothing() throws Exception {
this.command.run(new DefaultApplicationArguments("publishGradlePlugin", "RC", "1.2.3")); this.command.run(new DefaultApplicationArguments("publishToSdkman", "RC", "1.2.3"));
verifyNoInteractions(this.service); verifyNoInteractions(this.service);
} }
@Test @Test
void runWhenBranchNotSpecifiedShouldCallServiceWithMakeDefaultFalse() throws Exception { void runWhenLatestGANotSpecifiedShouldCallServiceWithMakeDefaultFalse() throws Exception {
DefaultApplicationArguments args = new DefaultApplicationArguments("promote", "RELEASE", "1.2.3"); DefaultApplicationArguments args = new DefaultApplicationArguments("promote", "RELEASE", "1.2.3");
testRun(args, false); testRun(args, false);
} }
@Test
void runWhenBranchNotMasterShouldCallServiceWithMakeDefaultFalse() throws Exception {
DefaultApplicationArguments args = new DefaultApplicationArguments("promote", "RELEASE", "1.2.3", "other");
testRun(args, false);
}
@Test @Test
void runWhenReleaseTypeReleaseShouldCallService() throws Exception { void runWhenReleaseTypeReleaseShouldCallService() throws Exception {
DefaultApplicationArguments args = new DefaultApplicationArguments("promote", "RELEASE", "1.2.3", "master"); DefaultApplicationArguments args = new DefaultApplicationArguments("promote", "RELEASE", "1.2.3", "true");
testRun(args, true); testRun(args, true);
} }

@ -59,8 +59,8 @@ class SdkmanServiceTests {
void publishWhenMakeDefaultTrue() throws Exception { void publishWhenMakeDefaultTrue() throws Exception {
setupExpectation("https://vendors.sdkman.io/release", setupExpectation("https://vendors.sdkman.io/release",
"{\"candidate\": \"springboot\", \"version\": \"1.2.3\", \"url\": \"https://repo.spring.io/simple/libs-release-local/org/springframework/boot/spring-boot-cli/1.2.3/spring-boot-cli-1.2.3-bin.zip\"}"); "{\"candidate\": \"springboot\", \"version\": \"1.2.3\", \"url\": \"https://repo.spring.io/simple/libs-release-local/org/springframework/boot/spring-boot-cli/1.2.3/spring-boot-cli-1.2.3-bin.zip\"}");
setupExpectation("https://vendors.sdkman.io/default", setupExpectation("https://vendors.sdkman.io/default", "{\"candidate\": \"springboot\", \"version\": \"1.2.3\"}",
"{\"candidate\": \"springboot\", \"version\": \"1.2.3\"}"); HttpMethod.PUT);
setupExpectation("https://vendors.sdkman.io/announce/struct", setupExpectation("https://vendors.sdkman.io/announce/struct",
"{\"candidate\": \"springboot\", \"version\": \"1.2.3\", \"hashtag\": \"springboot\"}"); "{\"candidate\": \"springboot\", \"version\": \"1.2.3\", \"hashtag\": \"springboot\"}");
this.service.publish("1.2.3", true); this.service.publish("1.2.3", true);
@ -78,7 +78,11 @@ class SdkmanServiceTests {
} }
private void setupExpectation(String url, String body) { private void setupExpectation(String url, String body) {
this.server.expect(requestTo(url)).andExpect(method(HttpMethod.POST)).andExpect(content().json(body)) setupExpectation(url, body, HttpMethod.POST);
}
private void setupExpectation(String url, String body, HttpMethod method) {
this.server.expect(requestTo(url)).andExpect(method(method)).andExpect(content().json(body))
.andExpect(header("Consumer-Key", "sdkman-consumer-key")) .andExpect(header("Consumer-Key", "sdkman-consumer-key"))
.andExpect(header("Consumer-Token", "sdkman-consumer-token")) .andExpect(header("Consumer-Token", "sdkman-consumer-token"))
.andExpect(header("Content-Type", MediaType.APPLICATION_JSON.toString())).andRespond(withSuccess()); .andExpect(header("Content-Type", MediaType.APPLICATION_JSON.toString())).andRespond(withSuccess());

@ -693,6 +693,7 @@ jobs:
<<: *sdkman-task-params <<: *sdkman-task-params
RELEASE_TYPE: RELEASE RELEASE_TYPE: RELEASE
BRANCH: ((branch)) BRANCH: ((branch))
LATEST_GA: false
groups: groups:
- name: "builds" - name: "builds"
jobs: ["build", "jdk11-build", "jdk15-build", "windows-build"] jobs: ["build", "jdk11-build", "jdk15-build", "windows-build"]

@ -4,6 +4,6 @@ source $(dirname $0)/common.sh
version=$( cat artifactory-repo/build-info.json | jq -r '.buildInfo.modules[0].id' | sed 's/.*:.*:\(.*\)/\1/' ) version=$( cat artifactory-repo/build-info.json | jq -r '.buildInfo.modules[0].id' | sed 's/.*:.*:\(.*\)/\1/' )
java -jar /spring-boot-release-scripts.jar publishToSdkman $RELEASE_TYPE $version $BRANCH || { exit 1; } java -jar /spring-boot-release-scripts.jar publishToSdkman $RELEASE_TYPE $version $LATEST_GA || { exit 1; }
echo "Push to SDKMAN complete" echo "Push to SDKMAN complete"

@ -6,6 +6,7 @@ inputs:
params: params:
RELEASE_TYPE: RELEASE_TYPE:
BRANCH: BRANCH:
LATEST_GA:
SDKMAN_CONSUMER_KEY: SDKMAN_CONSUMER_KEY:
SDKMAN_CONSUMER_TOKEN: SDKMAN_CONSUMER_TOKEN:
run: run:

Loading…
Cancel
Save