From a27015abd73c5a14523a46d0fe4e093ed206c9ca Mon Sep 17 00:00:00 2001 From: Pieter De Gendt Date: Mon, 4 Nov 2024 20:21:18 +0100 Subject: [PATCH] ci: Add format check workflow 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 --- .github/workflows/format.yml | 57 ++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 .github/workflows/format.yml diff --git a/.github/workflows/format.yml b/.github/workflows/format.yml new file mode 100644 index 00000000..faae0068 --- /dev/null +++ b/.github/workflows/format.yml @@ -0,0 +1,57 @@ +name: Format check + +on: + pull_request: + branches: + - main + paths: + - '**.py' + +jobs: + generate: + runs-on: ubuntu-latest + outputs: + files: ${{ steps.git-diff-filter.outputs.files }} + 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' + # Ignore deleted files + git_options: '--no-color --diff-filter=d' + + - 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[] | {path: .path}]') + echo "files=$files" >> $GITHUB_OUTPUT + + check-files: + needs: generate + if: ${{ needs.generate.outputs.files != '[]' }} + runs-on: ubuntu-latest + # Allow the workflow run to pass when this job fails + continue-on-error: true + 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 "::warning file=${{ matrix.files.path }},title=File format check failed::Run 'ruff format ${{ matrix.files.path }}'"