Skip to content

chore: ignore non-code files from triggering builds#3175

Closed
rahul31124 wants to merge 1 commit into
fossasia:flutterfrom
rahul31124:non_code_file
Closed

chore: ignore non-code files from triggering builds#3175
rahul31124 wants to merge 1 commit into
fossasia:flutterfrom
rahul31124:non_code_file

Conversation

@rahul31124

@rahul31124 rahul31124 commented Apr 12, 2026

Copy link
Copy Markdown
Member

Fixes #3168

Changes

Previously, paths-ignore was used to skip CI builds for documentation and media files.
Since Android and iOS builds are marked as required checks, skipping these jobs meant no status was reported, which blocked the Merge button even for documentation-only PRs.

Solution

Added a Detect Changes gatekeeper job that checks the PR diff.
Instead of skipping the workflow, heavy build/test steps are skipped for non-code changes while still reporting successful CI checks.

How It Works

Detect Changes Logic

The Detect Changes job determines whether a PR contains code changes or only documentation/media files.

  1. Git Diff Check

    • Runs git diff --name-only between the PR base SHA and head SHA.
    • This checks the entire PR change, even if it contains multiple commits.
  2. Filtering Non-Code Files
    The file list is filtered using grep:

    • Extension filter: removes files like .md, .png, .jpg, .svg, .txt, .arb
    • Path filter: removes files inside the docs/ directory
  3. Decision

    • If files remain → is_code = true (code changes detected)
    • If nothing remains → is_code = false (documentation/media only)

CI Workflow Behavior

  • Doc-only changes

    • Build and test steps are skipped
    • CI finishes in a few seconds
  • Code changes

    • Full CI pipeline runs
  • Mixed changes

    • Full CI pipeline runs

Result

I tested the changes in my fork: rahul31124#35

The CI workflow runs successfully and required checks are reported correctly.
Documentation-only changes now skip heavy build steps while still completing the required CI jobs.

As a result, PR #3150 can now be merged.

Screenshots / Recordings

N/A

Checklist:

  • No hard coding: I have used values from constants.dart or localization files instead of hard-coded values.
  • No end of file edits: No modifications done at end of resource files.
  • Code reformatting: I have formatted the code using dart format or the IDE formatter.
  • Code analysis: My code passes checks run in flutter analyze and tests run in flutter test.

Summary by Sourcery

Introduce a change-detection gate in the pull request workflow so required CI jobs always report status while heavy build steps are skipped for non-code changes.

Build:

  • Replace pull_request paths-ignore filters with a Detect Changes job that classifies PRs as code vs non-code changes and exposes this via a workflow output.

CI:

  • Condition all platform build and screenshot jobs on the Detect Changes result so code changes run full builds while documentation/media-only PRs complete quickly with lightweight no-op steps.

@sourcery-ai

sourcery-ai Bot commented Apr 12, 2026

Copy link
Copy Markdown
Contributor

Reviewer's Guide

Introduces a Detect Changes gatekeeper job in the pull-request GitHub Actions workflow that always runs, classifies PRs as code vs non-code based on a git diff, and conditionally runs or skips the expensive platform build/screenshot jobs while still reporting required checks for all PRs.

Flow diagram for Detect Changes gatekeeper logic

flowchart TD
  start([Start Detect Changes job])
  diff[Run git diff --name-only base_sha..head_sha]
  filterExt[Filter out files by extension md, png, jpg, jpeg, gif, svg, webp, txt, arb]
  filterDocs[Filter out files under docs directory]
  anyFiles{Any files remaining?}
  isCodeTrue[Set output is_code=true]
  isCodeFalse[Set output is_code=false]
  endTrue([Downstream jobs see is_code=true])
  endFalse([Downstream jobs see is_code=false])

  start --> diff --> filterExt --> filterDocs --> anyFiles
  anyFiles -->|Yes| isCodeTrue --> endTrue
  anyFiles -->|No| isCodeFalse --> endFalse
Loading

File-Level Changes

Change Details Files
Add a gatekeeper job that detects whether a pull request has code changes vs documentation/media-only changes and exposes this as a workflow output.
  • Define a new changes job that checks out the repository with full history on ubuntu-latest
  • Run git diff between the pull request base and head SHAs to list changed files
  • Filter out non-code files by extension and docs/ directory paths using grep, setting an is_code output flag accordingly
.github/workflows/pull-request.yml
Wire all existing platform build and screenshot jobs to respect the Detect Changes result so that heavy CI work is skipped for non-code changes while required checks still complete.
  • Make the common job depend on the changes job and guard all its steps with an is_code == 'true' condition, adding a fallback echo step for non-code changes
  • Update android, ios, windows, linux, linux-arm64, macos, and screenshot jobs to depend on changes (and common where needed), adding conditional checkout/build steps when is_code is true and a lightweight echo step otherwise
  • Use conditional expressions to choose macOS runners only when is_code is true and default to ubuntu-latest otherwise for jobs that no longer need macOS on non-code PRs
.github/workflows/pull-request.yml
Remove the previous paths-ignore based skipping mechanism in favor of the new diff-based gating approach.
  • Delete the paths-ignore section on the pull_request trigger that excluded docs and media file patterns so that the workflow still runs for these changes
  • Rely entirely on the changes gatekeeper to decide whether to run full builds or short-circuit jobs for documentation-only PRs
.github/workflows/pull-request.yml

Assessment against linked issues

Issue Objective Addressed Explanation
#3168 Ensure that required CI checks (especially Android and iOS builds) still run and report a status for PRs that only modify non-code files (e.g., .md, docs, images), so such PRs are mergeable via the GitHub web interface.
#3168 Avoid running heavy build and test steps for PRs that only modify non-code files, while still completing the CI workflow and required jobs.

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 1 issue, and left some high level feedback:

  • The grep -v '^docs/' filter only ignores files in a top-level docs/ directory, whereas the previous paths-ignore: docs/** would also ignore nested docs paths (e.g. packages/foo/docs/...); if such patterns exist in this repo, consider broadening the path filter to preserve the previous behavior.
  • Many jobs repeat the same if: needs.changes.outputs.is_code == 'true' on each step and add a nearly identical Non-Code Change step; you could simplify this by using a job-level if: for code-only jobs or extracting a reusable step/action to avoid duplication.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The `grep -v '^docs/'` filter only ignores files in a top-level `docs/` directory, whereas the previous `paths-ignore: docs/**` would also ignore nested docs paths (e.g. `packages/foo/docs/...`); if such patterns exist in this repo, consider broadening the path filter to preserve the previous behavior.
- Many jobs repeat the same `if: needs.changes.outputs.is_code == 'true'` on each step and add a nearly identical `Non-Code Change` step; you could simplify this by using a job-level `if:` for code-only jobs or extracting a reusable step/action to avoid duplication.

## Individual Comments

### Comment 1
<location path=".github/workflows/pull-request.yml" line_range="24-33" />
<code_context>
+    outputs:
+      is_code: ${{ steps.check.outputs.is_code }}
+    steps:
+      - uses: actions/checkout@v6
+        with:
+          fetch-depth: 0
+
+      - id: check
+        run: |
+          # Diff the actual commit SHAs. 
+          # grep -vE removes your media/doc extensions. grep -v removes the docs folder.
+          # If anything is left over, it's code. If the output is empty, it's just docs.
+          if git diff --name-only ${{ github.event.pull_request.base.sha }} ${{ github.event.pull_request.head.sha }} | grep -vE '\.(md|png|jpg|jpeg|gif|svg|webp|txt|arb)$' | grep -v '^docs/'; then
+            echo "is_code=true" >> $GITHUB_OUTPUT
+          else
+            echo "is_code=false" >> $GITHUB_OUTPUT
+          fi
+
   common:
     name: Common Build
+    needs: changes
     runs-on: ubuntu-latest
     steps:
       - uses: actions/checkout@v6
+        if: needs.changes.outputs.is_code == 'true'

       - name: Common Workflow
</code_context>
<issue_to_address>
**suggestion (performance):** Consider moving the `if` condition from steps to the job level where possible.

Since every significant step in jobs like `common`, `android`, and `ios` is already guarded with `if: needs.changes.outputs.is_code == 'true'`, you could instead move this condition to the job level and introduce a small separate job for the non-code path. This would avoid spinning up runners for jobs that immediately skip all steps and make the code/non-code behavior clearer at a glance. Optional, but would simplify the workflow and reduce unnecessary resource usage.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment on lines +24 to +33
- uses: actions/checkout@v6
with:
fetch-depth: 0

- id: check
run: |
# Diff the actual commit SHAs.
# grep -vE removes your media/doc extensions. grep -v removes the docs folder.
# If anything is left over, it's code. If the output is empty, it's just docs.
if git diff --name-only ${{ github.event.pull_request.base.sha }} ${{ github.event.pull_request.head.sha }} | grep -vE '\.(md|png|jpg|jpeg|gif|svg|webp|txt|arb)$' | grep -v '^docs/'; then

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (performance): Consider moving the if condition from steps to the job level where possible.

Since every significant step in jobs like common, android, and ios is already guarded with if: needs.changes.outputs.is_code == 'true', you could instead move this condition to the job level and introduce a small separate job for the non-code path. This would avoid spinning up runners for jobs that immediately skip all steps and make the code/non-code behavior clearer at a glance. Optional, but would simplify the workflow and reduce unnecessary resource usage.

@github-actions

Copy link
Copy Markdown
Contributor

Build Status

Build successful. APKs to test: https://github.com/fossasia/pslab-app/actions/runs/24307223668/artifacts/6392888206.

Screenshots

Android Screenshots
iPhone Screenshots
iPad Screenshots

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CI does not run required steps if PR contains only MD files

1 participant