From 47a6a021967a9ce953983aa32588b564a52a888e Mon Sep 17 00:00:00 2001 From: fboundy Date: Wed, 1 Jan 2025 07:11:50 +0000 Subject: [PATCH 01/13] Bug fix --- apps/pv_opt/solis.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/pv_opt/solis.py b/apps/pv_opt/solis.py index 5f00bd5..b1c4a08 100644 --- a/apps/pv_opt/solis.py +++ b/apps/pv_opt/solis.py @@ -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: From 01aaf156ac6debc5323a5bdd488fc5ef5802e93b Mon Sep 17 00:00:00 2001 From: fboundy Date: Wed, 1 Jan 2025 07:21:43 +0000 Subject: [PATCH 02/13] Updated workflows --- .github/workflows/auto_release.yaml | 84 ----------------------- .github/workflows/black.yaml | 101 ++++++++++++++++++++++++++++ 2 files changed, 101 insertions(+), 84 deletions(-) diff --git a/.github/workflows/auto_release.yaml b/.github/workflows/auto_release.yaml index ecb9266..87ef9f7 100644 --- a/.github/workflows/auto_release.yaml +++ b/.github/workflows/auto_release.yaml @@ -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 "actions@github.com" - 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 diff --git a/.github/workflows/black.yaml b/.github/workflows/black.yaml index e892d13..c477a06 100644 --- a/.github/workflows/black.yaml +++ b/.github/workflows/black.yaml @@ -62,3 +62,104 @@ jobs: else echo "No changes detected. Nothing to commit or push." fi + + validate-version: + name: Validate Version + runs-on: ubuntu-latest + needs: auto-format + + 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 "actions@github.com" + 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" + + + commit-changes: + needs: + - auto-format + - validate-version + name: Commit and Push All Changes + runs-on: ubuntu-latest + steps: + - name: Checkout Repository + uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - name: Configure Git User + run: | + git config user.name "github-actions" + git config user.email "github-actions@users.noreply.github.com" + + - name: Pull Latest Changes + run: | + git checkout -b patch || git checkout patch + git pull origin patch --rebase + + - name: Commit All Changes + run: | + git add README.md apps/pv_opt/pv_opt.py + git commit --amend --no-edit || echo "No changes to commit" + + - name: Push Changes + run: | + git push --force-with-lease --set-upstream origin patch + + \ No newline at end of file From c17dc5884e40daa4a5de481b8bac8c9644652e7e Mon Sep 17 00:00:00 2001 From: fboundy Date: Wed, 1 Jan 2025 07:21:43 +0000 Subject: [PATCH 03/13] Updated workflows --- .github/workflows/auto_release.yaml | 84 ----------------------- .github/workflows/black.yaml | 101 ++++++++++++++++++++++++++++ 2 files changed, 101 insertions(+), 84 deletions(-) diff --git a/.github/workflows/auto_release.yaml b/.github/workflows/auto_release.yaml index ecb9266..87ef9f7 100644 --- a/.github/workflows/auto_release.yaml +++ b/.github/workflows/auto_release.yaml @@ -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 "actions@github.com" - 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 diff --git a/.github/workflows/black.yaml b/.github/workflows/black.yaml index e892d13..c477a06 100644 --- a/.github/workflows/black.yaml +++ b/.github/workflows/black.yaml @@ -62,3 +62,104 @@ jobs: else echo "No changes detected. Nothing to commit or push." fi + + validate-version: + name: Validate Version + runs-on: ubuntu-latest + needs: auto-format + + 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 "actions@github.com" + 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" + + + commit-changes: + needs: + - auto-format + - validate-version + name: Commit and Push All Changes + runs-on: ubuntu-latest + steps: + - name: Checkout Repository + uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - name: Configure Git User + run: | + git config user.name "github-actions" + git config user.email "github-actions@users.noreply.github.com" + + - name: Pull Latest Changes + run: | + git checkout -b patch || git checkout patch + git pull origin patch --rebase + + - name: Commit All Changes + run: | + git add README.md apps/pv_opt/pv_opt.py + git commit --amend --no-edit || echo "No changes to commit" + + - name: Push Changes + run: | + git push --force-with-lease --set-upstream origin patch + + \ No newline at end of file From f1fdf5451bbc6983f4e813969f611a4f55ceae94 Mon Sep 17 00:00:00 2001 From: fboundy Date: Wed, 1 Jan 2025 07:30:51 +0000 Subject: [PATCH 04/13] Updated workflow --- .github/workflows/black.yaml | 51 +++++++----------------------------- 1 file changed, 9 insertions(+), 42 deletions(-) diff --git a/.github/workflows/black.yaml b/.github/workflows/black.yaml index c477a06..66f1670 100644 --- a/.github/workflows/black.yaml +++ b/.github/workflows/black.yaml @@ -34,39 +34,11 @@ jobs: echo "Running isort..." isort . - # Step 5: Commit and push changes if any files were modified - - name: Commit and Push 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" - - echo "Checking for changes..." - git status - - if [ -n "$(git status --porcelain)" ]; then - echo "Changes detected. Inspecting changes..." - git diff - - echo "Staging files..." - git add . - - echo "Committing changes..." - git commit -m "Auto-format code with Black and isort" - - echo "Pushing changes to branch..." - git push - echo "Push completed successfully." - else - echo "No changes detected. Nothing to commit or push." - fi - validate-version: name: Validate Version runs-on: ubuntu-latest needs: auto-format + if: github.base_ref == 'main' && startsWith(github.head_ref, 'patch') steps: - name: Checkout Repository @@ -123,13 +95,6 @@ jobs: 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 "actions@github.com" - 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" - commit-changes: needs: @@ -137,6 +102,7 @@ jobs: - validate-version name: Commit and Push All Changes runs-on: ubuntu-latest + steps: - name: Checkout Repository uses: actions/checkout@v3 @@ -145,8 +111,8 @@ jobs: - name: Configure Git User run: | - git config user.name "github-actions" - git config user.email "github-actions@users.noreply.github.com" + git config user.name "github-actions[bot]" + git config user.email "github-actions[bot]@users.noreply.github.com" - name: Pull Latest Changes run: | @@ -155,11 +121,12 @@ jobs: - name: Commit All Changes run: | - git add README.md apps/pv_opt/pv_opt.py - git commit --amend --no-edit || echo "No changes to commit" + git add . + git diff --cached --quiet || git commit -m "Auto-format code and validate version" - name: Push Changes + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | git push --force-with-lease --set-upstream origin patch - - \ No newline at end of file + \ No newline at end of file From 5b68963f49ef6fedc08efc658ab3725cc3b5866e Mon Sep 17 00:00:00 2001 From: fboundy Date: Wed, 1 Jan 2025 07:34:59 +0000 Subject: [PATCH 05/13] Updated workflow --- .github/workflows/black.yaml | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/.github/workflows/black.yaml b/.github/workflows/black.yaml index 66f1670..9c9c092 100644 --- a/.github/workflows/black.yaml +++ b/.github/workflows/black.yaml @@ -5,7 +5,7 @@ on: jobs: auto-format: - name: Auto-format and Push Changes + name: Auto-format with Black and iSort runs-on: ubuntu-latest steps: @@ -114,10 +114,6 @@ jobs: git config user.name "github-actions[bot]" git config user.email "github-actions[bot]@users.noreply.github.com" - - name: Pull Latest Changes - run: | - git checkout -b patch || git checkout patch - git pull origin patch --rebase - name: Commit All Changes run: | From e30a3c502ab03fcac49d3df6def5249bacf14c1c Mon Sep 17 00:00:00 2001 From: fboundy Date: Wed, 1 Jan 2025 07:50:36 +0000 Subject: [PATCH 06/13] Updated workflows --- .github/workflows/black.yaml | 50 ++++++++++++++++++++++-------------- 1 file changed, 31 insertions(+), 19 deletions(-) diff --git a/.github/workflows/black.yaml b/.github/workflows/black.yaml index 9c9c092..0e5e73b 100644 --- a/.github/workflows/black.yaml +++ b/.github/workflows/black.yaml @@ -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 with Black and iSort + name: Auto-format Code runs-on: ubuntu-latest steps: @@ -27,7 +27,7 @@ jobs: 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 . @@ -38,7 +38,7 @@ jobs: name: Validate Version runs-on: ubuntu-latest needs: auto-format - if: github.base_ref == 'main' && startsWith(github.head_ref, 'patch') + if: github.base_ref == 'main' && (startsWith(github.head_ref, 'patch') || startsWith(github.head_ref, 'dev')) steps: - name: Checkout Repository @@ -78,30 +78,34 @@ jobs: patch_version=$patch_version main_version=$main_version - # Extract PATCH numbers + 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}') - 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 + + if startsWith "$GITHUB_HEAD_REF" "patch"; then + new_patch_version="$main_major.$main_minor.$((main_patch + 1))" + elif startsWith "$GITHUB_HEAD_REF" "dev"; then + new_patch_version="$main_major.$((main_minor + 1)).0" + else + 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 "VERSION_CHANGED=true" >> $GITHUB_ENV + - name: Update README.md version run: | + patch_version=$(grep -m 1 -oP '(?<=^VERSION = ")[^"]+' apps/pv_opt/pv_opt.py) sed -i "1s/v[0-9]*\.[0-9]*\.[0-9]*/v$patch_version/" README.md - commit-changes: needs: - - auto-format - - validate-version + - auto-format # Remove dependency on validate-version name: Commit and Push All Changes runs-on: ubuntu-latest + if: success() || github.event.pull_request.base.ref == 'main' steps: - name: Checkout Repository @@ -114,15 +118,23 @@ jobs: git config user.name "github-actions[bot]" git config user.email "github-actions[bot]@users.noreply.github.com" + - name: Checkout or Create Patch Branch + run: | + git checkout -b patch || git checkout patch - name: Commit All Changes + env: + VERSION_CHANGED: ${{ env.VERSION_CHANGED }} run: | git add . - git diff --cached --quiet || git commit -m "Auto-format code and validate version" + if [ "$VERSION_CHANGED" = "true" ]; then + git commit -m "Auto-format code and validate version [Version Updated]" + else + git commit -m "Auto-format code and validate version" + fi - name: Push Changes env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | git push --force-with-lease --set-upstream origin patch - \ No newline at end of file From 563f88b6056c05decec8dd55f7f8fe90eaf3757e Mon Sep 17 00:00:00 2001 From: fboundy Date: Wed, 1 Jan 2025 08:00:55 +0000 Subject: [PATCH 07/13] Updated workflow --- .github/workflows/black.yaml | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/.github/workflows/black.yaml b/.github/workflows/black.yaml index 0e5e73b..6933d6e 100644 --- a/.github/workflows/black.yaml +++ b/.github/workflows/black.yaml @@ -22,23 +22,20 @@ 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: Format Code with Black and isort run: | - echo "Running black..." black --line-length=119 . - echo "Running isort..." isort . validate-version: name: Validate Version runs-on: ubuntu-latest needs: auto-format - if: github.base_ref == 'main' && (startsWith(github.head_ref, 'patch') || startsWith(github.head_ref, 'dev')) + if: github.base_ref == 'main' && (github.head_ref startsWith 'patch' || github.head_ref startsWith 'dev') steps: - name: Checkout Repository @@ -82,9 +79,9 @@ jobs: main_minor=$(echo "$main_version" | awk -F '.' '{print $2}') main_patch=$(echo "$main_version" | awk -F '.' '{print $3}') - if startsWith "$GITHUB_HEAD_REF" "patch"; then + if [[ "$GITHUB_HEAD_REF" == patch* ]]; then new_patch_version="$main_major.$main_minor.$((main_patch + 1))" - elif startsWith "$GITHUB_HEAD_REF" "dev"; then + elif [[ "$GITHUB_HEAD_REF" == dev* ]]; then new_patch_version="$main_major.$((main_minor + 1)).0" else echo "Error: Unsupported source branch type." >&2 @@ -102,7 +99,7 @@ jobs: commit-changes: needs: - - auto-format # Remove dependency on validate-version + - auto-format name: Commit and Push All Changes runs-on: ubuntu-latest if: success() || github.event.pull_request.base.ref == 'main' @@ -124,11 +121,11 @@ jobs: - name: Commit All Changes env: - VERSION_CHANGED: ${{ env.VERSION_CHANGED }} + VERSION_CHANGED: ${{ env.VERSION_CHANGED || 'false' }} run: | git add . if [ "$VERSION_CHANGED" = "true" ]; then - git commit -m "Auto-format code and validate version [Version Updated]" + git commit -m "Auto-format code and update version to [Version Updated]" else git commit -m "Auto-format code and validate version" fi From 505ce79e8e58c31f167183e2b11b906cb0999a40 Mon Sep 17 00:00:00 2001 From: fboundy Date: Wed, 1 Jan 2025 08:04:11 +0000 Subject: [PATCH 08/13] Fix workflow --- .github/workflows/black.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/black.yaml b/.github/workflows/black.yaml index 6933d6e..f1b78fb 100644 --- a/.github/workflows/black.yaml +++ b/.github/workflows/black.yaml @@ -35,7 +35,7 @@ jobs: name: Validate Version runs-on: ubuntu-latest needs: auto-format - if: github.base_ref == 'main' && (github.head_ref startsWith 'patch' || github.head_ref startsWith 'dev') + if: github.base_ref == 'main' && (startsWith(github.head_ref, 'patch') || startsWith(github.head_ref, 'dev')) steps: - name: Checkout Repository From e3e5156280dd0b933e57e8d8f37c356422dbc700 Mon Sep 17 00:00:00 2001 From: fboundy Date: Wed, 1 Jan 2025 08:09:36 +0000 Subject: [PATCH 09/13] Update workflow --- .github/workflows/black.yaml | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/.github/workflows/black.yaml b/.github/workflows/black.yaml index f1b78fb..4f52dd8 100644 --- a/.github/workflows/black.yaml +++ b/.github/workflows/black.yaml @@ -35,13 +35,19 @@ jobs: name: Validate Version runs-on: ubuntu-latest needs: auto-format - if: github.base_ref == 'main' && (startsWith(github.head_ref, 'patch') || startsWith(github.head_ref, 'dev')) + if: github.base_ref == 'main' steps: - name: Checkout Repository uses: actions/checkout@v3 - with: - fetch-depth: 0 + + - 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 + - name: Fetch main branch into a temporary branch run: | @@ -100,9 +106,10 @@ jobs: commit-changes: needs: - auto-format + - validate-version name: Commit and Push All Changes runs-on: ubuntu-latest - if: success() || github.event.pull_request.base.ref == 'main' + steps: - name: Checkout Repository From 4492340eba380fbfea1153cb6857831793d1caf9 Mon Sep 17 00:00:00 2001 From: fboundy Date: Wed, 1 Jan 2025 08:16:52 +0000 Subject: [PATCH 10/13] Updated workflow --- .github/workflows/black.yaml | 59 ++++++++++++++---------------------- 1 file changed, 22 insertions(+), 37 deletions(-) diff --git a/.github/workflows/black.yaml b/.github/workflows/black.yaml index 4f52dd8..0d90cf8 100644 --- a/.github/workflows/black.yaml +++ b/.github/workflows/black.yaml @@ -31,6 +31,21 @@ jobs: black --line-length=119 . isort . + # Step 5: Commit Formatting Changes + - name: Commit Formatting Changes + 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 . + 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 @@ -48,7 +63,6 @@ jobs: exit 0 fi - - name: Fetch main branch into a temporary branch run: | git fetch origin main @@ -103,42 +117,13 @@ jobs: patch_version=$(grep -m 1 -oP '(?<=^VERSION = ")[^"]+' apps/pv_opt/pv_opt.py) sed -i "1s/v[0-9]*\.[0-9]*\.[0-9]*/v$patch_version/" README.md - commit-changes: - needs: - - auto-format - - validate-version - name: Commit and Push All Changes - runs-on: ubuntu-latest - - - steps: - - name: Checkout Repository - uses: actions/checkout@v3 - with: - fetch-depth: 0 - - - name: Configure Git User - run: | - git config user.name "github-actions[bot]" - git config user.email "github-actions[bot]@users.noreply.github.com" - - - name: Checkout or Create Patch Branch - run: | - git checkout -b patch || git checkout patch - - - name: Commit All Changes - env: - VERSION_CHANGED: ${{ env.VERSION_CHANGED || 'false' }} - run: | - git add . - if [ "$VERSION_CHANGED" = "true" ]; then - git commit -m "Auto-format code and update version to [Version Updated]" - else - git commit -m "Auto-format code and validate version" - fi - - - name: Push Changes + - name: Commit Version Changes + if: env.VERSION_CHANGED == 'true' env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | - git push --force-with-lease --set-upstream origin patch + 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 $patch_version" + git push origin HEAD From 0bc4adb36b23301546eb3a036790f70af49ecece Mon Sep 17 00:00:00 2001 From: fboundy Date: Wed, 1 Jan 2025 08:27:10 +0000 Subject: [PATCH 11/13] Update workflow --- .github/workflows/black.yaml | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/.github/workflows/black.yaml b/.github/workflows/black.yaml index 0d90cf8..b5e5dec 100644 --- a/.github/workflows/black.yaml +++ b/.github/workflows/black.yaml @@ -110,12 +110,13 @@ jobs: 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: | - patch_version=$(grep -m 1 -oP '(?<=^VERSION = ")[^"]+' apps/pv_opt/pv_opt.py) - sed -i "1s/v[0-9]*\.[0-9]*\.[0-9]*/v$patch_version/" README.md + 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' @@ -125,5 +126,6 @@ jobs: 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 $patch_version" + git commit -m "Update version to ${{ env.new_patch_version }}" git push origin HEAD + \ No newline at end of file From 7fe8f80710221ec6b3277e4e735f1cd6466cb16a Mon Sep 17 00:00:00 2001 From: fboundy Date: Wed, 1 Jan 2025 08:34:25 +0000 Subject: [PATCH 12/13] Workflow --- .github/workflows/black.yaml | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/.github/workflows/black.yaml b/.github/workflows/black.yaml index b5e5dec..0ce1536 100644 --- a/.github/workflows/black.yaml +++ b/.github/workflows/black.yaml @@ -55,6 +55,8 @@ jobs: steps: - name: Checkout Repository uses: actions/checkout@v3 + with: + fetch-depth: 0 - name: Skip Validation for Non-patch/dev Branches run: | @@ -68,26 +70,30 @@ jobs: git fetch origin main git checkout -b temp-main origin/main - - name: Get VERSION from patch branch - id: get_patch_version + - 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 patch branch." >&2 + echo "Error: VERSION not found in apps/pv_opt/pv_opt.py on main branch." >&2 exit 1 fi - echo "patch_version=$VERSION" >> $GITHUB_ENV + echo "main_version=$VERSION" >> $GITHUB_ENV - - name: Get VERSION from main branch - id: get_main_version + - name: Switch Back to Source Branch + run: | + git fetch origin $GITHUB_HEAD_REF + git checkout $GITHUB_HEAD_REF + + - name: Get VERSION from Current Branch + id: get_patch_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 + echo "Error: VERSION not found in apps/pv_opt/pv_opt.py on source branch." >&2 exit 1 fi - echo "main_version=$VERSION" >> $GITHUB_ENV + echo "patch_version=$VERSION" >> $GITHUB_ENV - name: Validate or Fix Version Increment id: validate_or_fix_version @@ -116,7 +122,7 @@ jobs: - 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 + 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' @@ -127,5 +133,4 @@ jobs: 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 HEAD - \ No newline at end of file + git push origin $GITHUB_HEAD_REF \ No newline at end of file From 0f577ad331bca7862175c73ac489e9964dfc1128 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Wed, 1 Jan 2025 08:35:03 +0000 Subject: [PATCH 13/13] Update version to 4.0.1 --- README.md | 2 +- apps/pv_opt/pv_opt.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index afffe84..eaf6768 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/apps/pv_opt/pv_opt.py b/apps/pv_opt/pv_opt.py index 557ba2c..72b1faf 100644 --- a/apps/pv_opt/pv_opt.py +++ b/apps/pv_opt/pv_opt.py @@ -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",