Skip to content

Commit ac6c421

Browse files
Checking out branches before doing release tasks
1 parent 356aba9 commit ac6c421

File tree

6 files changed

+87
-5
lines changed

6 files changed

+87
-5
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/**
2+
* Copyright 2025 the original author or authors.
3+
* <p>
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5+
* in compliance with the License. You may obtain a copy of the License at
6+
* <p>
7+
* https://www.apache.org/licenses/LICENSE-2.0
8+
* <p>
9+
* Unless required by applicable law or agreed to in writing, software distributed under the License
10+
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11+
* or implied. See the License for the specific language governing permissions and limitations under
12+
* the License.
13+
*/
14+
package io.micrometer.release.train;
15+
16+
import io.micrometer.release.common.ProcessRunner;
17+
import org.slf4j.Logger;
18+
import org.slf4j.LoggerFactory;
19+
20+
class Git {
21+
22+
private static final Logger log = LoggerFactory.getLogger(Git.class);
23+
24+
private final ProcessRunner processRunner;
25+
26+
Git(ProcessRunner processRunner) {
27+
this.processRunner = processRunner;
28+
}
29+
30+
void changeTag(String tag) {
31+
log.info("Changing git head to tag [{}]", tag);
32+
processRunner.run("git", "fetch", "origin", "refs/tags/" + tag);
33+
processRunner.run("git", "checkout", tag);
34+
}
35+
36+
}

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

+5-1
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,13 @@ class PostReleaseTaskScheduler {
3030

3131
private final PostReleaseWorkflow postReleaseWorkflow;
3232

33+
private final Git git;
34+
3335
private final String githubOrgRepo;
3436

35-
PostReleaseTaskScheduler(PostReleaseWorkflow postReleaseWorkflow, String githubOrgRepo) {
37+
PostReleaseTaskScheduler(PostReleaseWorkflow postReleaseWorkflow, Git git, String githubOrgRepo) {
3638
this.postReleaseWorkflow = postReleaseWorkflow;
39+
this.git = git;
3740
this.githubOrgRepo = githubOrgRepo;
3841
}
3942

@@ -42,6 +45,7 @@ void runPostReleaseTasks(List<String> versions) {
4245
sortedVersions.sort(Comparator.comparing(PostReleaseTaskScheduler::extractMajorMinorVersion));
4346
String previousVersion = null;
4447
for (String version : sortedVersions) {
48+
git.changeTag("v" + version);
4549
log.info("Running post release task for version [{}] and previous version [{}]", version, previousVersion);
4650
postReleaseWorkflow.run(githubOrgRepo, "v" + version,
4751
previousVersion != null ? ("v" + previousVersion) : null);

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ public ProjectTrainReleaseWorkflow(String githubOrgRepo, String artifactToCheck,
4747
processRunner);
4848
this.versionToBranchConverter = new VersionToBranchConverter(System.getenv("GH_TOKEN"),
4949
"https://api.github.com/repos/" + githubOrgRepo + "/branches/", HTTP_CLIENT);
50-
this.postReleaseTaskScheduler = new PostReleaseTaskScheduler(postReleaseWorkflow, githubOrgRepo);
50+
this.postReleaseTaskScheduler = new PostReleaseTaskScheduler(postReleaseWorkflow, new Git(processRunner),
51+
githubOrgRepo);
5152
this.mavenCentralSyncChecker = new MavenCentralSyncChecker(artifactToCheck);
5253
}
5354

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/**
2+
* Copyright 2025 the original author or authors.
3+
* <p>
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5+
* in compliance with the License. You may obtain a copy of the License at
6+
* <p>
7+
* https://www.apache.org/licenses/LICENSE-2.0
8+
* <p>
9+
* Unless required by applicable law or agreed to in writing, software distributed under the License
10+
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11+
* or implied. See the License for the specific language governing permissions and limitations under
12+
* the License.
13+
*/
14+
package io.micrometer.release.train;
15+
16+
import io.micrometer.release.common.ProcessRunner;
17+
import org.junit.jupiter.api.Test;
18+
19+
import static org.mockito.BDDMockito.then;
20+
import static org.mockito.Mockito.mock;
21+
22+
class GitTests {
23+
24+
ProcessRunner processRunner = mock();
25+
26+
@Test
27+
void should_checkout_tag() {
28+
Git git = new Git(processRunner);
29+
30+
git.changeTag("v1.2.3");
31+
32+
then(processRunner).should().run("git", "fetch", "origin", "refs/tags/v1.2.3");
33+
then(processRunner).should().run("git", "checkout", "v1.2.3");
34+
}
35+
36+
}

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

+7-2
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,21 @@ class PostReleaseTaskSchedulerTests {
2828

2929
PostReleaseWorkflow postReleaseWorkflow = mock();
3030

31-
PostReleaseTaskScheduler scheduler = new PostReleaseTaskScheduler(postReleaseWorkflow,
31+
Git git = mock();
32+
33+
PostReleaseTaskScheduler scheduler = new PostReleaseTaskScheduler(postReleaseWorkflow, git,
3234
"micrometer-metrics/micrometer");
3335

3436
@Test
3537
void should_schedule_release_tasks() {
3638
scheduler.runPostReleaseTasks(List.of("1.0.0", "1.1.0", "1.2.0"));
3739

38-
InOrder inOrder = inOrder(postReleaseWorkflow);
40+
InOrder inOrder = inOrder(git, postReleaseWorkflow);
41+
inOrder.verify(git).changeTag("v1.0.0");
3942
inOrder.verify(postReleaseWorkflow).run("micrometer-metrics/micrometer", "v1.0.0", null);
43+
inOrder.verify(git).changeTag("v1.1.0");
4044
inOrder.verify(postReleaseWorkflow).run("micrometer-metrics/micrometer", "v1.1.0", "v1.0.0");
45+
inOrder.verify(git).changeTag("v1.2.0");
4146
inOrder.verify(postReleaseWorkflow).run("micrometer-metrics/micrometer", "v1.2.0", "v1.1.0");
4247
}
4348

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class ProjectTrainReleaseWorkflowAcceptanceTests {
5555
ReleaseScheduler releaseScheduler = new ReleaseScheduler(circleCiChecker, processRunner);
5656

5757
PostReleaseTaskScheduler postReleaseTaskScheduler = new PostReleaseTaskScheduler(postReleaseWorkflow,
58-
GITHUB_ORG_REPO);
58+
new Git(processRunner), GITHUB_ORG_REPO);
5959

6060
VersionToBranchConverter versionToBranchConverter = new VersionToBranchConverter("foo",
6161
wm1.url("/repos/micrometer-metrics/micrometer/branches/"), HttpClient.newBuilder().build());

0 commit comments

Comments
 (0)