Skip to content

Set matrix based on changed file types #6

Open

Description

@p5

Currently, CodeQL runs all languages defined in the array, even when a pull request does not touch a particular language. For example a single change to index.js triggers Python tests if that repo contains any Python at all.

Some of the checks take much longer than the others, so engineers are often sat waiting around for Python checks to pass when they didn't change any Python.

It would be great if this action was able to check the file extensions changed in a Pull Request, and set the matrix accordingly.

Activity

  1. LeShadow commented on Oct 16, 2024

    @LeShadow
    Contributor

    @CallMeGreg I'd like to take this on if that works for you?

    @p5 Some engineering teams may prefer to maintain control over this aspect themselves. It might be worthwhile to consider adding an option where, if specific files are provided to the action, it returns the detected languages based on their extensions.

    In the absence of any specified files, the action could default to its current behavior, returning all detected languages?

  2. p5 commented on Oct 17, 2024

    @p5
    Author

    if specific files are provided to the action, it returns the detected languages based on their extensions.

    Apologies for not quite following your suggestion here regarding the specific files being provided. Do you mean having a custom step before this which will query git for the changed files, feeding all of them into this action as an input?

    - run: echo "changed-files=$(git list changed files)" >> $GITHUB_OUTPUT 
      id: changed-files
    
    - uses: <this-action>
      with:
        changed-files: ${{ steps.changed-files.output.changed-files }}
    

    I agree that we should try and keep the current usage available to consumers of the action, so I was thinking of an input such as filter-changed-file-types: true|false (defaulting to the current behaviour of false).

  3. CallMeGreg commented on Oct 17, 2024

    @CallMeGreg
    Contributor

    @LeShadow by all means, thanks for contributing! FWIW, I believe GitHub uses linguist to determine languages in repositories. Love the idea @p5 shared about an input parameter along the lines of only-scan-changed-file-types defaulting to false.

    cc @leftrightleft

  4. LeShadow commented on Oct 17, 2024

    @LeShadow
    Contributor

    @CallMeGreg Thanks! I already started on something in the background!

    @p5 Exactly!

    I would use something like this action: https://github.com/tj-actions/changed-files
    (It can output changed files in a multitude of ways, like separated by a comma, or in json format)

    And then feed the output of that action into this action where we can return languages based on the extensions found in the list of files.

    However, if the argument is empty, we just return all detected languages.

    Does that make sense?

    PS: I think that if we add functionality to detect changed files to this action, instead of feeding it a list, that it would overcomplicate things.

  5. felickz commented on Aug 5, 2026

    @felickz
    Contributor

    Caveat here is this will break any rules/rulesets that require code scanning results before merge on PR. If you skip scanning those languages- the rule will never be satisfied. It waits for the expected categories to upload for any category it has sent uploaded against the base branch.

    We have workarounds for this "republish/sarif-caching" but they are not OOTB :

    https://github.com/advanced-security/monorepo-code-scanning-action#republish

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

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions