-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add GitHub action to set the version in heatpump.yaml when a pull request is merged to master --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
- Loading branch information
1 parent
ca66ad2
commit da1b59d
Showing
4 changed files
with
89 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
#!/usr/bin/env bash | ||
|
||
# This script extracts the new version from the | ||
# file CHANGELOG.md and uses that version to update | ||
# .esphome.project.version in heatpump.yaml | ||
|
||
|
||
function Message() { | ||
local LEVEL="${1:=INFO}" | ||
local MESSAGE="${2}" | ||
echo "$(basename $0) [${LEVEL}]: ${MESSAGE}" | ||
} | ||
|
||
function Info() { | ||
local MESSAGE="${1}" | ||
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 | ||
|
||
if [[ $? -eq 0 ]]; then | ||
Error "Version (tag) ${VERSION_FROM_CHANGELOG} already exists" | ||
else | ||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
--- | ||
name: Update version in heatpump.yaml | ||
|
||
on: | ||
pull_request: | ||
branches: | ||
- master | ||
types: [closed] | ||
|
||
jobs: | ||
update-version: | ||
if: ${{ github.event.pull_request.merged }} | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
- name: Update version | ||
run: | | ||
cat heatpump.yaml |grep -A7 ^esphome | ||
bash .github/scripts/set_version.sh | ||
cat heatpump.yaml |grep -A7 ^esphome | ||
- name: Commit files | ||
run: | | ||
git config --local user.email "github-actions[bot]@users.noreply.github.com" | ||
git config --local user.name "github-actions[bot]" | ||
git commit -a -m "Updated version in heatpump.yaml" | ||
- name: Push changes | ||
uses: ad-m/github-push-action@master | ||
with: | ||
github_token: ${{ secrets.GITHUB_TOKEN }} | ||
branch: ${{ github.ref }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters