Skip to content

Commit 8d4896e

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

File tree

5 files changed

+215
-12
lines changed

5 files changed

+215
-12
lines changed

.github/workflows/flakeFinder.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ jobs:
2222
--out-dir "failed_tests/"
2323
env:
2424
AWS_REGION: us-west-2
25+
GIT_BRANCH: main
2526
- name: Upload Errors
2627
uses: actions/upload-artifact@v4
2728
with:

.github/workflows/maven.yml

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ jobs:
1818
os: [ubuntu-latest, windows-latest]
1919
fail-fast: false
2020
name: Build on ${{ matrix.os }}
21+
env:
22+
GIT_BRANCH: ${{ github.head_ref || github.ref_name }}
2123
steps:
2224
- uses: actions/checkout@v4
2325
with:
@@ -44,9 +46,16 @@ jobs:
4446
env:
4547
AWS_REGION: us-west-2
4648
run: |
47-
sudo -E mvn -ntp -U verify
49+
sudo -E mvn -ntp -U verify
4850
sudo chown -R runner target
4951
if: matrix.os == 'ubuntu-latest'
52+
- name: Show file
53+
run: |
54+
sudo cat target/git.properties
55+
git branch --show-current
56+
git rev-parse --abbrev-ref HEAD
57+
git symbolic-ref --short HEAD
58+
if: matrix.os == 'ubuntu-latest' && failure()
5059
- name: Upload Failed Test Report
5160
uses: actions/upload-artifact@v4
5261
if: failure()
@@ -68,8 +77,7 @@ jobs:
6877
run: python3 .github/scripts/cover2cover.py target/jacoco-report/jacoco-it/jacoco.xml src/main/java > target/jacoco-report/cobertura-it.xml
6978
if: matrix.os == 'ubuntu-latest'
7079
- name: Check compatibility
71-
run: >-
72-
mvn -ntp japicmp:cmp -DskipTests
80+
run: mvn -ntp initialize japicmp:cmp -DskipTests
7381
if: github.event_name == 'pull_request' && matrix.os == 'ubuntu-latest'
7482
- name: Upload Compatibility Report
7583
uses: actions/upload-artifact@v4

nucleus-build-version.xml

Lines changed: 169 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,169 @@
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+
<!-- Load environment variables -->
31+
<property environment="env"/>
32+
<exec executable="git" outputproperty="git.branch">
33+
<arg value="branch"/>
34+
<arg value="--show-current"/>
35+
</exec>
36+
<!-- Use env var iff git.branch is empty and env var is set. Otherwise, use default -->
37+
<condition property="git.branch" value="${env.GIT_BRANCH}" else="dev">
38+
<and>
39+
<isset property="git.branch"/>
40+
<not><equals arg1="${git.branch}" arg2=""/></not>
41+
42+
<isset property="env.GIT_BRANCH"/>
43+
<not><equals arg1="${env.GIT_BRANCH}" arg2=""/></not>
44+
</and>
45+
</condition>
46+
<echo file="${project.build.directory}/git.properties" append="true">git.branch=${git.branch}${line.separator}</echo>
47+
</target>
48+
</configuration>
49+
</execution>
50+
<!-- Get latest Git tag for version determination -->
51+
<execution>
52+
<id>set-git-latest-tag-info</id>
53+
<phase>initialize</phase>
54+
<goals>
55+
<goal>run</goal>
56+
</goals>
57+
<configuration>
58+
<target>
59+
<!-- Get the most recent tag sorted by version -->
60+
<exec executable="git" outputproperty="git.latest.tag">
61+
<arg value="for-each-ref"/>
62+
<arg value="--count=1"/>
63+
<arg value="--sort=-version:refname"/>
64+
<arg value="--format=%(refname:short)"/>
65+
<arg value="refs/tags"/>
66+
</exec>
67+
<!-- Write latest tag to git.properties file -->
68+
<echo file="${project.build.directory}/git.properties" append="true">git.latest.tag=${git.latest.tag}${line.separator}</echo>
69+
</target>
70+
</configuration>
71+
</execution>
72+
</executions>
73+
</plugin>
74+
75+
<!-- Load the generated Git properties into Maven properties -->
76+
<plugin>
77+
<groupId>org.codehaus.mojo</groupId>
78+
<artifactId>properties-maven-plugin</artifactId>
79+
<version>1.1.0</version>
80+
<executions>
81+
<execution>
82+
<phase>initialize</phase>
83+
<goals>
84+
<goal>read-project-properties</goal>
85+
</goals>
86+
<configuration>
87+
<files>
88+
<!-- Read the git.properties file created above -->
89+
<file>${project.build.directory}/git.properties</file>
90+
</files>
91+
</configuration>
92+
</execution>
93+
</executions>
94+
</plugin>
95+
96+
<!-- Process version strings using regex transformations -->
97+
<plugin>
98+
<groupId>org.codehaus.mojo</groupId>
99+
<artifactId>build-helper-maven-plugin</artifactId>
100+
<version>3.6.1</version>
101+
<executions>
102+
<!-- Check if current branch is a release branch -->
103+
<execution>
104+
<id>process-release-branch-info</id>
105+
<phase>initialize</phase>
106+
<goals><goal>regex-property</goal></goals>
107+
<configuration>
108+
<name>release.branch.match</name>
109+
<value>${git.branch}</value>
110+
<!-- Match release_MAJOR.MINOR.x pattern and extract version -->
111+
<regex>^release_(\d+\.\d+)\.x$</regex>
112+
<!-- Transform release_MAJOR.MINOR.x to MAJOR.MINOR.0 -->
113+
<replacement>$1.0</replacement>
114+
<failIfNoMatch>false</failIfNoMatch>
115+
</configuration>
116+
</execution>
117+
<!-- Set final branch version (dev for non-release branches) -->
118+
<execution>
119+
<id>process-non-release-branch-info</id>
120+
<phase>initialize</phase>
121+
<goals><goal>regex-property</goal></goals>
122+
<configuration>
123+
<name>git.current.branch.snapshot</name>
124+
<value>${release.branch.match}</value>
125+
<!-- Default to 'dev' if not a release branch -->
126+
<regex>^${git.branch}$</regex>
127+
<replacement>dev</replacement>
128+
<failIfNoMatch>false</failIfNoMatch>
129+
</configuration>
130+
</execution>
131+
<!-- Convert latest tag to SNAPSHOT version format -->
132+
<execution>
133+
<id>process-latest-tag-info</id>
134+
<phase>initialize</phase>
135+
<goals><goal>regex-property</goal></goals>
136+
<configuration>
137+
<name>git.latest.tag.snapshot</name>
138+
<value>${git.latest.tag}</value>
139+
<!-- Transform vMAJOR.MINOR.PATCH to MAJOR.MINOR.0-SNAPSHOT -->
140+
<regex>^v?(\d+)\.(\d+)\.\d+.*$</regex>
141+
<replacement>$1.$2.0-SNAPSHOT</replacement>
142+
<failIfNoMatch>false</failIfNoMatch>
143+
</configuration>
144+
</execution>
145+
</executions>
146+
</plugin>
147+
148+
<!-- Write final git.current.branch.snapshot version information -->
149+
<plugin>
150+
<groupId>org.apache.maven.plugins</groupId>
151+
<artifactId>maven-antrun-plugin</artifactId>
152+
<version>3.1.0</version>
153+
<executions>
154+
<execution>
155+
<id>set-build-snapshot-version</id>
156+
<phase>compile</phase>
157+
<goals><goal>run</goal></goals>
158+
<configuration>
159+
<target>
160+
<!-- Append final branch snapshot version to properties -->
161+
<echo file="${project.build.directory}/git.properties" append="true">git.current.branch.snapshot=${git.current.branch.snapshot}${line.separator}</echo>
162+
</target>
163+
</configuration>
164+
</execution>
165+
</executions>
166+
</plugin>
167+
</plugins>
168+
</build>
169+
</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)