diff --git a/.github/workflows/additional_checks.yml b/.github/workflows/additional_checks.yml index 05ea074c6c7..8e1fd3969b1 100644 --- a/.github/workflows/additional_checks.yml +++ b/.github/workflows/additional_checks.yml @@ -25,6 +25,9 @@ jobs: runs-on: ubuntu-24.04 permissions: contents: read + env: + # renovate: datasource=pypi depName=prek + PREK_VERSION: 0.2.24 steps: - name: Checkout repository contents @@ -50,7 +53,7 @@ jobs: - name: Generate core modules with last commit JSON file and test it run: | - python -m pip install pytest pytest-depends + python -m pip install pytest pytest-depends pytest-timeout python utils/generate_last_commit_file.py . pytest utils/test_generate_last_commit_file.py @@ -64,20 +67,61 @@ jobs: python ./utils/generate_release_notes.py log \ "${GITHUB_REF_NAME}" \ "$(git rev-parse HEAD~30)" \ - "" - - name: "Cache pre-commit" + "" | \ + tee -a "release_notes_sample.md" + - name: Upload release notes and core modules with last commit JSON file + if: ${{ !cancelled() }} + uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0 + with: + name: release_notes-core_modules_with_last_commit + path: |- + core_modules_with_last_commit.json + release_notes_sample.md + - name: Remove created files + run: rm --verbose -f release_notes_sample.md core_modules_with_last_commit.json + - name: "Cache pre-commit/prek" # Not used for releases, only for running pre-commit uses: actions/cache@9255dc7a253b0ccc959486e2bca901246202afeb # v5.0.1 # zizmor: ignore[cache-poisoning] with: - path: ~/.cache/pre-commit + path: |- + ~/.cache/prek key: pre-commit-${{ hashFiles('.pre-commit-config.yaml') }} + - name: Install prek + run: uv tool install "prek@${PREK_VERSION}" + - name: "Run pre-commit/prek for fixes" + run: | + echo '```console' > "$GITHUB_STEP_SUMMARY" + # Enable color output for pre-commit and remove it for the summary + # Use --hook-stage=manual to enable slower pre-commit hooks that are skipped by default + # Skip hooks already handled in another workflow, to avoid duplicate suggestions + # Skip hooks with no fixes made with these hooks (for now) + prek run --all-files --show-diff-on-failure --color=always --hook-stage=manual \ + --skip ruff-check --skip ruff-format \ + --skip actionlint \ + --skip editorconfig-checker \ + --skip flake8 \ + --skip yamllint | \ + tee >(sed -E 's/\x1B\[([0-9]{1,2}(;[0-9]{1,2})*)?[mGK]//g' >> "$GITHUB_STEP_SUMMARY") >&1 + exit_code="${PIPESTATUS[0]}" + echo '```' >> "$GITHUB_STEP_SUMMARY" + exit "$exit_code" - - name: "Run pre-commit" + - name: Create and uploads code suggestions to apply for pre-commit + # Will fail fast here if there are changes required + id: diff-pre-commit + # To run after pre-commit step exits with failure + if: ${{ !cancelled() }} + uses: ./.github/actions/create-upload-suggestions + with: + tool-name: pre-commit + # To keep repo's file structure in formatted changes artifact + extra-upload-changes: pyproject.toml + - name: "Run pre-commit/prek" run: | echo '```console' > "$GITHUB_STEP_SUMMARY" # Enable color output for pre-commit and remove it for the summary # Use --hook-stage=manual to enable slower pre-commit hooks that are skipped by default - uvx pre-commit run --all-files --show-diff-on-failure --color=always --hook-stage=manual | \ + prek run --all-files --show-diff-on-failure --color=always --hook-stage=manual | \ tee >(sed -E 's/\x1B\[([0-9]{1,2}(;[0-9]{1,2})*)?[mGK]//g' >> "$GITHUB_STEP_SUMMARY") >&1 exit_code="${PIPESTATUS[0]}" echo '```' >> "$GITHUB_STEP_SUMMARY" diff --git a/.github/workflows/post-pr-reviews.yml b/.github/workflows/post-pr-reviews.yml index fa4bd603e5e..d987d27290b 100644 --- a/.github/workflows/post-pr-reviews.yml +++ b/.github/workflows/post-pr-reviews.yml @@ -4,7 +4,10 @@ name: Post PR code suggestions on: # zizmor: ignore[dangerous-triggers] Only selected workflows, and whitelisted input values are used workflow_run: - workflows: ["ClangFormat Check", "Python Code Quality"] + workflows: + - "Additional checks" + - "ClangFormat Check" + - "Python Code Quality" types: - completed permissions: {} @@ -28,6 +31,7 @@ jobs: github-token: ${{ github.token }} run-id: ${{github.event.workflow_run.id }} - uses: reviewdog/action-setup@d8a7baabd7f3e8544ee4dbde3ee41d0011c3a93f # v1.5.0 + - run: reviewdog -version - name: Check what tools have suggestions to post # Using this pattern to have expected file names explicitly named id: tools @@ -48,6 +52,7 @@ jobs: INPUT_TOOL_NAMES: >- black clang-format + pre-commit ruff - name: Post Black suggestions if: ${{ steps.tools.outputs.black == 'true' }} @@ -85,6 +90,24 @@ jobs: 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 pre-commit suggestions + if: ${{ steps.tools.outputs.pre-commit == '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: pre-commit + 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: |