Automatisierung der semantischen Versionierung mit Maven (SemVer GitFlow Maven)

Verwenden Sie einen semantischen Ansatz zur Versionskontrolle? Verwenden Sie gitflow? Sie sind höchstwahrscheinlich mit dem Anpassen von Versionen, dem Erstellen von Zweigen, dem Zusammenführen von Master / Dev, dem erneuten Anpassen von Versionen, dem Umgang mit Zusammenführungskonflikten usw. vertraut.



In diesem Artikel werde ich kurz den Release-Prozess erläutern, den wir im Wesentlichen für unsere Bibliotheken verwenden, und wie wir ihn automatisiert haben. Wir verwenden normalerweise einen CI / CD-Ansatz mit Build-Nummern, aber für unsere Bibliotheken haben wir uns für die semantische Versionierung entschieden. Ich bin in mehreren Unternehmen auf den langwierigen Release-Prozess gestoßen, der damit einhergeht, und jetzt habe ich endlich eine Lösung gefunden.



Dieser Artikel handelt von Maven, aber es gibt auch viele Alternativen zu Gradle .



Ein Beispielprojekt finden Sie auf unserer GitHub- Seite .



Semantische Versionierung und Git



Die semantische Versionierung ist das Klassifizierungssystem für Ihre Releases. Ich bin sicher, Sie haben Versionsnummern wie 1.6.4, 1.7.10, 1.12.2 und andere gesehen. Diese Zahlen stehen für MAJOR.MINOR.PATCH (MAJOR.MINOR.PATCH)



Darüber hinaus gibt es Versionen von SNAPSHOT, die gleich aussehen, jedoch am Ende "-SNAPSHOT" hinzufügen, z. B. 1.14.4-SNAPSHOT.



Ein typischer Freigabeprozess besteht aus den folgenden Schritten:



  1. Erstellen Sie einen Release-Zweig aus dem Entwicklungszweig (im Folgenden: Entwicklungszweig).
  2. Ändern Sie die Version in allen pom.xml-Dateien von SNAPSHOT (1.2.3-SNAPSHOT) in Nicht-SNAPSHOT (1.2.3) im Release-Zweig.
  3. Aktualisieren Sie die SNAPSHOT-Version im Entwicklungszweig (1.2.4-SNAPSHOT).
  4. Wenn alles für die Freigabe erledigt ist, führen Sie den Freigabezweig in den Hauptzweig ein. Dies ist die aktuelle Version.
  5. Führen Sie den Hauptzweig oder den Freigabezweig wieder in den Entwicklungszweig ein.


/ , : , , .



, , . , merge .



?



  • , .
  • master SNAPSHOT.
  • CI, .
  • merge .
  • hotfixes ( master ).


gitflow-maven



, maven, pom.xml. . , .



, , . , . , : gitflow-maven-plugin.



, :



  • .
  • release .
  • hotfix.
  • (Merging) .


, . , CI/CD, , .



, (goals) maven. , .



:



, .



$ mvn gitflow:release-start -B


release (-B Batch Mode)



$ mvn gitflow:release


. master .



, , .



$ mvn gitflow:hotfix-start -B


$ mvn gitflow:hotfix-finish -B -DhotfixVersion=1.8.9b 


hotfix master , 1.8.9b . . - , .





, poms:



<build>
    <plugins>
        <plugin>
            <groupId>com.amashchenko.maven.plugin</groupId>
            <artifactId>gitflow-maven-plugin</artifactId>
            <version>1.13.0</version>
            <configuration>
                <!-- optional configuration -->
            </configuration>
        </plugin>
    </plugins>
</build>


GitHub maven central.



GitHub. :



<configuration>
    <!-- We use maven wrapper in all our projects instead of a local maven installation -->
    <mvnExecutable>./mvnw</mvnExecutable>

    <!-- Don’t push to the git remote. Very useful for testing locally -->
    <pushRemote>true</pushRemote>

    <!-- Set to true to immediately bump the development version when creating a release branch -->
    <commitDevelopmentVersionAtStart>false</commitDevelopmentVersionAtStart>

    <!-- Which digit to increas in major.minor.patch versioning, the values being 0.1.2 respectively.
         By default the rightmost number is increased.
         Pass in the number via parameter or profile to allow configuration,
         since everything set in the file can't be overwritten via command line -->
    <versionDigitToIncrement>${gitflowDigitToIncrement}</versionDigitToIncrement>

    <!-- Execute mvn verify before release -->
    <preReleaseGoals>verify</preReleaseGoals>
    <preHotfixGoals>verify</preHotfixGoals>

    <!-- Configure branches -->
    <gitFlowConfig>
        <productionBranch>master</productionBranch>
        <!-- default is develop, but we use development -->
        <developmentBranch>development</developmentBranch>
    </gitFlowConfig>
</configuration>


, , . , Gitlab CI.



Gitlab CI



CI/CD Gitlab CI , commit snapshot, merge master — release.



, — , master merge , hotfixes.



Gitlab CI, . :





release. , release, release, snapshot, (merge) master snapshot. - .



git Gitlab CI



git Gitlab CI, : , CI git.



write_repository. , , .



GITLAB_TOKEN, protected, development, release/* hotfix/* (protected). , .



git remote runner, CI . , Gitlab, :



$ git remote set-url --push origin "https://oauth2:${GITLAB_TOKEN}@${CI_SERVER_HOST}/${CI_PROJECT_PATH}.git"


git . Git «», git. , git , . :



$ git config user.name "Gitlab CI"
$ git config user.email gitlab-ci@viesure.io


git, CI. .





, git CI, gitflow. .



, , :



· MINOR



· PATCH hotfixes



.



(goals) -B, , .



Release



$ ./mvnw gitflow: release -B -DgitflowDigitToIncrement = $RELEASE_DIGIT


. master SNAPSHOT , . (goal ) maven , .





$ ./mvnw gitflow: release-start -B -DgitflowDigitToIncrement = $RELEASE_DIGIT


$ git push origin HEAD


. , , , (, , ). , , .



$ git symbolic-ref refs/heads/$CI_COMMIT_REF_NAME refs/remotes/origin/$CI_COMMIT_REF_NAME
$ ./mvnw gitflow:release-finish -B -DgitflowDigitToIncrement=$RELEASE_DIGIT


release . Git ( ref) HEAD . Gitlab CI . HEAD . , , HEAD.



master , .



(Hotfix)



, , , , .



$ ./mvnw gitflow:hotfix-start -B -DgitflowDigitToIncrement=$HOTFIX_DIGIT
$ git push origin HEAD


Hotfix-start hotfix, .



$ export CURRENT_VERSION=${CI_COMMIT_REF_NAME/hotfix\/}
$ git symbolic-ref refs/heads/$CI_COMMIT_REF_NAME refs/remotes/origin/$CI_COMMIT_REF_NAME
$ ./mvnw gitflow:hotfix-finish -B -DgitflowDigitToIncrement=$HOTFIX_DIGIT -DhotfixVersion=$CURRENT_VERSION


Hotfix-finish master . : . , , . .



, hotfix-start , . , .



. , .





. , - !



, git CI runners . , , .



, . CI .



Gitlab CI GitHub.








All Articles