|
| 1 | +# Create a Release |
| 2 | +name: "Release" |
| 3 | + |
| 4 | +on: |
| 5 | + workflow_dispatch: |
| 6 | + inputs: |
| 7 | + version: |
| 8 | + description: "optional: version to release" |
| 9 | + required: false |
| 10 | + |
| 11 | +jobs: |
| 12 | + build: |
| 13 | + runs-on: ubuntu-latest |
| 14 | + steps: |
| 15 | + - name: Checkout |
| 16 | + uses: actions/checkout@v4 |
| 17 | + with: |
| 18 | + fetch-depth: 0 |
| 19 | + # This will be used by git in all further steps |
| 20 | + # We need a PERSONAL ACCESS TOKEN so pushes trigger other GitHub actions |
| 21 | + token: ${{ secrets.BOT_ACCESS_TOKEN }} |
| 22 | + |
| 23 | + - name: Calculate realise version |
| 24 | + run: | |
| 25 | + if [ -z "${{ github.event.inputs.version }}" ] |
| 26 | + then |
| 27 | + v=$(grep -oPm1 "(?<=<version>)[^<]+" "pom.xml" | sed 's/-SNAPSHOT//') |
| 28 | + echo ${{ github.repository }} |
| 29 | + else |
| 30 | + v=${{ github.event.inputs.version }} |
| 31 | + fi |
| 32 | + echo "realise version ${v}" |
| 33 | + # Set as Environment for all further steps |
| 34 | + echo "VERSION=${v}" >> $GITHUB_ENV |
| 35 | +
|
| 36 | + - name: Create Release Branch |
| 37 | + run: | |
| 38 | + # Config git |
| 39 | + git config --global user.email "bot@ehrbase.org" |
| 40 | + git config --global user.name "bot" |
| 41 | + # create branch |
| 42 | + git checkout -b release/v${VERSION} |
| 43 | + # Update version |
| 44 | + mvn versions:set -DnewVersion=${VERSION} -DprocessAllModules=true |
| 45 | + #edit changelog |
| 46 | + replace="s/\[unreleased\]/\[${VERSION}\]/" |
| 47 | + sed -i ${replace} CHANGELOG.md |
| 48 | + replace="s/...HEAD/\...v${VERSION}/" |
| 49 | + sed -i ${replace} CHANGELOG.md |
| 50 | + # commit & push |
| 51 | + git add -A |
| 52 | + git commit -m "release ${VERSION}: updated version to ${VERSION}" |
| 53 | + git push -u origin release/v${VERSION} |
| 54 | + # wait for status of commit to change from pending |
| 55 | + - name: Wait for ci pipeline |
| 56 | + run: | |
| 57 | + STATUS="pending" |
| 58 | + # Get commit last commit of release branch |
| 59 | + COMMIT=$(git rev-parse HEAD) |
| 60 | + echo "Listen for commit $COMMIT" |
| 61 | + WAITED="0" |
| 62 | + # Time between calls |
| 63 | + SLEEP_TIME="60" |
| 64 | + while [ "$STATUS" == "pending" ] && [ "$WAITED" -le 1800 ] |
| 65 | + do |
| 66 | + sleep ${SLEEP_TIME} |
| 67 | + WAITED=$((WAITED+SLEEP_TIME)) |
| 68 | + STATUS=$(gh api /repos/${{ github.repository }}/commits/"${COMMIT}"/status -q .state) |
| 69 | + echo "status : $STATUS" |
| 70 | + echo "waited $WAITED s" |
| 71 | + done |
| 72 | + echo "status : $STATUS" |
| 73 | + if [ "$STATUS" != "success" ] |
| 74 | + then exit 1 |
| 75 | + fi |
| 76 | + env: |
| 77 | + GITHUB_TOKEN: ${{ secrets.BOT_ACCESS_TOKEN }} |
| 78 | + |
| 79 | + - name: Merge into Main |
| 80 | + run: | |
| 81 | + git checkout main |
| 82 | + git pull |
| 83 | + git merge --no-ff release/v${VERSION} |
| 84 | + git tag -a -m "v${VERSION}" "v${VERSION}" |
| 85 | + git push --follow-tags |
| 86 | +
|
| 87 | + - name: Create Release |
| 88 | + run: | |
| 89 | + gh release create "v${VERSION}" -t "v${VERSION}" -F CHANGELOG.md -R ${{ github.repository }} --target main |
| 90 | + env: |
| 91 | + GITHUB_TOKEN: ${{ secrets.BOT_ACCESS_TOKEN }} |
| 92 | + |
| 93 | + - name: Merge into dev |
| 94 | + run: | |
| 95 | + # increment minor version and add SNAPSHOT |
| 96 | + ARRAY_VERSION=( ${VERSION//./ } ) |
| 97 | + git checkout release/v${VERSION} |
| 98 | + NEXT_VERSION=${ARRAY_VERSION[0]}.$((ARRAY_VERSION[1]+1)).0-SNAPSHOT |
| 99 | + echo "next version: $NEXT_VERSION" |
| 100 | + # update version |
| 101 | + mvn versions:set -DnewVersion=${NEXT_VERSION} -DprocessAllModules=true |
| 102 | + #edit changelog |
| 103 | + sed -i '5i ## [unreleased]\n ### Added \n ### Fixed \n' CHANGELOG.md |
| 104 | + replace="$ a \[unreleased\]: https:\/\/github.com\/ehrbase\/openEHR_SDK\/compare\/v$VERSION...HEAD" |
| 105 | + sed -i "${replace}" CHANGELOG.md |
| 106 | + git add -A |
| 107 | + git commit -m " updated version to ${NEXT_VERSION}" |
| 108 | + git checkout develop |
| 109 | + git pull |
| 110 | + git merge --no-ff release/v${VERSION} |
| 111 | + git push |
| 112 | +
|
| 113 | +
|
0 commit comments