Skip to content

Commit 194745f

Browse files
More logging
1 parent 9cebf9f commit 194745f

File tree

6 files changed

+52
-28
lines changed

6 files changed

+52
-28
lines changed

src/main/java/io/micrometer/release/train/DependencyVerifier.java

+36-18
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
*/
1616
package io.micrometer.release.train;
1717

18+
import com.fasterxml.jackson.core.JsonProcessingException;
19+
import com.fasterxml.jackson.databind.ObjectMapper;
1820
import io.micrometer.release.common.Dependency;
1921
import io.micrometer.release.common.GradleParser;
2022
import io.micrometer.release.common.Input;
@@ -38,6 +40,8 @@ class DependencyVerifier {
3840

3941
private final ProcessRunner processRunner;
4042

43+
private final ObjectMapper objectMapper;
44+
4145
private final int initialWait;
4246

4347
private final int timeout;
@@ -46,18 +50,20 @@ class DependencyVerifier {
4650

4751
private final TimeUnit timeUnit;
4852

49-
DependencyVerifier(ProcessRunner processRunner) {
53+
DependencyVerifier(ProcessRunner processRunner, ObjectMapper objectMapper) {
5054
this.processRunner = processRunner;
55+
this.objectMapper = objectMapper;
5156
this.timeUnit = TimeUnit.SECONDS;
5257
this.initialWait = 15;
5358
this.timeout = 60 * 10;
5459
this.waitBetweenRuns = 30;
5560
}
5661

5762
// for tests
58-
DependencyVerifier(ProcessRunner processRunner, int initialWait, int timeout, int waitBetweenRuns,
59-
TimeUnit timeUnit) {
63+
DependencyVerifier(ProcessRunner processRunner, ObjectMapper objectMapper, int initialWait, int timeout,
64+
int waitBetweenRuns, TimeUnit timeUnit) {
6065
this.processRunner = processRunner;
66+
this.objectMapper = objectMapper;
6167
this.initialWait = initialWait;
6268
this.timeout = timeout;
6369
this.waitBetweenRuns = waitBetweenRuns;
@@ -213,23 +219,27 @@ private void waitForDependabotJobsToFinish(String orgRepository, String githubSe
213219
long startTime = System.currentTimeMillis();
214220
long timeoutMillis = timeUnit.toMillis(timeout / 2);
215221
while (System.currentTimeMillis() - startTime < timeoutMillis) {
216-
List<String> statuses = curlRuns(orgRepository, githubServerTime, id).stream()
217-
.filter(s -> s.contains("\"status\": \""))
218-
.map(s -> s.substring(s.lastIndexOf(":") + 1).replace("\"", "").replace(",", "").trim())
219-
.toList();
220-
if (statuses.isEmpty()) {
221-
log.info("No dependabot jobs found");
222-
}
223-
else {
224-
log.info("Found {} Dependabot jobs with statuses {}", statuses.size(), statuses);
225-
boolean allCompleted = statuses.stream().allMatch(s -> s.equalsIgnoreCase("completed"));
226-
if (allCompleted) {
227-
log.info("All dependabot jobs completed");
228-
return;
222+
List<String> curl = curlRuns(orgRepository, githubServerTime, id);
223+
try {
224+
Workflows workflows = objectMapper.readValue(String.join("\n", curl), Workflows.class);
225+
List<Pr> prs = workflows.workflow_runs();
226+
if (prs.isEmpty()) {
227+
log.info("No dependabot jobs found");
229228
}
229+
else {
230+
log.info("Found {} Dependabot jobs with statuses {}", prs.size(), prs);
231+
boolean allCompleted = prs.stream().allMatch(pr -> pr.status().equalsIgnoreCase("completed"));
232+
if (allCompleted) {
233+
log.info("All dependabot jobs completed");
234+
return;
235+
}
236+
}
237+
log.info("Not all Dependabot jobs processed, will try again...");
238+
sleep(waitBetweenRuns);
239+
}
240+
catch (JsonProcessingException e) {
241+
throw new RuntimeException(e);
230242
}
231-
log.info("Not all Dependabot jobs processed, will try again...");
232-
sleep(waitBetweenRuns);
233243
}
234244
log.error("Failed! Dependabot jobs not processed within the provided timeout");
235245
throw new IllegalStateException("Timeout waiting for Dependabot jobs to complete");
@@ -241,6 +251,14 @@ List<String> curlRuns(String orgRepository, String githubServerTime, String id)
241251
+ "&workflow_id=" + id);
242252
}
243253

254+
record Pr(String id, String name, String url, String status) {
255+
256+
}
257+
258+
record Workflows(List<Pr> workflow_runs) {
259+
260+
}
261+
244262
private String getDependabotupdatesWorkflowId(String orgRepository) {
245263
List<String> ids = processRunner.run("gh", "workflow", "list", "-R", orgRepository, "--json", "id,name", "--jq",
246264
".[] | select(.name==\"Dependabot Updates\") | .id");

src/main/java/io/micrometer/release/train/ProjectTrainReleaseWorkflow.java

+2-3
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import io.micrometer.release.common.Input;
2121
import io.micrometer.release.common.ProcessRunner;
2222
import io.micrometer.release.single.PostReleaseWorkflow;
23-
2423
import io.micrometer.release.train.TrainOptions.ProjectSetup;
2524

2625
import java.net.http.HttpClient;
@@ -31,7 +30,7 @@ public class ProjectTrainReleaseWorkflow {
3130

3231
private static final HttpClient HTTP_CLIENT = HttpClient.newHttpClient();
3332

34-
private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper()
33+
static final ObjectMapper OBJECT_MAPPER = new ObjectMapper()
3534
.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
3635

3736
private final ReleaseScheduler releaseScheduler;
@@ -46,7 +45,7 @@ public ProjectTrainReleaseWorkflow(String githubOrgRepo, ProcessRunner processRu
4645
PostReleaseWorkflow postReleaseWorkflow) {
4746
this.releaseScheduler = new ReleaseScheduler(
4847
new CircleCiChecker(System.getenv("CIRCLE_CI_TOKEN"), githubOrgRepo, HTTP_CLIENT, OBJECT_MAPPER),
49-
processRunner);
48+
OBJECT_MAPPER, processRunner);
5049
this.versionToBranchConverter = new VersionToBranchConverter(Input.getGhToken(),
5150
"https://api.github.com/repos/" + githubOrgRepo + "/branches/", HTTP_CLIENT);
5251
this.postReleaseTaskScheduler = new PostReleaseTaskScheduler(postReleaseWorkflow, new Git(processRunner),

src/main/java/io/micrometer/release/train/ReleaseScheduler.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616
package io.micrometer.release.train;
1717

18+
import com.fasterxml.jackson.databind.ObjectMapper;
1819
import io.micrometer.release.common.Input;
1920
import io.micrometer.release.common.ProcessRunner;
2021
import io.micrometer.release.train.TrainOptions.ProjectSetup;
@@ -36,10 +37,10 @@ class ReleaseScheduler {
3637

3738
private final DependencyVerifier dependencyVerifier;
3839

39-
ReleaseScheduler(CircleCiChecker circleCiChecker, ProcessRunner processRunner) {
40+
ReleaseScheduler(CircleCiChecker circleCiChecker, ObjectMapper objectMapper, ProcessRunner processRunner) {
4041
this.circleCiChecker = circleCiChecker;
4142
this.processRunner = processRunner;
42-
this.dependencyVerifier = new DependencyVerifier(processRunner);
43+
this.dependencyVerifier = new DependencyVerifier(processRunner, objectMapper);
4344
}
4445

4546
// for tests

src/main/java/io/micrometer/release/train/TrainOptions.java

-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313
*/
1414
package io.micrometer.release.train;
1515

16-
import io.micrometer.release.common.Dependency;
17-
1816
import java.util.ArrayList;
1917
import java.util.List;
2018
import java.util.Objects;

src/test/java/io/micrometer/release/train/DependencyVerifierTests.java

+10-2
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ class DependencyVerifierTests {
5959

6060
ProcessRunner processRunner = mock();
6161

62-
DependencyVerifier verifier = new DependencyVerifier(processRunner, 1, 5, 1, TimeUnit.MILLISECONDS) {
62+
DependencyVerifier verifier = new DependencyVerifier(processRunner, ProjectTrainReleaseWorkflow.OBJECT_MAPPER, 1, 5,
63+
1, TimeUnit.MILLISECONDS) {
6364
@Override
6465
GradleParser gradleParser(ProcessRunner branchProcessRunner) {
6566
return new TestGradleParser();
@@ -145,14 +146,21 @@ void should_fail_when_dependabot_jobs_are_not_successful() {
145146
"total_count": 15,
146147
"workflow_runs": [
147148
{
149+
"id" : 1,
150+
"url": "a",
151+
"name": "foo",
148152
"status": "blocked",
149153
"event": "pull_request"
150154
},
151155
{
156+
"id" : 2,
157+
"url": "a",
158+
"name": "bar",
152159
"status": "open",
153160
"event": "pull_request"
154161
}
155-
]"""));
162+
]
163+
}"""));
156164

157165
thenThrownBy(() -> verifier.verifyDependencies("main", "micrometer-metrics/micrometer", projectSetup()))
158166
.isInstanceOf(IllegalStateException.class)

src/test/java/io/micrometer/release/train/ReleaseSchedulerTests.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ void should_schedule_releases() throws IOException, InterruptedException {
5454
@Test
5555
void should_not_make_a_release_when_dependency_check_fails() {
5656
ReleaseScheduler releaseScheduler = new ReleaseScheduler(checker, processRunner,
57-
new DependencyVerifier(processRunner) {
57+
new DependencyVerifier(processRunner, ProjectTrainReleaseWorkflow.OBJECT_MAPPER) {
5858
@Override
5959
void verifyDependencies(String branch, String orgRepository, ProjectSetup projectSetup) {
6060
throw new IllegalStateException("BOOM!"); // mock doesn't work for

0 commit comments

Comments
 (0)