Skip to content

Commit

Permalink
Merge pull request #348 from fboundy/patch
Browse files Browse the repository at this point in the history
Bug fix
  • Loading branch information
fboundy authored Jan 1, 2025
2 parents c6661b4 + 0f577ad commit fe29d07
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 111 deletions.
84 changes: 0 additions & 84 deletions .github/workflows/auto_release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,93 +6,9 @@ on:
- main # Trigger on pushes to main (e.g., after a PR is merged)

jobs:
validate-version:
name: Validate Version
runs-on: ubuntu-latest

steps:
- name: Checkout Repository
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Fetch main branch into a temporary branch
run: |
git fetch origin main
git checkout -b temp-main origin/main
- name: Get VERSION from patch branch
id: get_patch_version
run: |
VERSION=$(grep -m 1 -oP '(?<=^VERSION = ")[^"]+' apps/pv_opt/pv_opt.py)
if [ -z "$VERSION" ]; then
echo "Error: VERSION not found in apps/pv_opt/pv_opt.py on patch branch." >&2
exit 1
fi
echo "patch_version=$VERSION" >> $GITHUB_ENV
- name: Get VERSION from main branch
id: get_main_version
run: |
git checkout temp-main
VERSION=$(grep -m 1 -oP '(?<=^VERSION = ")[^"]+' apps/pv_opt/pv_opt.py)
if [ -z "$VERSION" ]; then
echo "Error: VERSION not found in apps/pv_opt/pv_opt.py on main branch." >&2
exit 1
fi
echo "main_version=$VERSION" >> $GITHUB_ENV
- name: Validate or Fix Version Increment
id: validate_or_fix_version
run: |
patch_version=$patch_version
main_version=$main_version
# Extract PATCH numbers
main_patch=$(echo "$main_version" | awk -F '.' '{print $3}')
patch_patch=$(echo "$patch_version" | awk -F '.' '{print $3}')
# Check if the patch version is incremented correctly
if [ "$patch_patch" -ne $((main_patch + 1)) ]; then
echo "Warning: PATCH version is not incremented correctly. Fixing..."
new_patch_version=$(echo "$main_version" | awk -F '.' '{print $1"."$2"."($3+1)}')
sed -i "s/^VERSION = \".*\"/VERSION = \"$new_patch_version\"/" apps/pv_opt/pv_opt.py
echo "Corrected version to $new_patch_version."
echo "patch_version=$new_patch_version" >> $GITHUB_ENV
fi
- name: Update README.md version
run: |
sed -i "1s/v[0-9]*\.[0-9]*\.[0-9]*/v$patch_version/" README.md
- name: Commit Changes if Needed
run: |
git config user.name "GitHub Actions"
git config user.email "[email protected]"
git add apps/pv_opt/pv_opt.py README.md
git diff --cached --quiet || git commit -m "Fix version and update README.md to $patch_version"
- name: Push changes back to patch branch
run: |
git push origin HEAD:patch
- name: Create or Update Pull Request for Main
uses: peter-evans/create-pull-request@v5
with:
token: ${{ secrets.GITHUB_TOKEN }}
branch: patch
base: main
title: "Automated Version Fix and README Update"
body: |
This pull request was automatically created or updated to fix the version number and update the README.md file.
Please review and merge to apply these changes to the main branch.
labels: automated
delete-branch: false

publish-release:
name: Publish Release
runs-on: ubuntu-latest
needs: validate-version

steps:
# Step 1: Checkout the repository
Expand Down
120 changes: 96 additions & 24 deletions .github/workflows/black.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
name: Auto-format Code with Debugging
name: Auto-format and Validate Version

on:
pull_request:

jobs:
auto-format:
name: Auto-format and Push Changes
name: Auto-format Code
runs-on: ubuntu-latest

steps:
Expand All @@ -22,43 +22,115 @@ jobs:
# Step 3: Install tools (black and isort)
- name: Install Tools
run: |
echo "Installing tools..."
python -m pip install --upgrade pip
pip install black isort
# Step 4: Run black and isort to format the code
- name: Run Black and isort
- name: Format Code with Black and isort
run: |
echo "Running black..."
black --line-length=119 .
echo "Running isort..."
isort .
# Step 5: Commit and push changes if any files were modified
- name: Commit and Push Changes
# Step 5: Commit Formatting Changes
- name: Commit Formatting Changes
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
echo "Configuring git user..."
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add .
if git diff --cached --quiet; then
echo "No formatting changes to commit."
exit 0
fi
git commit -m "Auto-format code with Black and isort"
git push origin HEAD
validate-version:
name: Validate Version
runs-on: ubuntu-latest
needs: auto-format
if: github.base_ref == 'main'

steps:
- name: Checkout Repository
uses: actions/checkout@v3
with:
fetch-depth: 0

echo "Checking for changes..."
git status
- name: Skip Validation for Non-patch/dev Branches
run: |
if [[ "$GITHUB_HEAD_REF" != patch* && "$GITHUB_HEAD_REF" != dev* ]]; then
echo "Skipping validation for non-patch/dev branch."
exit 0
fi
if [ -n "$(git status --porcelain)" ]; then
echo "Changes detected. Inspecting changes..."
git diff
- name: Fetch main branch into a temporary branch
run: |
git fetch origin main
git checkout -b temp-main origin/main
echo "Staging files..."
git add .
- name: Get VERSION from Main Branch
id: get_main_version
run: |
VERSION=$(grep -m 1 -oP '(?<=^VERSION = ")[^"]+' apps/pv_opt/pv_opt.py)
if [ -z "$VERSION" ]; then
echo "Error: VERSION not found in apps/pv_opt/pv_opt.py on main branch." >&2
exit 1
fi
echo "main_version=$VERSION" >> $GITHUB_ENV
echo "Committing changes..."
git commit -m "Auto-format code with Black and isort"
- name: Switch Back to Source Branch
run: |
git fetch origin $GITHUB_HEAD_REF
git checkout $GITHUB_HEAD_REF
echo "Pushing changes to branch..."
git push
echo "Push completed successfully."
- name: Get VERSION from Current Branch
id: get_patch_version
run: |
VERSION=$(grep -m 1 -oP '(?<=^VERSION = ")[^"]+' apps/pv_opt/pv_opt.py)
if [ -z "$VERSION" ]; then
echo "Error: VERSION not found in apps/pv_opt/pv_opt.py on source branch." >&2
exit 1
fi
echo "patch_version=$VERSION" >> $GITHUB_ENV
- name: Validate or Fix Version Increment
id: validate_or_fix_version
run: |
patch_version=$patch_version
main_version=$main_version
main_major=$(echo "$main_version" | awk -F '.' '{print $1}')
main_minor=$(echo "$main_version" | awk -F '.' '{print $2}')
main_patch=$(echo "$main_version" | awk -F '.' '{print $3}')
if [[ "$GITHUB_HEAD_REF" == patch* ]]; then
new_patch_version="$main_major.$main_minor.$((main_patch + 1))"
elif [[ "$GITHUB_HEAD_REF" == dev* ]]; then
new_patch_version="$main_major.$((main_minor + 1)).0"
else
echo "No changes detected. Nothing to commit or push."
echo "Error: Unsupported source branch type." >&2
exit 1
fi
sed -i "s/^VERSION = \".*\"/VERSION = \"$new_patch_version\"/" apps/pv_opt/pv_opt.py
echo "Corrected version to $new_patch_version."
echo "new_patch_version=$new_patch_version" >> $GITHUB_ENV
echo "VERSION_CHANGED=true" >> $GITHUB_ENV
- name: Update README.md version
run: |
new_patch_version=${{ env.new_patch_version }}
sed -i "1s/v[0-9]*\.[0-9]*\.[0-9]*/v$new_patch_version/" README.md
- name: Commit Version Changes
if: env.VERSION_CHANGED == 'true'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add apps/pv_opt/pv_opt.py README.md
git commit -m "Update version to ${{ env.new_patch_version }}"
git push origin $GITHUB_HEAD_REF
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# PV Opt: Home Assistant Solar/Battery Optimiser v4.0.0
# PV Opt: Home Assistant Solar/Battery Optimiser v4.0.1


Solar / Battery Charging Optimisation for Home Assistant. This appDaemon application attempts to optimise charging and discharging of a home solar/battery system to minimise cost electricity cost on a daily basis using freely available solar forecast data from SolCast. This is particularly beneficial for Octopus Agile but is also benefeficial for other time-of-use tariffs such as Octopus Flux or simple Economy 7.
Expand Down
2 changes: 1 addition & 1 deletion apps/pv_opt/pv_opt.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import pvpy as pv
from numpy import nan

VERSION = "4.0.0"
VERSION = "4.0.1"
UNITS = {
"current": "A",
"power": "W",
Expand Down
2 changes: 1 addition & 1 deletion apps/pv_opt/solis.py
Original file line number Diff line number Diff line change
Expand Up @@ -667,7 +667,7 @@ def _set_target_soc(self, direction, target_soc: int = 100, forced=True) -> bool
tolerance = 0

if entity_id is not None:
changed, written = self.write_to_hass()
changed, written = self.write_to_hass(entity_id=entity_id, value=target_soc, tolerance=tolerance)

if changed:
if written:
Expand Down

0 comments on commit fe29d07

Please sign in to comment.