Skip to content

zyactions/glob

Use this GitHub action with your project
Add this Action to an existing workflow or create a new one
View on Marketplace

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Glob Match

License: MIT CI Ubuntu macOS Windows

A GitHub Action for matching glob patterns.

Features

  • Matches filenames and pathes using glob patterns
    • ... in the file system
    • ... from a user-supplied input
    • ... from an input pipe
  • Fast execution
  • Scales to large repositories
  • Supports all platforms (Linux, macOS, Windows)
  • Does not use external GitHub Actions dependencies

Usage

Match Files in the File System

steps:
  - name: Checkout
    uses: actions/checkout@v3

  - name: Glob Match
    id: glob
    uses: zyactions/glob@v2
    with:
      pattern: |
        **/[ac].txt
        !test/a.txt

  - name: Print Matches
    run: |
      echo "${{ steps.glob.outputs.matches }}"

Match Input Values

steps:
  - name: Glob Match
    id: glob
    uses: zyactions/glob@v2
    with:
      pattern: '**/[ac].txt'
      values: |-
        test/a.txt
        test/b.txt
        text/c.txt

  - name: Print Matches
    run: |
      echo "${{ steps.glob.outputs.matches }}"

The input values must be separated by line breaks.

Match Input Values from Pipe

steps:
  - name: Checkout
    uses: actions/checkout@v3

  - name: Glob Match
    id: glob
    uses: zyactions/glob@v2
    with:
      pattern: '**/[ac].txt'
      pipe: 'git diff --name-only'

  - name: Print Matches
    run: |
      echo "${{ steps.glob.outputs.matches }}"

This is especially useful when a large number of items need to be matched without first storing them in an action output, environment variable, temporary file, or other temporary storage.

The input values returned by the pipe command must be separated by line breaks.

Return a Pipe Command

steps:
  - name: Checkout
    uses: actions/checkout@v3

  - name: Glob Match
    id: glob
    uses: zyactions/glob@v2
    with:
      pattern: '**/[ac].txt'
      return-pipe: true

  - name: Print Matches
    shell: bash
    run: |
      ${{ steps.glob.outputs.pipe }} | while IFS= read -r x ; do echo $x ; done

The return-pipe option can also be combined with the pipe input to insert a glob filter step in the middle of a pipeline.

Inputs

working-directory

The working-directory for the action.

Defaults to the repository root directory (github.workspace).

When working on the file system, patterns and matches are considered relative to the specified working directory. If the pipe input is used, the pipe command will be executed in the current working-directory. This input has no effect if the values input is set.

The working directory will as well be included in the pipe output, if return-pipe is enabled.

pattern

One or more file, path, or placeholder patterns that describe which items to match.

Check out the glob pattern cheat sheet for reference. Multi line patterns must be specified without quotes.

Note

When running on Windows, / and \ are accepted as path separators. When running on UNIX systems, only / is accepted as the path separator. This as well applies to the input values.

values

An optional list of values to be matched (separated by line breaks).

The action operates on the file system if neither the values-, nor the pipe-input is set.

Note: This input must be used mutually exclusive with the pipe input.

pipe

An optional pipe input from which the input values are to be read.

This must be set to a valid shell command line (bash) that can be used for piping. The command must output to stdout and separate the individual values by line breaks.

The action operates on the file system if neither the values-, nor the pipe-input is set.

Warning

The command passed to this input will be evaluated and should not come from untrusted sources.

Note:

The pipe command is executed in the current working-directory by default. If the pipe command is to be executed in another working directory, make sure to properly insert a directory change command.

Example pipe command:

(cd '/my/absolute/workdir' && ls -1)

Note: This input must be used mutually exclusive with the values input.

return-pipe

Enable this option to return a shell (bash) command in the pipe output that can be used for piping.

The output command must be evaled to return the results. It can also be passed to other actions that support a pipe input.

Note: The matches output will not be populated if this option is enabled.

Outputs

matches

A list of all matching elements, delimited by newlines or spaces (if the quote option is used).

Note: This output is only available if the return-pipe option is not enabled.

pipe

A shell (bash) command which can be used for piping.

Note: This output is only available if the return-pipe option is enabled.

Dependencies

This action does not use external GitHub Actions dependencies.

Internal depenencies:

Versioning

Versions follow the semantic versioning scheme.

License

Glob Match Action is licensed under the MIT license.