Skip to content

Bug fix

Bug fix #65

Workflow file for this run

name: Auto-format and Validate Version
on:
pull_request:
jobs:
auto-format:
name: Auto-format Code
runs-on: ubuntu-latest
steps:
# Step 1: Checkout the repository
- name: Checkout Repository
uses: actions/checkout@v3
# Step 2: Set up Python environment
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.x'
# Step 3: Install tools (black and isort)
- name: Install Tools
run: |
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: |
black --line-length=119 .
isort .
validate-version:
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')

Check failure on line 38 in .github/workflows/black.yaml

View workflow run for this annotation

GitHub Actions / Auto-format and Validate Version

Invalid workflow file

The workflow is not valid. .github/workflows/black.yaml (Line: 38, Col: 9): Unexpected symbol: 'startsWith'. Located at position 47 within expression: github.base_ref == 'main' && (github.head_ref startsWith 'patch' || github.head_ref startsWith 'dev')
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
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 "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
name: Commit and Push All Changes
runs-on: ubuntu-latest
if: success() || github.event.pull_request.base.ref == 'main'
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
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
git push --force-with-lease --set-upstream origin patch