Skip to content

Commit 4343708

Browse files
committed
chore: use git branch info for snapshot versioning
1 parent 79702c5 commit 4343708

File tree

4 files changed

+198
-10
lines changed

4 files changed

+198
-10
lines changed

.github/workflows/maven.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ jobs:
4747
sudo -E mvn -ntp -U verify
4848
sudo chown -R runner target
4949
if: matrix.os == 'ubuntu-latest'
50+
- name: Show file
51+
run: |
52+
sudo cat target/git.properties
53+
if: matrix.os == 'ubuntu-latest' && failure()
5054
- name: Upload Failed Test Report
5155
uses: actions/upload-artifact@v4
5256
if: failure()
@@ -69,7 +73,7 @@ jobs:
6973
if: matrix.os == 'ubuntu-latest'
7074
- name: Check compatibility
7175
run: >-
72-
mvn -ntp japicmp:cmp -DskipTests
76+
mvn -ntp initialize japicmp:cmp -DskipTests
7377
if: github.event_name == 'pull_request' && matrix.os == 'ubuntu-latest'
7478
- name: Upload Compatibility Report
7579
uses: actions/upload-artifact@v4

nucleus-build-version.xml

Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!-- Maven POM for generating Git-based version properties for Greengrass Nucleus -->
3+
<project xmlns="http://maven.apache.org/POM/4.0.0"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
6+
http://maven.apache.org/xsd/maven-4.0.0.xsd">
7+
<modelVersion>4.0.0</modelVersion>
8+
<groupId>com.aws.greengrass</groupId>
9+
<artifactId>nucleus-build-version</artifactId>
10+
<version>1.0.0</version>
11+
<packaging>pom</packaging>
12+
13+
<build>
14+
<plugins>
15+
<!-- Extract Git information and write to properties file -->
16+
<plugin>
17+
<groupId>org.apache.maven.plugins</groupId>
18+
<artifactId>maven-antrun-plugin</artifactId>
19+
<version>3.1.0</version>
20+
<executions>
21+
<!-- Get current Git branch name -->
22+
<execution>
23+
<id>set-git-branch-info</id>
24+
<phase>initialize</phase>
25+
<goals>
26+
<goal>run</goal>
27+
</goals>
28+
<configuration>
29+
<target>
30+
<!-- Execute git command to get current branch -->
31+
<exec executable="git" outputproperty="git.branch">
32+
<arg value="branch"/>
33+
<arg value="--show-current"/>
34+
</exec>
35+
<!-- Write branch name to git.properties file -->
36+
<echo file="${project.build.directory}/git.properties" append="true">git.branch=${git.branch}${line.separator}</echo>
37+
</target>
38+
</configuration>
39+
</execution>
40+
<!-- Get latest Git tag for version determination -->
41+
<execution>
42+
<id>set-git-latest-tag-info</id>
43+
<phase>initialize</phase>
44+
<goals>
45+
<goal>run</goal>
46+
</goals>
47+
<configuration>
48+
<target>
49+
<!-- Get the most recent tag sorted by version -->
50+
<exec executable="git" outputproperty="git.latest.tag">
51+
<arg value="for-each-ref"/>
52+
<arg value="--count=1"/>
53+
<arg value="--sort=-version:refname"/>
54+
<arg value="--format=%(refname:short)"/>
55+
<arg value="refs/tags"/>
56+
</exec>
57+
<!-- Write latest tag to git.properties file -->
58+
<echo file="${project.build.directory}/git.properties" append="true">git.latest.tag=${git.latest.tag}${line.separator}</echo>
59+
</target>
60+
</configuration>
61+
</execution>
62+
</executions>
63+
</plugin>
64+
65+
<!-- Load the generated Git properties into Maven properties -->
66+
<plugin>
67+
<groupId>org.codehaus.mojo</groupId>
68+
<artifactId>properties-maven-plugin</artifactId>
69+
<version>1.1.0</version>
70+
<executions>
71+
<execution>
72+
<phase>initialize</phase>
73+
<goals>
74+
<goal>read-project-properties</goal>
75+
</goals>
76+
<configuration>
77+
<files>
78+
<!-- Read the git.properties file created above -->
79+
<file>${project.build.directory}/git.properties</file>
80+
</files>
81+
</configuration>
82+
</execution>
83+
</executions>
84+
</plugin>
85+
86+
<!-- Process version strings using regex transformations -->
87+
<plugin>
88+
<groupId>org.codehaus.mojo</groupId>
89+
<artifactId>build-helper-maven-plugin</artifactId>
90+
<version>3.6.1</version>
91+
<executions>
92+
<!-- Check if current branch is a release branch -->
93+
<execution>
94+
<id>process-release-branch-info</id>
95+
<phase>initialize</phase>
96+
<goals><goal>regex-property</goal></goals>
97+
<configuration>
98+
<name>release.branch.match</name>
99+
<value>${git.branch}</value>
100+
<!-- Match release_MAJOR.MINOR.x pattern and extract version -->
101+
<regex>^release_(\d+\.\d+)\.x$</regex>
102+
<!-- Transform release_MAJOR.MINOR.x to MAJOR.MINOR.0 -->
103+
<replacement>$1.0</replacement>
104+
<failIfNoMatch>false</failIfNoMatch>
105+
</configuration>
106+
</execution>
107+
<!-- Set final branch version (dev for non-release branches) -->
108+
<execution>
109+
<id>process-non-release-branch-info</id>
110+
<phase>initialize</phase>
111+
<goals><goal>regex-property</goal></goals>
112+
<configuration>
113+
<name>git.current.branch.snapshot</name>
114+
<value>${release.branch.match}</value>
115+
<!-- Default to 'dev' if not a release branch -->
116+
<regex>^${git.branch}$</regex>
117+
<replacement>dev</replacement>
118+
<failIfNoMatch>false</failIfNoMatch>
119+
</configuration>
120+
</execution>
121+
<!-- Convert latest tag to SNAPSHOT version format -->
122+
<execution>
123+
<id>process-latest-tag-info</id>
124+
<phase>initialize</phase>
125+
<goals><goal>regex-property</goal></goals>
126+
<configuration>
127+
<name>git.latest.tag.snapshot</name>
128+
<value>${git.latest.tag}</value>
129+
<!-- Transform vMAJOR.MINOR.PATCH to MAJOR.MINOR.0-SNAPSHOT -->
130+
<regex>^v?(\d+)\.(\d+)\.\d+.*$</regex>
131+
<replacement>$1.$2.0-SNAPSHOT</replacement>
132+
<failIfNoMatch>false</failIfNoMatch>
133+
</configuration>
134+
</execution>
135+
</executions>
136+
</plugin>
137+
138+
<!-- Write final git.current.branch.snapshot version information -->
139+
<plugin>
140+
<groupId>org.apache.maven.plugins</groupId>
141+
<artifactId>maven-antrun-plugin</artifactId>
142+
<version>3.1.0</version>
143+
<executions>
144+
<execution>
145+
<id>set-build-snapshot-version</id>
146+
<phase>compile</phase>
147+
<goals><goal>run</goal></goals>
148+
<configuration>
149+
<target>
150+
<!-- Append final branch snapshot version to properties -->
151+
<echo file="${project.build.directory}/git.properties" append="true">git.current.branch.snapshot=${git.current.branch.snapshot}${line.separator}</echo>
152+
</target>
153+
</configuration>
154+
</execution>
155+
</executions>
156+
</plugin>
157+
</plugins>
158+
</build>
159+
</project>

pom.xml

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<modelVersion>4.0.0</modelVersion>
55
<groupId>com.aws.greengrass</groupId>
66
<artifactId>nucleus</artifactId>
7-
<version>2.15.0-SNAPSHOT</version>
7+
<version>${git.current.branch.snapshot}-SNAPSHOT</version>
88
<packaging>jar</packaging>
99

1010
<licenses>
@@ -204,9 +204,9 @@
204204
<version>1.11</version>
205205
</dependency>
206206
<dependency>
207-
<groupId>com.github.oshi</groupId>
208-
<artifactId>oshi-core</artifactId>
209-
<version>6.4.4</version>
207+
<groupId>com.github.oshi</groupId>
208+
<artifactId>oshi-core</artifactId>
209+
<version>6.4.4</version>
210210
</dependency>
211211

212212
<!-- zeroturnaround brings in an older version jna which tries to load msvcr100.dll. msvcr100.dll is not shipped
@@ -308,7 +308,7 @@
308308
<dependency>
309309
<groupId>${project.groupId}</groupId>
310310
<artifactId>${project.artifactId}</artifactId>
311-
<version>${lastVersion}</version>
311+
<version>${git.latest.tag.snapshot}</version>
312312
<type>${project.packaging}</type>
313313
</dependency>
314314
</oldVersion>
@@ -856,9 +856,8 @@
856856
<maven.compiler.useIncrementalCompilation>false</maven.compiler.useIncrementalCompilation>
857857
<skipTests>false</skipTests>
858858
<excludedGroups>E2E,E2E-INTRUSIVE</excludedGroups>
859-
<groups></groups>
860859
<greengrassjar.name>Greengrass</greengrassjar.name>
861-
<lastVersion>2.14.0-SNAPSHOT</lastVersion>
860+
<git.current.branch.snapshot>dev</git.current.branch.snapshot>
862861
</properties>
863862
<distributionManagement>
864863
<snapshotRepository>
@@ -868,4 +867,11 @@
868867
</snapshotRepository>
869868
</distributionManagement>
870869
<name>greengrass-nucleus</name>
870+
<!-- Get build and latest tag snapshot versions properties using git repo details -->
871+
<parent>
872+
<groupId>com.aws.greengrass</groupId>
873+
<artifactId>nucleus-build-version</artifactId>
874+
<version>1.0.0</version>
875+
<relativePath>nucleus-build-version.xml</relativePath>
876+
</parent>
871877
</project>

src/test/greengrass-nucleus-benchmark/pom.xml

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
<groupId>com.aws.greengrass</groupId>
66
<artifactId>greengrass-nucleus-benchmark</artifactId>
7-
<version>2.15.0-SNAPSHOT</version>
7+
<version>${git.current.branch.snapshot}-SNAPSHOT</version>
88
<packaging>jar</packaging>
99

1010
<name>JMH benchmark sample: Java</name>
@@ -54,7 +54,7 @@
5454
<dependency>
5555
<groupId>com.aws.greengrass</groupId>
5656
<artifactId>nucleus</artifactId>
57-
<version>2.15.0-SNAPSHOT</version>
57+
<version>${git.current.branch.snapshot}-SNAPSHOT</version>
5858
</dependency>
5959
</dependencies>
6060

@@ -79,6 +79,25 @@
7979

8080
<build>
8181
<plugins>
82+
<!-- Read git info from the nucleus project build folder -->
83+
<plugin>
84+
<groupId>org.codehaus.mojo</groupId>
85+
<artifactId>properties-maven-plugin</artifactId>
86+
<version>1.1.0</version>
87+
<executions>
88+
<execution>
89+
<phase>initialize</phase>
90+
<goals>
91+
<goal>read-project-properties</goal>
92+
</goals>
93+
<configuration>
94+
<files>
95+
<file>../../../target/git.properties</file>
96+
</files>
97+
</configuration>
98+
</execution>
99+
</executions>
100+
</plugin>
82101
<plugin>
83102
<groupId>org.apache.maven.plugins</groupId>
84103
<artifactId>maven-compiler-plugin</artifactId>

0 commit comments

Comments
 (0)