Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

create a post about automated version generation using git in maven and et al. #43

Open
wildone opened this issue Feb 2, 2022 · 0 comments

Comments

@wildone
Copy link
Member

wildone commented Feb 2, 2022

generate build version number based on commit count since the last tag. use semver otherwise you will encounter all sort of issues namely "JCR Installer Pause Issue" as well as packages and bundles not installing properly. See https://semver.org
same concept applies to piplines.

Maven

<!-- get git information to update artifacts version -->
            <plugin>
                <groupId>pl.project13.maven</groupId>
                <artifactId>git-commit-id-plugin</artifactId>
                <version>3.0.1</version>
                <executions>
                    <execution>
                        <phase>validate</phase>
                        <id>get-the-git-infos</id>
                        <goals>
                            <goal>revision</goal>
                        </goals>
                        <!-- *NOTE*: The default phase of revision is initialize, but in case you want to change it, you can do so by adding the phase here -->
                        <!--<phase>initialize</phase>-->
                    </execution>
                    <execution>
                        <phase>validate</phase>
                        <id>validate-the-git-infos</id>
                        <goals>
                            <goal>validateRevision</goal>
                        </goals>
                        <!-- *NOTE*: The default phase of validateRevision is verify, but in case you want to change it, you can do so by adding the phase here -->
                        <!--<phase>package</phase>-->
                    </execution>
                </executions>
                <configuration>
                    <skipPoms>false</skipPoms>
                    <injectAllReactorProjects>true</injectAllReactorProjects>
                    <dateFormat>yyyy.MM.dd</dateFormat>
                    <gitDescribe>
                        <!--<always>true</always>-->
                        <dirty>-SNAPSHOT</dirty>
                        <!--<match>__null__</match>-->
                        <!--<tags>true</tags>-->
                    </gitDescribe>
                    <includeOnlyProperties>
                        <includeOnlyProperty>^git.closest.tag.name$</includeOnlyProperty>
                        <includeOnlyProperty>^git.closest.tag.commit.count$</includeOnlyProperty>
                    </includeOnlyProperties>
                </configuration>
            </plugin>


            <plugin>
                <groupId>org.codehaus.gmaven</groupId>
                <artifactId>groovy-maven-plugin</artifactId>
                <version>2.0</version>
                <executions>
                    <execution>
                        <id>update-finalname</id>
                        <phase>validate</phase>
                        <goals>
                            <goal>execute</goal>
                        </goals>
                        <configuration>
                            <source>
                                project.build.finalName="${project.artifactId}-${gitClosestTagName}.${gitClosestTagCommitCount}";
                                project.properties['gitClosestTagName']="${git.closest.tag.name}";
                                project.properties['gitClosestTagCommitCount']="${git.closest.tag.commit.count}";
                                println("project.build.finalName=${project.build.finalName}");
                            </source>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

            <!-- update versions for all submodules -->
            <plugin>
                <!-- sets the version for each pom including children pom -->
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>versions-maven-plugin</artifactId>
                <version>2.5</version>
                <executions>
                    <execution>
                        <phase>validate</phase>
                        <goals>
                            <goal>set</goal>
                        </goals>
                        <inherited>false</inherited>
                        <configuration>
                            <!-- comes from the git-commit-id-plugin -->
                            <newVersion>${git.closest.tag.name}.${git.closest.tag.commit.count}</newVersion>
                            <generateBackupPoms>false</generateBackupPoms>
                        </configuration>
                    </execution>
                </executions>
            </plugin>


            <!-- ensure all version variables names are set to updated version -->
            <plugin>
                <groupId>org.codehaus.gmavenplus</groupId>
                <artifactId>gmavenplus-plugin</artifactId>
                <version>1.6</version>
                <executions>
                    <execution>
                        <id>change-version</id>
                        <phase>validate</phase>
                        <goals>
                            <goal>execute</goal>
                        </goals>
                        <configuration>
                            <scripts>
                                <script><![CDATA[
                            import org.apache.maven.artifact.versioning.VersionRange;
                            git_revision = '${git.closest.tag.name}.${git.closest.tag.commit.count}'
                            if (! project.properties['revision']?.trim()) {
                            println 'Change `version` to ' + git_revision
                            System.properties['revision'] = git_revision
                            project.properties['revision'] = git_revision
                            project.properties['project.version'] = git_revision
                            project.properties['git.build.version'] = git_revision
                            project.version = git_revision
                            project.artifact.version = git_revision
                            project.artifact.versionRange = VersionRange.createFromVersion(git_revision)
                            project.build.finalName = '${project.artifactId}-${gitClosestTagName}.${gitClosestTagCommitCount}'
                            }
                            ]]></script>
                            </scripts>
                        </configuration>
                    </execution>

                    <!-- for debug: -->
                    <!--
                    <execution>
                    <id>dump-version</id>
                    <phase>package</phase>
                    <goals>
                    <goal>execute</goal>
                    </goals>
                    <configuration>
                    <scripts>
                    <script><![CDATA[
                    println System.properties['revision']
                    println '${revision}'
                    println '${project.version}'
                    println '${git.build.version}'
                    println project.version
                    println project.artifact
                    println project.artifact.version
                    println project.artifact.versionRange
                    ]]></script>
                    </scripts>
                    </configuration>
                    </execution>
                    -->
                </executions>
                <dependencies>
                    <dependency>
                        <groupId>org.codehaus.groovy</groupId>
                        <artifactId>groovy-all</artifactId>
                        <version>2.4.14</version>
                        <scope>runtime</scope>
                    </dependency>
                </dependencies>
            </plugin>

<!--            &lt;!&ndash; ensure all variables are set &ndash;&gt;-->
<!--            <plugin>-->
<!--                <groupId>org.codehaus.mojo</groupId>-->
<!--                <artifactId>flatten-maven-plugin</artifactId>-->
<!--                <version>1.1.0</version>-->
<!--                <configuration>-->
<!--                    &lt;!&ndash; <flattenMode>ossrh</flattenMode> &ndash;&gt;-->
<!--                    <flattenedPomFilename>.flattened-pom.xml</flattenedPomFilename>-->
<!--                    <outputDirectory>${project.build.directory}</outputDirectory>-->
<!--                    <updatePomFile>true</updatePomFile>-->
<!--                    <flattenMode>resolveCiFriendliesOnly</flattenMode>-->
<!--					<embedBuildProfileDependencies>true</embedBuildProfileDependencies>-->
<!--                </configuration>-->
<!--                <executions>-->
<!--                    <execution>-->
<!--                        <id>flatten</id>-->
<!--                        <phase>process-resources</phase>-->
<!--                        <goals>-->
<!--                            <goal>flatten</goal>-->
<!--                        </goals>-->
<!--                    </execution>-->
<!--                    <execution>-->
<!--                        <id>flatten.clean</id>-->
<!--                        <phase>clean</phase>-->
<!--                        <goals>-->
<!--                            <goal>clean</goal>-->
<!--                        </goals>-->
<!--                    </execution>-->
<!--                </executions>-->
<!--            </plugin>-->

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-site-plugin</artifactId>
                <version>${maven.site.plugin.version}</version>
                <configuration>
                    <locales>en</locales>
                </configuration>
            </plugin>
        </plugins>
        <!-- ensure all artifact names are set to updated version -->
        <finalName>${project.artifactId}-${gitClosestTagName}.${gitClosestTagCommitCount}</finalName>

Pipeline

      - name: set envirnment variables
        id: config
        run: |
          source <(curl -sL https://github.com/aem-design/aemdesign-docker/releases/latest/download/github_get_config.sh)
          source <(curl -sL https://github.com/aem-design/aemdesign-docker/releases/latest/download/github_get_version.sh)

      - uses: meeDamian/[email protected]
        if: github.ref == 'refs/heads/main'
        with:
          token: ${{ secrets.GITHUB_TOKEN }}
          tag: ${{ env.GITHUB_TAG }}
          name: ${{ env.GITHUB_TAG }}
          body: ${{ env.GIT_RELEASE_NOTES }}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant