-
Notifications
You must be signed in to change notification settings - Fork 0
113 lines (104 loc) · 3.82 KB
/
release.yml
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# Create a Release
name: "Release"
on:
workflow_dispatch:
inputs:
version:
description: "optional: version to release"
required: false
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
# This will be used by git in all further steps
# We need a PERSONAL ACCESS TOKEN so pushes trigger other GitHub actions
token: ${{ secrets.BOT_ACCESS_TOKEN }}
- name: Calculate realise version
run: |
if [ -z "${{ github.event.inputs.version }}" ]
then
v=$(grep -oPm1 "(?<=<version>)[^<]+" "pom.xml" | sed 's/-SNAPSHOT//')
echo ${{ github.repository }}
else
v=${{ github.event.inputs.version }}
fi
echo "realise version ${v}"
# Set as Environment for all further steps
echo "VERSION=${v}" >> $GITHUB_ENV
- name: Create Release Branch
run: |
# Config git
git config --global user.email "[email protected]"
git config --global user.name "bot"
# create branch
git checkout -b release/v${VERSION}
# Update version
mvn versions:set -DnewVersion=${VERSION} -DprocessAllModules=true
#edit changelog
replace="s/\[unreleased\]/\[${VERSION}\]/"
sed -i ${replace} CHANGELOG.md
replace="s/...HEAD/\...v${VERSION}/"
sed -i ${replace} CHANGELOG.md
# commit & push
git add -A
git commit -m "release ${VERSION}: updated version to ${VERSION}"
git push -u origin release/v${VERSION}
# wait for status of commit to change from pending
- name: Wait for ci pipeline
run: |
STATUS="pending"
# Get commit last commit of release branch
COMMIT=$(git rev-parse HEAD)
echo "Listen for commit $COMMIT"
WAITED="0"
# Time between calls
SLEEP_TIME="60"
while [ "$STATUS" == "pending" ] && [ "$WAITED" -le 1800 ]
do
sleep ${SLEEP_TIME}
WAITED=$((WAITED+SLEEP_TIME))
STATUS=$(gh api /repos/${{ github.repository }}/commits/"${COMMIT}"/status -q .state)
echo "status : $STATUS"
echo "waited $WAITED s"
done
echo "status : $STATUS"
if [ "$STATUS" != "success" ]
then exit 1
fi
env:
GITHUB_TOKEN: ${{ secrets.BOT_ACCESS_TOKEN }}
- name: Merge into Main
run: |
git checkout main
git pull
git merge --no-ff release/v${VERSION}
git tag -a -m "v${VERSION}" "v${VERSION}"
git push --follow-tags
- name: Create Release
run: |
gh release create "v${VERSION}" -t "v${VERSION}" -F CHANGELOG.md -R ${{ github.repository }} --target main
env:
GITHUB_TOKEN: ${{ secrets.BOT_ACCESS_TOKEN }}
- name: Merge into dev
run: |
# increment minor version and add SNAPSHOT
ARRAY_VERSION=( ${VERSION//./ } )
git checkout release/v${VERSION}
NEXT_VERSION=${ARRAY_VERSION[0]}.$((ARRAY_VERSION[1]+1)).0-SNAPSHOT
echo "next version: $NEXT_VERSION"
# update version
mvn versions:set -DnewVersion=${NEXT_VERSION} -DprocessAllModules=true
#edit changelog
sed -i '5i ## [unreleased]\n ### Added \n ### Fixed \n' CHANGELOG.md
replace="$ a \[unreleased\]: https:\/\/github.com\/ehrbase\/openEHR_SDK\/compare\/v$VERSION...HEAD"
sed -i "${replace}" CHANGELOG.md
git add -A
git commit -m " updated version to ${NEXT_VERSION}"
git checkout develop
git pull
git merge --no-ff release/v${VERSION}
git push