-
Oumayma Rahabat a rédigé
release.sh 1.68 Kio
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/bin/bash
set -e
# Function to read the current version from pom.xml
get_current_version() {
mvn help:evaluate -Dexpression=project.version -q -DforceStdout
}
# Read the current version from pom.xml
CURRENT_VERSION=$(get_current_version)
RELEASE_VERSION=${CURRENT_VERSION/-SNAPSHOT/-RELEASE}
echo "Current version: $CURRENT_VERSION"
echo "Release version: $RELEASE_VERSION"
git remote set-url origin "https://oauth2:${GITLAB_API_TOKEN}@${GITLAB_PROJECT_URL}"
# Update pom.xml to release version, commit and tag
mvn versions:set -DnewVersion=$RELEASE_VERSION -DgenerateBackupPoms=false
mvn versions:commit
git add pom.xml
git commit -m "Prepare release $RELEASE_VERSION [skip ci]"
git tag -a $RELEASE_VERSION -m "Release $RELEASE_VERSION"
# Push changes to develop branch along with tags
git push origin HEAD:develop --tags
# Create the release via API
curl --header "Content-Type: application/json" \
--header "PRIVATE-TOKEN: $GITLAB_API_TOKEN" \
--data "{
\"name\": \"Release of $RELEASE_VERSION\",
\"tag_name\": \"$RELEASE_VERSION\",
\"ref\": \"develop\"
}" \
--request POST "https://mc-git.com/api/v4/projects/$CI_PROJECT_ID/releases"
# Determine the next snapshot version
IFS='.' read -ra ADDR <<< "${CURRENT_VERSION/-SNAPSHOT/}"
if [ ${ADDR[2]} -eq 999 ]; then
if [ ${ADDR[1]} -eq 99 ]; then
NEXT_SNAPSHOT="$((ADDR[0]+1)).0.0-SNAPSHOT"
else
NEXT_SNAPSHOT="${ADDR[0]}.$((ADDR[1]+1)).0-SNAPSHOT"
fi
else
NEXT_SNAPSHOT="${ADDR[0]}.${ADDR[1]}.$((ADDR[2]+1))-SNAPSHOT"
fi
echo "Next snapshot version: $NEXT_SNAPSHOT"
# Output new tag for next stages
echo $RELEASE_VERSION > release_version
echo $NEXT_SNAPSHOT > next_snapshot_version