Skip to content

@action/glob: expose a public method to test patterns on given paths #2169

@redsun82

Description

@redsun82

Describe the enhancement
The globber instance returned by glob.create should have a method test(path: string): boolean returning whether the given path matches the patterns provided on creation.

Additional information
Currently @actions/glob only allows to use a pattern to iterate through actual files existing on the runner at the time of execution. There are however use cases where we want to know which files from a given list match against a list of patterns.

We have such a use case where we first fetch the list of files changed by a PR (via a paginated oktokit's rest.pulls.listFiles request), and we want to filter them with a list of patterns, in a way consistent with how glob patterns work across github actions.

@actions/glob would seem like the library of choice for this, but because it insists on providing existing files it's not of immediate use. I ended up recreating a tree structure of empty files from the list of modified files to appease @actions/glob, but a test method would be much more natural to use. As far as I can tell this would just require exporting functionality that is already present in the library implementation.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions