diff --git a/.github/file-filters.yml b/.github/file-filters.yml index dd3619b3462..d209f50b83e 100644 --- a/.github/file-filters.yml +++ b/.github/file-filters.yml @@ -65,6 +65,25 @@ run_api_stability_for_prs: &run_api_stability_for_prs # API-related code - "sdk_api.json" - "sdk_api_v9.json" +run_lint_clang_formatting_for_prs: &run_lint_clang_formatting_for_prs + - "**/*.h" + - "**/*.hpp" + - "**/*.c" + - "**/*.cpp" + - "**/*.m" + - "**/*.mm" + + # GH Actions + - ".github/workflows/lint-clang-formatting.yml" + - ".github/file-filters.yml" + + # Formatting + - ".clang-format" + # Other + - "Makefile" # Make commands used for formatting setup + - "Brewfile*" # Tools installation affects formatting environment + - "scripts/ci-diagnostics.sh" # CI diagnostics may affect formatting checks + run_objc_conversion_analysis_for_prs: &run_objc_conversion_analysis_for_prs - "SwiftConversion/**" diff --git a/.github/workflows/lint-clang-formatting.yml b/.github/workflows/lint-clang-formatting.yml index 56809714e2f..07854da1e67 100644 --- a/.github/workflows/lint-clang-formatting.yml +++ b/.github/workflows/lint-clang-formatting.yml @@ -4,32 +4,8 @@ on: push: branches: - main - paths: - - "**/*.h" - - "**/*.hpp" - - "**/*.c" - - "**/*.cpp" - - "**/*.m" - - "**/*.mm" - - ".github/workflows/lint-clang-formatting.yml" - - ".clang-format" - - "Makefile" # Make commands used for formatting setup - - "Brewfile*" # Tools installation affects formatting environment - - "scripts/ci-diagnostics.sh" pull_request: - paths: - - "**/*.h" - - "**/*.hpp" - - "**/*.c" - - "**/*.cpp" - - "**/*.m" - - "**/*.mm" - - ".github/workflows/lint-clang-formatting.yml" - - ".clang-format" - - "Makefile" # Make commands used for formatting setup - - "Brewfile*" # Tools installation affects formatting environment - - "scripts/ci-diagnostics.sh" # Concurrency configuration: # - We use workflow-specific concurrency groups to prevent multiple lint runs on the same code, @@ -43,10 +19,27 @@ concurrency: cancel-in-progress: ${{ github.event_name == 'pull_request' }} jobs: + files-changed: + name: Detect File Changes + runs-on: ubuntu-latest + outputs: + run_lint_clang_formatting_for_prs: ${{ steps.changes.outputs.run_lint_clang_formatting_for_prs }} + steps: + - uses: actions/checkout@v5 + - name: Get changed files + id: changes + uses: dorny/paths-filter@de90cc6fb38fc0963ad72b210f1f284cd68cea36 # v3.0.2 + with: + token: ${{ github.token }} + filters: .github/file-filters.yml + lint: # While ubuntu runners have clang-format preinstalled, they use an older version. We want to use the most recent one, # that we can easily install locally via brew. name: Lint + # Run the job only for PRs with related changes or non-PR events. + if: github.event_name != 'pull_request' || needs.files-changed.outputs.run_lint_clang_formatting_for_prs == 'true' + needs: files-changed runs-on: macos-15 steps: - uses: actions/checkout@v5 @@ -70,3 +63,21 @@ jobs: - name: Run CI Diagnostics if: failure() run: ./scripts/ci-diagnostics.sh + + lint_clang_formatting-required-check: + needs: + [ + files-changed, + lint, + ] + name: Lint Clang + # This is necessary since a failed/skipped dependent job would cause this job to be skipped + if: always() + runs-on: ubuntu-latest + steps: + # If any jobs we depend on fails gets cancelled or times out, this job will fail. + # Skipped jobs are not considered failures. + - name: Check for failures + if: contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled') + run: | + echo "One of the clang formatting check jobs has failed." && exit 1