Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce 'paths_filter' option along with new return values #159

Closed
wants to merge 5 commits into from

Conversation

paescuj
Copy link
Collaborator

@paescuj paescuj commented Nov 29, 2021

This introduces a new option called paths_filter which can be used to define one or more named filters with path patterns (paths_ignore, paths), inspired by the paths-filter action. When defining such filters, the action returns corresponding information in a new output called paths_result.
This makes it possible to get dedicated information about different path patterns and react accordingly, in a single run of 'skip-duplicate-actions'.
For example in a monorepo, I want to run jobs related to the "frontend" only if some files in the corresponding folder frontend/ have changed and same with "backend". This can now be achieved with the following configuration:

jobs:
  pre_job:
    runs-on: ubuntu-latest
    outputs:
      should_skip: ${{ steps.skip_check.outputs.should_skip }}
      paths_result: ${{ steps.skip_check.outputs.paths_result }}
    steps:
      - id: skip_check
        uses: fkirc/skip-duplicate-actions@master
        with:
          paths_filter: |
            frontend:
              paths:
                - 'frontend/**/*'
            backend:
              paths:
                - 'backend/**/*'

  frontend:
    needs: pre_job
    if: needs.pre_job.outputs.should_skip != 'true' || !fromJSON(needs.pre_job.outputs.paths_result).frontend.should_skip
    ...

  backend:
    ...

The paths_result output returns a JSON-object which looks something like this:

{
  "frontend": {
    "should_skip": true,
    "backtrack_count": 1,
    "skipped_by": {
      // Information about the workflow run
    }
  },
  "backend": {
    "should_skip": false,
    "backtrack_count": 1,
    "matched_files": ["backend/file.txt"]
  },
  "global": {
    "should_skip": false,
    "backtrack_count": 0
  }
}

If 'skip-duplicate-actions' terminates before the paths checks are performed (for example, when a successful duplicate run has been found) the paths_result returns an empty object ({}). This can be easily intercepted in the if condition of a job by checking the result of the "global" should_skip output first (see above).
The global key in the output of paths_result corresponds to the "global" paths_ignore and paths inputs, which makes it possible to profit from the information of paths_result even when only defining "global" paths_ignore and/or paths inputs.
As you can see above, the paths_result object also returns a list of matched files, if there are any, and skipped_by information.
The backtrack_count shows how many commits where traced back (skipped) until a result has been found.

The named filters in paths_filter also accept the paths_ignore setting and backtracking can optionally be disabled or limited to a number of commits, for example:

          paths_filter:
            frontend:
              paths_ignore:
                - 'frontend/readme.md'
                - 'frontend/docs/**/*'
              paths:
                - 'frontend/**/*'
              # can be a boolean or number (default: true)
              # 5 means to stop after having traced back 5 commits
              backtracking: 5

In addition, this pull request introduces the following outputs:

  • changed_files: A two-dimensional array, with a list of changed files for each commit that was traced back. Returns information only if one of the options "paths_ignore", "paths" or "paths_filter" is set.
    • For example: [["some/example/file.txt", "another/example/file.txt"], ["frontend/file.txt"]]
    • Having a two-dimensional list makes processing flexible. For example, one can flatten (and uniquify) the list to get all changed files for all commits which were traced back. Or one can use changed_files[0] to get the changed files in the current commit. One might also use the output of backtrack_count to process the list of changed files.
  • reason: The reason why the current run is considered skippable or unskippable.
    • For example: skip_after_successful_duplicate

This pull request contains no breaking changes and I was particularly careful to not compromise the performance of the action.

Closes #139

@fkirc If you like those changes (I really hope you do 😄), I'll happily update the README.

@paescuj paescuj marked this pull request as ready for review November 30, 2021 09:34
@fkirc
Copy link
Owner

fkirc commented Dec 4, 2021

Thanks for submitting the PR with detailed descriptions.
The changes look good, but I think that we need to split this into multiple PRs.
I suggest the following structure:

  • a separate PR for dependency updates
  • a separate PR for the reason output
  • a separate PR for the changed_file output
  • a separate PR for paths_filter/paths_result

My hope is that small chunks of functionality make it easier to upgrade this action in a safe way.

@paescuj
Copy link
Collaborator Author

paescuj commented Dec 4, 2021

Thanks for submitting the PR with detailed descriptions. The changes look good, but I think that we need to split this into multiple PRs. I suggest the following structure:

* a separate PR for dependency updates

* a separate PR for the reason output

* a separate PR for the changed_file output

* a separate PR for paths_filter/paths_result

My hope is that small chunks of functionality make it easier to upgrade this action in a safe way.

Hey @fkirc, thanks for your positive feedback! Sure, will split it up and submit separate pull requests tomorrow 👍

@paescuj
Copy link
Collaborator Author

paescuj commented Dec 4, 2021

Also, please let me know if you have better ideas about the naming of the input/output parameters.

paescuj added a commit to paescuj/skip-duplicate-actions that referenced this pull request Jan 16, 2022
@paescuj paescuj mentioned this pull request Jan 16, 2022
paescuj added a commit to paescuj/skip-duplicate-actions that referenced this pull request Jan 16, 2022
paescuj added a commit to paescuj/skip-duplicate-actions that referenced this pull request Jan 16, 2022
@paescuj
Copy link
Collaborator Author

paescuj commented Jan 16, 2022

Closing in favor of new PRs (#179, #180 & others will follow soon).

@paescuj paescuj closed this Jan 16, 2022
paescuj added a commit to paescuj/skip-duplicate-actions that referenced this pull request Jan 16, 2022
fkirc pushed a commit that referenced this pull request Jan 16, 2022
* Udpdate all dependencies

See #159

* Switch to Node.js v16

Node.js v16 is current LTS and now supported as action runtime

* Only format files in 'src' folder
fkirc added a commit that referenced this pull request Jan 16, 2022
* Udpdate all dependencies

See #159

* Switch to Node.js v16

Node.js v16 is current LTS and now supported as action runtime

* Only format files in 'src' folder

* Introduce 'reason' output

See #159

Co-authored-by: Felix K <[email protected]>
fkirc pushed a commit that referenced this pull request Jan 17, 2022
* Udpdate all dependencies

See #159

* Switch to Node.js v16

Node.js v16 is current LTS and now supported as action runtime

* Only format files in 'src' folder

* Introduce 'reason' output

See #159

* Introduce 'paths_filter' option and 'changed_files' output

See #159

* Fix action.yml and first part of README update

* Rebuild

* Update README.md to reflect new input/outputs
@paescuj paescuj deleted the path-filters branch October 5, 2022 10:23
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.

Matched paths as output
2 participants