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

Patch #358

Merged
merged 15 commits into from
Jan 7, 2025
59 changes: 9 additions & 50 deletions .github/workflows/auto_release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,73 +14,32 @@ jobs:
# Step 1: Checkout the repository
- name: Checkout Repository
uses: actions/checkout@v3
with:
fetch-depth: 0 # Fetch all history for all branches and tags

# Step 2: Debug Tag Visibility
- name: List Tags
run: |
echo "Listing all available tags:"
git tag

# Step 3: Extract Version from `pv_opt.py`
# Step 2: Extract Version from `pv_opt.py`
- name: Extract Version
id: extract_version
run: |
echo "Extracting version from apps/pv_opt/pv_opt.py"
# Extract the VERSION variable from pv_opt.py
VERSION=$(grep -oP '(?<=^VERSION = ")[^"]+' apps/pv_opt/pv_opt.py)
if [ -z "$VERSION" ]; then
echo "Error: VERSION not found in apps/pv_opt/pv_opt.py"
exit 1
fi
echo "Extracted VERSION=$VERSION"
echo "VERSION=$VERSION"
echo "version=$VERSION" >> $GITHUB_ENV # Save to environment file

# Step 4: Generate Release Notes
- name: Generate Release Notes
id: generate_notes
run: |
echo "Generating release notes..."
# Get the latest tag before this release
LAST_TAG=$(git describe --tags --abbrev=0 --match "v*" 2>/dev/null)

# If no tags exist, use the initial commit hash
if [ -z "$LAST_TAG" ]; then
echo "No previous tags found. Using initial commit as starting point."
LAST_TAG=$(git rev-list --max-parents=0 HEAD)
else
echo "Found latest tag: $LAST_TAG"
fi

# Gather commit messages since the last tag
echo "Collecting commits since $LAST_TAG..."
COMMITS=$(git log ${LAST_TAG}..HEAD --pretty=format:"- %s (%h)")

# Format the release notes
RELEASE_NOTES="## Changes\n"
if [ -z "$COMMITS" ]; then
echo "No significant changes found."
RELEASE_NOTES+="No significant changes."
else
echo "Found commits:"
echo -e "${COMMITS}"
RELEASE_NOTES+=$(echo -e "${COMMITS}")
fi

# Output the release notes
echo -e "Release notes generated:\n${RELEASE_NOTES}"
echo "${RELEASE_NOTES}" > release_notes.txt
echo "RELEASE_NOTES=$(<release_notes.txt)" >> $GITHUB_ENV


# Step 5: Create GitHub Release
# Step 3: Create GitHub Release
- name: Create GitHub Release
if: |
github.event_name == 'push' ||
(github.event_name == 'pull_request_review' && github.event.review.state == 'approved')
uses: actions/create-release@v1
with:
tag_name: "v${{ env.version }}"
release_name: "Release v${{ env.version }}"
body: ${{ env.release_notes }}
body: |
## Changes
This release was automatically generated.
draft: false
prerelease: false
env:
Expand Down
49 changes: 27 additions & 22 deletions .github/workflows/black.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -65,26 +65,29 @@ jobs:
exit 0
fi

- name: Fetch main branch into a temporary branch
- name: Get Latest Tag
id: get_latest_tag
run: |
git fetch origin main
git checkout -b temp-main origin/main
LATEST_TAG=$(git tag --list | sort -V | tail -n 1)
if [ -z "$LATEST_TAG" ]; then
echo "Error: No tags found in the repository." >&2
exit 1
fi
echo "LATEST_TAG=$LATEST_TAG" >> $GITHUB_ENV
echo "Latest Tag: '$LATEST_TAG'"

- name: Get VERSION from Main Branch
id: get_main_version
- name: Get VERSION from Latest Tag
id: get_tag_version
run: |
VERSION=$(grep -m 1 -oP '(?<=^VERSION = ")[^"]+' apps/pv_opt/pv_opt.py)
VERSION=$(echo "$LATEST_TAG" | sed -E 's/^v([0-9]+\\.[0-9]+\\.[0-9]+)$/\\1/')
echo "Extracted VERSION: '$VERSION'"
if [ -z "$VERSION" ]; then
echo "Error: VERSION not found in apps/pv_opt/pv_opt.py on main branch." >&2
echo "Error: VERSION could not be extracted from the latest tag." >&2
exit 1
fi
echo "main_version=$VERSION" >> $GITHUB_ENV

- name: Switch Back to Source Branch
run: |
git fetch origin $GITHUB_HEAD_REF
git checkout $GITHUB_HEAD_REF

echo "tag_version=$VERSION" >> $GITHUB_ENV


- name: Get VERSION from Current Branch
id: get_patch_version
run: |
Expand All @@ -99,20 +102,20 @@ jobs:
id: validate_or_fix_version
run: |
patch_version=$patch_version
main_version=$main_version
tag_version=$tag_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}')
tag_major=$(echo "$tag_version" | awk -F '.' '{print $1}')
tag_minor=$(echo "$tag_version" | awk -F '.' '{print $2}')
tag_patch=$(echo "$tag_version" | awk -F '.' '{print $3}')

if [[ "$GITHUB_HEAD_REF" == patch* ]]; then
new_patch_version="$main_major.$main_minor.$((main_patch + 1))"
new_patch_version="$tag_major.$tag_minor.$((tag_patch + 1))"
elif [[ "$GITHUB_HEAD_REF" == dev* ]]; then
new_patch_version="$main_major.$((main_minor + 1)).0"
new_patch_version="$tag_major.$((tag_minor + 1)).0"
else
echo "Error: Unsupported source branch type." >&2
exit 1
fi
exit 1
fi

sed -i "s/^VERSION = \".*\"/VERSION = \"$new_patch_version\"/" apps/pv_opt/pv_opt.py
echo "Corrected version to $new_patch_version."
Expand All @@ -131,10 +134,12 @@ jobs:
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git checkout -B $GITHUB_HEAD_REF # Create or switch to the correct branch
git add apps/pv_opt/pv_opt.py README.md
if git diff --cached --quiet; then
echo "No version changes to commit."
exit 0
fi
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.6
# PV Opt: Home Assistant Solar/Battery Optimiser vv4.0.6


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.6"
VERSION = "v4.0.6"
UNITS = {
"current": "A",
"power": "W",
Expand Down
4 changes: 1 addition & 3 deletions apps/pv_opt/solis.py
Original file line number Diff line number Diff line change
Expand Up @@ -799,9 +799,7 @@ def _write_modbus_register(self, register, value, cfg=None, tolerance=0, multipl
self._host.call_service("modbus/write_register", **data)
sleep(0.1)
new_value = int(float(self.get_config(cfg))) / multiplier
# self.log(f">>> current_value: {current_value/multiplier}")
# self.log(f">>> value: {value}")
# self.log(f">>> new_value: {new_value}")

written = new_value == value
return changed, written

Expand Down