Added disclaimer / TODO #25
This file contains hidden or 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: Format | |
| permissions: | |
| contents: read | |
| pull-requests: write | |
| on: | |
| push: | |
| branches: | |
| - main | |
| workflow_dispatch: | |
| jobs: | |
| format: | |
| runs-on: ubuntu-24.04 | |
| steps: | |
| - name: Checks-out repository | |
| uses: actions/checkout@v4 | |
| - name: Set up Python 3.12 | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: "3.12" | |
| - name: Install black | |
| run: | | |
| python -m pip install --upgrade pip | |
| python -m pip install black | |
| - name: Reformat with black | |
| run: | | |
| shopt -s globstar | |
| black . > black_output.txt 2>&1 | |
| - name: Check if there are changes | |
| run: | | |
| git diff --exit-code || touch git_diff_exists | |
| if [ -f git_diff_exists ]; then echo "Changes need to be commited"; else echo "No changes to commit"; fi | |
| - name: Create commit message | |
| if: hashFiles('git_diff_exists') != '' | |
| run: | | |
| echo "Reformatted python code using Black formatter" >> commit_message.txt | |
| echo "" >> commit_message.txt | |
| echo "Output from black:" >> commit_message.txt | |
| echo "" >> commit_message.txt | |
| echo '```' >> commit_message.txt | |
| cat black_output.txt >> commit_message.txt | |
| echo '```' >> commit_message.txt | |
| - name: Commit changes | |
| if: hashFiles('git_diff_exists') != '' | |
| run: | | |
| git config user.name 'GitHub' | |
| git config user.email '<noreply@github.com>' | |
| shopt -s globstar | |
| git add src/cfengine_cli/*.py src/cfengine_cli/**/*.py tests/*.py tests/**/*.py | |
| git commit -F commit_message.txt | |
| - id: commit-message-from-file | |
| name: Parse commit message from file into variable | |
| if: hashFiles('git_diff_exists') != '' | |
| run: | | |
| body=$(cat commit_message.txt) | |
| body="${body//$'\n'/'%0A'}" | |
| echo ::set-output name=body::$body | |
| - name: Create Pull Request | |
| if: hashFiles('git_diff_exists') != '' | |
| uses: cfengine/create-pull-request@158a28c1bf5c08c846b8e7d26d13becbd4136eda # v7.0.7a | |
| with: | |
| title: Reformatted python code using Black formatter | |
| body: ${{ steps.commit-message-from-file.outputs.body }} | |
| reviewers: | | |
| olehermanse | |
| larsewi | |
| vpodzime | |
| branch: formatting-action |