Test with tokens #6
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Black | |
on: | |
push: | |
branches: | |
- main | |
- master | |
- 'feature/*' | |
pull_request: | |
branches: | |
- main | |
- master | |
- 'feature/*' | |
jobs: | |
black: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Cache Black | |
uses: actions/cache@v3 | |
with: | |
path: ~/.cache/pypoetry | |
key: ${{ runner.os }}-black-${{ hashFiles('**/pyproject.toml') }} | |
restore-keys: | | |
${{ runner.os }}-black- | |
- name: Install Black | |
run: | | |
python -m pip install --upgrade pip | |
pip install black | |
- name: Format Code with Black | |
run: | | |
black . # Format all Python files in the repo | |
- name: Commit Changes | |
run: | | |
if [[ `git status --porcelain` ]]; then | |
git checkout -b auto-format-black-${{ github.run_id }} | |
git config --global user.name "github-actions[bot]" | |
git config --global user.email "github-actions[bot]@users.noreply.github.com" | |
git add . | |
git commit -m "chore: auto-format code with Black" | |
git push --set-upstream https://x-access-token:${{ secrets.PAT_TOKEN }}@github.com/${{ github.repository }}.git auto-format-black-${{ github.run_id }} | |
fi | |
- name: Create Pull Request | |
uses: peter-evans/create-pull-request@v3 | |
with: | |
token: ${{ secrets.PAT_TOKEN }} | |
title: "chore: auto-format code with Black" | |
body: "This PR auto-formats the codebase using Black." | |
branch: auto-format-black-${{ github.run_id }} # Corrected from 'head' to 'branch' | |
base: ${{ github.event.pull_request.base.ref || github.ref_name }} |