Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add GitHub actions #55

Merged
merged 11 commits into from
Oct 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .github/scripts/.set_version.sh.swp
Binary file not shown.
53 changes: 53 additions & 0 deletions .github/scripts/set_version.sh
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
33 changes: 33 additions & 0 deletions .github/workflows/update_version.yml
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 }}
3 changes: 3 additions & 0 deletions heatpump.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ esphome:
name: "${devicename}"
comment: "${description}"
friendly_name: "${description}"
project:
name: "${devicename}.${description}"
version: 4.1.2

esp32:
board: esp32dev
Expand Down
Loading