-
Notifications
You must be signed in to change notification settings - Fork 124
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a CI workflow to report formatting issues on changed files. This is to gradually update files in the repository to be conform with PEP8 formatting. Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
- Loading branch information
Showing
1 changed file
with
77 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
name: Format check | ||
|
||
on: | ||
pull_request: | ||
branches: | ||
- main | ||
paths: | ||
- '**.py' | ||
|
||
jobs: | ||
generate: | ||
runs-on: ubuntu-latest | ||
outputs: | ||
files: ${{ steps.git-diff-filter.outputs.files }} | ||
chunks: ${{ steps.git-diff-filter.outputs.chunks }} | ||
name: Detect added and changed files | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
|
||
- uses: GrantBirki/git-diff-action@v2 | ||
id: git-diff-action | ||
with: | ||
base_branch: origin/main | ||
search_path: '**.py' | ||
# there's a bug in parse-git-diff that forces us to have unified set to at least 1 | ||
# see https://github.com/yeonjuan/parse-git-diff/issues/33 | ||
git_options: '--no-color --full-index --unified=1' | ||
|
||
- name: Filter json diff | ||
id: git-diff-filter | ||
env: | ||
JSON_DIFF: ${{ steps.git-diff-action.outputs.json-diff }} | ||
run: | | ||
echo $JSON_DIFF | jq | ||
files=$(echo $JSON_DIFF | jq -c -r '[.files[] | select(.type == "AddedFile") | {path: .path}]') | ||
echo "files=$files" >> $GITHUB_OUTPUT | ||
chunks=$(echo $JSON_DIFF | jq -c -r '[.files[] | select(.type == "ChangedFile") | . as $file | .chunks[] | select(.toFileRange.lines > 0) | {path: $file.path, start: .toFileRange.start, end: (.toFileRange.start + .toFileRange.lines)}]') | ||
echo "chunks=$chunks" >> $GITHUB_OUTPUT | ||
check-files: | ||
needs: generate | ||
if: ${{ needs.generate.outputs.files != '[]' }} | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
files: ${{ fromJSON(needs.generate.outputs.files) }} | ||
name: Check file ${{ matrix.files.path }} | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: astral-sh/ruff-action@v1 | ||
with: | ||
args: "format --check --diff" | ||
src: "${{ matrix.files.path }}" | ||
- if: ${{ failure() }} | ||
run: | | ||
echo "::error file=${{ matrix.files.path }},title=File format check failed::Run 'ruff format ${{ matrix.files.path }}'" | ||
check-chunks: | ||
needs: generate | ||
if: ${{ needs.generate.outputs.chunks != '[]' }} | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
chunks: ${{ fromJSON(needs.generate.outputs.chunks) }} | ||
name: "Check chunk ${{ matrix.chunks.path }}:${{ matrix.chunks.start }}-${{ matrix.chunks.end }}" | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: astral-sh/ruff-action@v1 | ||
with: | ||
args: "format --check --diff --range ${{ matrix.chunks.start }}-${{ matrix.chunks.end }}" | ||
src: "${{ matrix.chunks.path }}" | ||
- if: ${{ failure() }} | ||
run: | | ||
echo "::error file=${{ matrix.chunks.path }},line=${{ matrix.chunks.start }},endLine=${{ matrix.chunks.end }},title=Chunk format check failed::Run 'ruff format --range ${{ matrix.chunks.start }}-${{ matrix.chunks.end }} ${{ matrix.chunks.path }}'" |