Skip to content

Commit

Permalink
FIx black workflow for dev
Browse files Browse the repository at this point in the history
  • Loading branch information
fboundy committed Dec 23, 2024
1 parent 3f78f19 commit 9222e3f
Showing 1 changed file with 51 additions and 35 deletions.
86 changes: 51 additions & 35 deletions .github/workflows/black.yaml
Original file line number Diff line number Diff line change
@@ -1,49 +1,65 @@
name: Auto Release for Main Branch
name: Auto-format Code with Debugging

on:
push:
branches:
- main # Trigger on pushes to main (e.g., after a PR is merged)
pull_request_review:
types:
- submitted # Trigger when a review is submitted
pull_request:

jobs:
publish-release:
name: Publish Release
auto-format:
name: Auto-format and Push Changes
runs-on: ubuntu-latest

steps:
# Step 1: Checkout the repository
- name: Checkout Repository
uses: actions/checkout@v3

# Step 2: Extract Version from `pv_opt.py`
- name: Extract Version
id: extract_version
run: |
# 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 "version=$VERSION" >> $GITHUB_ENV # Save to environment file
# 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
# Step 2: Set up Python environment
- name: Set up Python
uses: actions/setup-python@v4
with:
tag_name: "v${{ env.version }}"
release_name: "Release v${{ env.version }}"
body: |
## Changes
This release was automatically generated.
draft: false
prerelease: false
python-version: '3.x'

# 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
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
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
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

0 comments on commit 9222e3f

Please sign in to comment.