diff --git a/.github/workflows/linting.yml b/.github/workflows/linting.yml index 4bbeedd..7ef50f3 100644 --- a/.github/workflows/linting.yml +++ b/.github/workflows/linting.yml @@ -145,6 +145,12 @@ jobs: - name: Check code style with Black run: | black --check --diff --line-length 79 . + - name: Create and upload code suggestions to apply for black + id: diff-black + uses: OSGeo/grass/.github/actions/create-upload-suggestions@main + with: + tool-name: black + # extra-upload-changes: .clang-format ruff: name: ruff if: ${{ inputs.ruff-version != '' }} @@ -164,9 +170,20 @@ jobs: run: | echo "ruff.toml does not exists. Will be downloaded." wget https://raw.githubusercontent.com/mundialis/github-workflows/main/linting-config-examples/ruff.toml - - name: Lint with ruff - run: | - ruff check --config ruff.toml . + - name: Run ruff (output annotations on fixable errors) + run: | + ruff check --config ruff.toml --output-format=github . --preview --unsafe-fixes + continue-on-error: true + - name: Run ruff (apply fixes for suggestions) + run: | + ruff check --config ruff.toml . --preview --fix --unsafe-fixes + - name: Create and upload code suggestions to apply for ruff + id: diff-ruff + if: ${{ !cancelled() }} + uses: OSGeo/grass/.github/actions/create-upload-suggestions@main + with: + tool-name: ruff + # extra-upload-changes: ruff.toml super-linter: name: super-linter runs-on: ubuntu-latest diff --git a/.github/workflows/post-pr-reviews.yml b/.github/workflows/post-pr-reviews.yml new file mode 100644 index 0000000..f135ae3 --- /dev/null +++ b/.github/workflows/post-pr-reviews.yml @@ -0,0 +1,84 @@ +# from https://github.com/OSGeo/grass/blob/main/.github/workflows/post-pr-reviews.yml and slightly modified +--- +name: Post PR code suggestions + +on: + workflow_call: + +permissions: {} +jobs: + post-suggestions: + runs-on: ubuntu-latest + # Only run on failures, since no changes are needed on success + # if: > + # (github.event.workflow_run.event == 'pull_request' && + # github.event.workflow_run.conclusion == 'failure') + permissions: + pull-requests: write + steps: + - name: Create a .git directory needed by reviewdog + run: git init + - uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.8 + id: diff + continue-on-error: true + with: + name: diff + github-token: ${{ github.token }} + run-id: ${{github.event.workflow_run.id }} + - uses: reviewdog/action-setup@3f401fe1d58fe77e10d665ab713057375e39b887 # v1.3.0 + - name: Check what tools have suggestions to post + # Using this pattern to have expected file names explicitly named + id: tools + run: | + for tool_name in $INPUT_TOOL_NAMES + do + INPUT_TOOL_NAME_FILE="diff-${tool_name}.patch" + echo "Checking if tool ${tool_name} left suggestions in ${INPUT_TOOL_NAME_FILE}..." + if [[ -f "${INPUT_TOOL_NAME_FILE}" ]]; then + echo " ${INPUT_TOOL_NAME_FILE} was found for tool ${tool_name}" + echo "$tool_name=true" >> "${GITHUB_OUTPUT}" + else + echo " ${INPUT_TOOL_NAME_FILE} was not found for tool ${tool_name}" + echo "$tool_name=false" >> "${GITHUB_OUTPUT}" + fi + done + env: + INPUT_TOOL_NAMES: >- + black + ruff + - name: Post black suggestions + if: ${{ steps.tools.outputs.black == 'true' }} + run: | + TMPFILE="diff-${INPUT_TOOL_NAME}.patch" + GITHUB_ACTIONS="" reviewdog \ + -name="${INPUT_TOOL_NAME:-reviewdog-suggester}" \ + -f=diff \ + -f.diff.strip=1 \ + -filter-mode=nofilter \ + -guess \ + -reporter="github-pr-review" < "${TMPFILE}" + env: + INPUT_TOOL_NAME: black + REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }} + CI_COMMIT: ${{ github.event.workflow_run.head_sha }} + CI_REPO_OWNER: ${{ github.event.workflow_run.repository.owner.login }} + CI_REPO_NAME: ${{ github.event.workflow_run.repository.name }} + # CI_PULL_REQUEST: "" # Populated from reviewdog's "-guess" flag since hard to get + - name: Post ruff suggestions + if: ${{ steps.tools.outputs.ruff == 'true' }} + run: | + TMPFILE="diff-${INPUT_TOOL_NAME}.patch" + GITHUB_ACTIONS="" reviewdog \ + -name="${INPUT_TOOL_NAME:-reviewdog-suggester}" \ + -f=diff \ + -f.diff.strip=1 \ + -filter-mode=nofilter \ + -guess \ + -reporter="github-pr-review" < "${TMPFILE}" + env: + INPUT_TOOL_NAME: ruff + REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }} + CI_COMMIT: ${{ github.event.workflow_run.head_sha }} + CI_REPO_OWNER: ${{ github.event.workflow_run.repository.owner.login }} + CI_REPO_NAME: ${{ github.event.workflow_run.repository.name }} + # CI_PULL_REQUEST: "" # Populated from reviewdog's "-guess" flag since hard to get