Skip to content

Commit

Permalink
Merge pull request #359 from fboundy/patch
Browse files Browse the repository at this point in the history
Patch
  • Loading branch information
fboundy authored Jan 7, 2025
2 parents 7376a8e + b4aec53 commit 309e7cc
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 20 deletions.
59 changes: 50 additions & 9 deletions .github/workflows/auto_release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,32 +14,73 @@ 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 2: Extract Version from `pv_opt.py`
# Step 3: 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 "VERSION=$VERSION"
echo "Extracted VERSION=$VERSION"
echo "version=$VERSION" >> $GITHUB_ENV # Save to environment file
# Step 3: Create GitHub Release
# 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 "${COMMITS}"
RELEASE_NOTES+="${COMMITS}"
fi
# Output the release notes
echo "Release notes generated:"\n"${RELEASE_NOTES}"
echo "release_notes<<EOF" >> $GITHUB_ENV
echo "${RELEASE_NOTES}" >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
# Step 5: 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: |
## Changes
This release was automatically generated.
body: ${{ env.release_notes }}
draft: false
prerelease: false
env:
Expand Down
20 changes: 10 additions & 10 deletions .github/workflows/black.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
- name: Format Code with Black and isort
run: |
black --line-length=119 .
isort .
isort --profile="black" .
# Step 5: Commit Formatting Changes
- name: Commit Formatting Changes
Expand Down Expand Up @@ -87,7 +87,8 @@ jobs:
fi
echo "tag_version=$VERSION" >> $GITHUB_ENV



- name: Get VERSION from Current Branch
id: get_patch_version
run: |
Expand All @@ -114,18 +115,18 @@ jobs:
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."
echo "new_patch_version=$new_patch_version" >> $GITHUB_ENV
sed -i "s/^VERSION = \".*\"/VERSION = \"v$new_patch_version\"/" apps/pv_opt/pv_opt.py
echo "Corrected version to v$new_patch_version."
echo "new_patch_version=v$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
sed -i "1s/v[0-9]*\.[0-9]*\.[0-9]*/$new_patch_version/" README.md
- name: Commit Version Changes
if: env.VERSION_CHANGED == 'true'
Expand All @@ -134,12 +135,11 @@ 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 checkout -B $GITHUB_HEAD_REF
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 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 = "v4.0.6"
VERSION = "vv4.0.6"
UNITS = {
"current": "A",
"power": "W",
Expand Down

0 comments on commit 309e7cc

Please sign in to comment.