chore: simplify the workflow 'push' #24
Workflow file for this run
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 Formatter | |
on: | |
push: | |
branches: | |
- '*' | |
permissions: | |
contents: write | |
jobs: | |
black: | |
name: Format code with Black | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
python-version: ["3.9", "3.10", "3.11"] | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Setup Python ${{ matrix.python-version }} | |
uses: actions/setup-python@v4 | |
with: | |
python-version: ${{ matrix.python-version }} | |
- name: Install dependencies | |
run: | | |
python -m pip install --upgrade pip | |
pip install black | |
- name: Run Black | |
run: black . | |
- name: Show Black changes | |
id: check_diff | |
run: | | |
git config --global user.name 'github-actions[bot]' | |
git config --global user.email 'github-actions[bot]@users.noreply.github.com' | |
CHANGED_FILES=$(git diff --name-only) | |
echo "changed files:" | |
if [ -n "$CHANGED_FILES" ]; then | |
echo "$CHANGED_FILES" | |
echo "::set-output name=has_changes::true" | |
else | |
echo "No files formatted by Black." | |
echo "::set-output name=has_changes::false" | |
fi | |
- name: Commit and Push changes | |
if: steps.check_diff.outputs.has_changes == 'true' | |
run: | | |
git add . | |
git commit -m "auto-format code using Black" | |
git push | |
env: | |
GITHUB_TOKEN: ${{ secrets.GH_ACTIONS_BLACK_TOKEN }} |