Skip to content

Commit

Permalink
updated set version script: 6
Browse files Browse the repository at this point in the history
  • Loading branch information
Mosibi committed Oct 20, 2024
1 parent 4cffde5 commit 185b5c4
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
Binary file added .github/scripts/.set_version.sh.swp
Binary file not shown.
14 changes: 14 additions & 0 deletions .github/scripts/set_version.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,28 @@ function Info() {
Message "INFO" "${MESSAGE}"
}

function Warning() {
local MESSAGE="${1}"
Message "WARNGIN" "${MESSAGE}"
}

function Error() {
local MESSAGE="${1}"
Message "ERROR" "${MESSAGE}"
exit 101
}

VERSION_FROM_CHANGELOG=$(grep '^## \[[0-9]' CHANGELOG.md | sed -E 's/^##\ \[([0-9].*)\]\ -.*/\1/g' | head -1)
VERSION_IN_YAML=$(awk '/^ {4}version:/ {print $NF}' heatpump.yaml)

if [[ ! -z "${VERSION_FROM_CHANGELOG}" ]] && [[ "${VERSION_FROM_CHANGELOG}" =~ ^[0-9].*$ ]]; then
Info "Version extracted from changelog is ${VERSION_FROM_CHANGELOG}"
Info "Current version in heatpump.yaml is ${VERSION_IN_YAML}"

if [[ "${VERSION_FROM_CHANGELOG}" == "${VERSION_IN_YAML}" ]]; then
Info "Versions are the same, nothing has to be done now"
exit 0
fi

# Check if version already exists
git describe "${VERSION_FROM_CHANGELOG}" --tags 1>/dev/null 2>/dev/null
Expand All @@ -36,4 +48,6 @@ if [[ ! -z "${VERSION_FROM_CHANGELOG}" ]] && [[ "${VERSION_FROM_CHANGELOG}" =~ ^
sed -i -E "s/(^\ {4}version:)(.*$)/\1 ${VERSION_FROM_CHANGELOG}/g" heatpump.yaml || Error "Could not update version in heatpump.yaml"
Info "Version in heatpump.yaml is successful updated to ${VERSION_FROM_CHANGELOG}"
fi
else
Warning "Version extracted from CHANGELOG.md does not seem to be a version tag: ${VERSION_FROM_CHANGELOG}, version will not be updated"
fi
7 changes: 6 additions & 1 deletion .github/workflows/update_version.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
---
name: Update version in heatpump.yaml

on: [push]
on:
pull_request:
branches:
- master
types: [closed]

jobs:
update-version:
if: ${{ github.event.pull_request.merged }}
runs-on: ubuntu-latest
steps:
- name: Checkout code
Expand Down

0 comments on commit 185b5c4

Please sign in to comment.