|
| 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> |
0 commit comments