Skip to content

Commit 6561f69

Browse files
committed
Rm-3196: release workflow
1 parent 4158415 commit 6561f69

File tree

7 files changed

+315
-21
lines changed

7 files changed

+315
-21
lines changed

README.md

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -202,32 +202,14 @@ service haveged start
202202

203203
See `cdoc2-cli/README.md`
204204

205-
## Releasing
205+
## Releasing and version management
206206

207-
First update CHANGELOG.md - follow semantic versioning
207+
See [VERSIONING.md](VERSIONING.md)
208208

209-
Will update version numbers in pom.xml files and create tag with version v{x.y.z} in git
210209

211-
# Non-Interactive mode without pushing changes (for release simulation)
212-
```
213-
mvn release:clean
214-
mvn --batch-mode -Dtag=v{x.y.z} release:prepare -DreleaseVersion={x.y.z} -DdevelopmentVersion={x.y+1.z}-SNAPSHOT -DdryRun=true -DpushChanges=false
215-
mvn release:perform -Darguments="-Dmaven.deploy.skip=true"
216-
```
217-
218-
# Non-Interactive mode
219-
```
220-
mvn release:clean
221-
mvn --batch-mode -Dtag=v{x.y.z} release:prepare -DreleaseVersion={x.y.z} -DdevelopmentVersion={x.y+1.z}-SNAPSHOT -DdeveloperConnectionUrl=scm:git:${git.repo.url}"
222-
mvn release:perform -Darguments="-Dmaven.deploy.skip=true"
223-
```
224210

225-
Verify that git repositories are synced (master points to same commit) and the tag is pushed (using `git push <remote> v{x.y.z}`).
226211

227-
As maven repository doesn't exist yet, then maven deploy is not performed
228212

229-
For more info, see
230-
[Maven Non-interactive Release](https://maven.apache.org/maven-release/maven-release-plugin/examples/non-interactive-release.html)
231213

232214

233215

VERSIONING.md

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
# Versioning guidelines for CDOC2 project
2+
3+
CDOC2 modules are split between two repositories (or more in future). As all modules are not in the
4+
same repository, then version management becomes necessity.
5+
6+
To help with version management, this document describes some ways to manage module versions.
7+
8+
CDOC2 project tries to follow [semantic versioning](https://semver.org/)
9+
10+
## Development without release (inc_version.sh)
11+
12+
* Create feature branch <TASK_ID>_<short_description>
13+
* Make changes
14+
15+
Before opening merge request, run `inc_versions.sh -d` (dry-run) and `inc_versions.sh`
16+
17+
This, will scan modules and increase module version only for changed modules that are not already on
18+
"-SNAPSHOT" version. Changes are detected only for current branch and won't work for main branch.
19+
20+
* `git diff` to verify changes
21+
* Commit, push
22+
* Create MR
23+
24+
`inc_version.sh -d` will print out changed modules, but doesn't change any files.
25+
26+
The script is not perfect, for example if you only change README in a module, then module is still
27+
considered changed although no code changes.
28+
29+
## Using latest version of modules (use_latest_snapshot.sh)
30+
31+
After creating new version Maven module or artifact, install it locally
32+
33+
`mvn install`
34+
`mvn -f <module_name> install`
35+
36+
### Update cdoc2 dependencies for single module
37+
38+
* `mvn -f <module> versions:use-latest-versions -Dincludes=ee.cyber.cdoc2:* -DexcludeReactor=false -DallowSnapshots=true`
39+
40+
Example: `mvn -f cdoc2-server/get-server versions:use-latest-versions -Dincludes=ee.cyber.cdoc2:* -DexcludeReactor=false -DallowSnapshots=true`
41+
42+
43+
### Update cdoc2 dependencies for all modules in repository
44+
45+
* Run `use_latest_snapshot.sh` to update all modules
46+
* `git diff` to verify changes
47+
48+
## Releases (prepare_release.sh and make_release.sh)
49+
50+
General release procedure:
51+
52+
* Checkout clean branch (usually 'master')
53+
* `prepare_release.sh` (changes versions to RELEASE versions and runs tests)
54+
* Verify changes (`git diff`)
55+
* Edit CHANGELOG.md
56+
* `make_release.sh` (`git commit; git push` RELEASE branch and `mvn deploy` RELEASE artifacts)
57+
58+
This will change -SNAPSHOT version to release version, update dependencies in all modules to latest
59+
non-SNAPSHOT version. Build, test, create release branch, push changes, deploy maven artifacts.
60+
61+
Without parameters `prepare_release.sh` will use version (with -SNAPSHOT removed) from parent pom.
62+
To specify custom release version use `-v`, example `prepare_release.sh -v 1.2.3`. This will update
63+
version in parent pom before changing other versions.
64+
65+
If everything went well, then
66+
* release branch was created with name 'release_v<parent-pom.version>'
67+
* Maven artifacts with release version are in Maven repository
68+
* original branch is checked out ('master' usually)
69+
70+
To finish create squash merge from release branch to main branch
71+
```bash
72+
git merge --squash $RELEASE_BRANCH
73+
git commit -m "Squashed commit from $RELEASE_BRANCH"
74+
git push $GIT_REMOTE $GIT_BRANCH
75+
```
76+
77+
### Release cdoc2-java-ref-impl and cdoc2-capsule-server
78+
79+
Since test code for cdoc2-capsule-server depends on cdoc2-java-ref-impl `cdoc2-lib` module and
80+
transiently `cdoc2-client` module, then for bigger releases following procedure is recommended:
81+
82+
* Checkout both repositories
83+
* Run `prepare_release.sh` in `cdoc2-java-ref-impl` and then in `cdoc2-capsule-server`. That installs
84+
`cdoc2-lib` into local maven repository and `cdoc2-capsule-server` will use it during testing
85+
('mvn verify')
86+
* Update CHANGELOGs in both repositories
87+
* Run `make_release.sh` in `cdoc2-java-ref-impl` and then in `cdoc2-capsule-server`
88+
89+
### make_release.sh without deploy
90+
91+
`make_release.sh -d` will create release branch, but will not deploy Maven artifacts.

cdoc2-client/pom.xml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
33
<modelVersion>4.0.0</modelVersion>
4+
<parent>
5+
<artifactId>cdoc2</artifactId>
6+
<groupId>ee.cyber.cdoc2</groupId>
7+
<version>1.3.0-SNAPSHOT</version>
8+
</parent>
49

510
<artifactId>cdoc2-client</artifactId>
6-
<groupId>ee.cyber.cdoc2</groupId>
711
<version>1.3.0-SNAPSHOT</version>
812
<description>CDOC2 server client generation from openapi specification</description>
913

inc_versions.sh

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
#!/bin/bash
2+
3+
# Increase maven module version for changed modules based on git diff.
4+
5+
# Based on
6+
# https://gist.github.com/corneil/20585cb944615abb434063b8507d2d8d
7+
8+
9+
function itemInModules() {
10+
local e
11+
for e in ${MODULES}; do
12+
if [[ "$e" == "$ITEM" ]]; then
13+
echo "1"
14+
return 0
15+
fi
16+
done
17+
echo "0"
18+
}
19+
function addItem() {
20+
if [ "$MODULES" == "" ]; then
21+
echo "$1"
22+
else
23+
echo "$MODULES $1"
24+
fi
25+
}
26+
27+
PERFORM=true
28+
29+
while getopts ":d" opt; do
30+
case ${opt} in
31+
d)
32+
echo "-d Dry-run mode"
33+
PERFORM=false
34+
;;
35+
?)
36+
echo "Invalid option: -${OPTARG}."
37+
exit 1
38+
;;
39+
esac
40+
done
41+
42+
# Find parent branch
43+
#https://gist.github.com/joechrysler/6073741
44+
#https://stackoverflow.com/questions/3161204/how-to-find-the-nearest-parent-of-a-git-branch?noredirect=1&lq=1
45+
PARENT_BRANCH=$(git show-branch -a \
46+
| grep '\*' \
47+
| grep -v "$(git rev-parse --abbrev-ref HEAD)" \
48+
| head -n1 \
49+
| sed 's/.*\[\(.*\)\].*/\1/' \
50+
| sed 's/[\^~].*//')
51+
echo
52+
echo "Using $PARENT_BRANCH as parent branch"
53+
echo
54+
55+
56+
MODIFIED=$(git diff --name-only "$PARENT_BRANCH")
57+
ALL_MODULES=$(find . -name "pom.xml" -type f -exec dirname '{}' \; | sed 's/\.\///' | sort -r)
58+
MODULES=
59+
for file in $MODIFIED; do
60+
#FILE=$(realpath $file)
61+
echo "$file was changed"
62+
for ITEM in $ALL_MODULES; do
63+
if [[ "$ITEM" != "." ]] && [[ "$file" == *"$ITEM"* ]]; then
64+
echo "Matched $ITEM"
65+
HAS_ITEM=$(itemInModules)
66+
if ((HAS_ITEM == 0)); then
67+
MODULES=$(addItem "$ITEM")
68+
fi
69+
break
70+
fi
71+
done
72+
done
73+
74+
#echo "All modules: $ALL_MODULES"
75+
echo
76+
echo "Changed modules: $MODULES"
77+
echo
78+
for module in $MODULES; do
79+
80+
if [[ "$PERFORM" = true ]]; then
81+
MODULE_VERSION=$(mvn -f "$module" help:evaluate -Dexpression=project.version -q -DforceStdout)
82+
if [[ ${MODULE_VERSION} == *"SNAPSHOT"* ]];then
83+
echo "Ignoring $module as it already on SNAPSHOT "
84+
else
85+
echo "Creating -SNAPSHOT minor version for $module;"
86+
mvn -f "$module" versions:set -DnextSnapshot -DnextSnapshotIndexToIncrement=2
87+
fi
88+
else
89+
echo "Dry-run. Not increasing version for $module."
90+
fi
91+
done

make_release.sh

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
#!/bin/bash
2+
3+
set -o xtrace
4+
# git commit
5+
# git tag
6+
# git push
7+
# mvn deploy
8+
# docker deploy
9+
10+
11+
CDOC2_VER=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)
12+
13+
GIT_BRANCH=$(git branch --show-current)
14+
GIT_REMOTE=$(git config --get-regexp "branch\.$GIT_BRANCH\.remote" | sed -e "s/^.* //")
15+
16+
# if mvn deploy is called
17+
DEPLOY=true
18+
19+
if [[ "master" != "$GIT_BRANCH" ]]; then
20+
echo "Not on 'master' branch. You have 5 seconds to abort or the script will continue"
21+
sleep 5
22+
fi
23+
24+
if [[ ${CDOC2_VER} == *"SNAPSHOT"* ]];then
25+
echo "cdoc2 is still on SNAPSHOT ${CDOC2_VER}. Did you run prepare_release.sh?"
26+
exit 2
27+
fi
28+
29+
if ! grep -q ${CDOC2_VER} "CHANGELOG.md"; then
30+
echo "Can't find \"${CDOC2_VER}\" in CHANGELOG.md. Did you write CHANGELOG?"
31+
exit 3
32+
fi
33+
34+
while getopts ":d" opt; do
35+
case ${opt} in
36+
d)
37+
echo "-d Dry-run mode. Deploy will not be performed."
38+
DEPLOY=false
39+
;;
40+
?)
41+
echo "Invalid option: -${OPTARG}."
42+
exit 1
43+
;;
44+
esac
45+
done
46+
47+
48+
49+
export RELEASE_BRANCH="release_v$CDOC2_VER"
50+
export RELEASE_TAG="v$CDOC2_VER"
51+
52+
git checkout -b "$RELEASE_BRANCH" || exit 1
53+
git commit -a -m "Release cdoc2-java-ref-impl version $CDOC2_VER" || exit 1
54+
git push "$GIT_REMOTE" -u "$RELEASE_BRANCH" || exit 1
55+
git tag "$RELEASE_TAG" || exit 1
56+
git push --tags $GIT_REMOTE "$RELEASE_TAG" || exit 1
57+
echo "Created release branch $RELEASE_BRANCH"
58+
59+
# to delete branch, run:
60+
# git checkout parent_branch
61+
# git branch -D test_v1.2.0
62+
# git push gitlab.ext -d test_v1.2.0
63+
64+
65+
#deploy RELEASE modules
66+
if [[ "$DEPLOY" = true ]]; then
67+
mvn deploy -DskipTests
68+
if [[ $? -ne 0 ]]; then
69+
echo "mvn deploy failed. If this was temporary error, it may be possible to recover by re-running 'mvn deploy -DskipTests'"
70+
fi
71+
else
72+
echo "DEPLOY=$DEPLOY. To deploy Maven artifacts, run 'mvn deploy -DskipTests' on branch $RELEASE_BRANCH"
73+
fi
74+
75+
76+
# switch back to original branch
77+
git checkout $GIT_BRANCH
78+
79+
echo "Created release branch $RELEASE_BRANCH"
80+
echo "To merge squash back to your branch. Run"
81+
echo "git merge --squash $RELEASE_BRANCH"
82+
echo "git commit -m \"Squashed commit from $RELEASE_BRANCH\""
83+
echo "git push $GIT_REMOTE $GIT_BRANCH"

prepare_release.sh

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/bin/bash
2+
3+
GIT_BRANCH=$(git branch --show-current)
4+
5+
if [[ "master" != "$GIT_BRANCH" ]]; then
6+
echo "Not on 'master' branch. You have 5 seconds to abort, before script will continue"
7+
sleep 5
8+
fi
9+
10+
11+
#if [[ -n $(git cherry -v) ]]; then
12+
# echo "Detected unpushed commits. Exit"
13+
# exit 1
14+
#fi
15+
#
16+
#if [[ -n $(git status --porcelain --untracked-files=no) ]]; then
17+
# echo "Uncommited changes detected. Exit"
18+
# exit 1
19+
#fi
20+
21+
while getopts "v:" opt; do
22+
case $opt in
23+
v)
24+
echo "Changing parent pom version to: $OPTARG" >&2
25+
mvn versions:set -DnewVersion="${OPTARG}" -DupdateMatchingVersions=false
26+
;;
27+
?)
28+
echo "Invalid option: -${OPTARG}."
29+
exit 1
30+
;;
31+
esac
32+
done
33+
34+
35+
# replace module -SNAPSHOT version with release version (non-SNAPSHOT)
36+
mvn versions:set -DremoveSnapshot
37+
# build and install into local maven package repository
38+
mvn install

use_latest_snapshot.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/bash
2+
3+
#Update dependencies for latest -SNAPSHOT
4+
5+
mvn versions:use-latest-versions -Dincludes=ee.cyber.cdoc2:* -DexcludeReactor=false -DallowSnapshots=true

0 commit comments

Comments
 (0)