CI/CD: Enforcing release number in Subversion (SVN) commit message

CI/CD: Enforcing release number in Subversion (SVN) commit message

Gepubliceerd: Categorie: Oracle

While working on our CI/CD implementation, we were looking for a way to enforce everyone to include the release number in the SVN commit message. However, this should happen only whenever someone merges into the Release branch. Our automated build script uses this release number from the SVN commit to version each component and release artifact. We will show how to enforce this on the SVN server using a pre-commit hook.

Use case: Release number

Each time a developer merges changes into the release branch, our CI/CD server kicks in to build and deploy a new release. In our case, we require developers to enter a release number into the SVN commit message, to enable our build/deploy scripting to determine the version of this release and its artifacts.

Fig 1: Example of commit with release number SOA_2019_41_1

Pre-commit hook

Using a pre-commit hook, SVN enables administrators to do a few checks before actually committing sources into the repository.

Each time before a commit is persisted, a batch script is run from the SVNROOT folder.

Fig 2: SVN hooks located in the SVN Root

Pre-commit hook requirements

First, our pre-commit hook should only enforce a release number in the comments for commits in the release branch. Secondly, we need to check the commit message to contain a specific release number format.

SVN provides us with a great utility (svnlook) to get information about a specific commit transaction. We were content with only the use of ‘svnlook log’ and ‘svnlook changed’.

For the first requirement, we used the svnlook changed command to see what folder location was changed. Every time we find /branches/Release we need to check the commit message/

Fig 3: Example of svnlook changed output during a pre-commit trigger

For the second requirement, we’ve used svnlook log to check the commit message.

Fig 4: Example of svnlook log output during a pre-commit trigger.

In the next sections, we will show both a Linux and Windows implementation of this particular pre-commit hook.

Linux hook
  1. #!/bin/sh
  3. REPOS="$1"
  4. TXN="$2"
  6. echo "Repository $REPOS" >&2
  7. echo "TXN $TXN" >&2
  10. SVNLOOK=/usr/bin/svnlook
  12. RELEASE=`$SVNLOOK log -t "$TXN" "$REPOS" | grep -o "SOA_[0-9][0-9][0-9][0-9]_[0-9][0-9]_[0-9][0-9]"`
  13. FOLDER=`$SVNLOOK changed "$REPOS" | grep -o "SOA/branches/Release"`
  15. # Only check the release branch
  16. if [ "$FOLDER" == "SOA/branches/Release" ]
  17. then
  18. # If the RELEASE variable does not contain any match, raise error and abort commit (exit1)
  19. if [ "$RELEASE" == "" ]
  20. then
  21. echo "No valid release number (e.g.: SOA_2019_41_01)" >&2
  22. exit 1
  23. else
  24. echo "Valid release number found $RELEASE" >&2
  25. fi
  26. fi
  29. # All checks passed, so allow the commit.
  30. exit 0
Windows hook using .bat file
  1. setlocal EnableDelayedExpansion
  3. set REPOS=%1
  4. set TXN=%2
  6. svnlook changed %REPOS% -t %TXN% | findstr "SOA/branches/Release" > null >&2
  7. if not errorlevel 1 (
  8. svnlook log %REPOS% -t %TXN% | findstr /R "SOA_[0-9][0-9][0-9][0-9]_[0-9][0-9]_[0-9][0-9]" > null >&2
  9. if errorlevel 1 (goto err)
  10. )
  12. exit 0
  14. :err
  15. echo. 1>&2
  16. echo REPOS %REPOS% 1>&2
  17. echo TXN %TXN% 1>&2
  18. echo Your commit has been blocked because you didn't enter a valid release number (e.g.: SOA_2019_41_01). 1>&2
  19. echo Please write a log message containing a release number and describe the changes made and try again. 1>&2
  20. echo Thanks 1>&2
  21. exit 1
Richard Velden
Over auteur Richard Velden

Oracle Fusion Middleware Developer at Qualogy. Specializes in integration and cloud development using Oracle technologies such as: SOA Suite, Service Bus, Integration and Process Cloud.

Meer posts van Richard Velden
Reactie plaatsen