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

Export lists of changed files via action output parameter #20

Closed
dorny opened this issue Jun 30, 2020 · 6 comments
Closed

Export lists of changed files via action output parameter #20

dorny opened this issue Jun 30, 2020 · 6 comments
Assignees
Labels
enhancement New feature or request
Milestone

Comments

@dorny
Copy link
Owner

dorny commented Jun 30, 2020

For some use-cases it might be useful to provide access to lists of changed (or added/deleted/modified) files via output parameters.

For this use-cases there is already Changed Files Exporter action. Benefit to implement it here is that we could make it work also for push events and provide different encoding option (JSON array, new-line delimited).

@robdodson
Copy link
Contributor

Would this make it so I could get a list of files that changed that matched a specific filter?

My use case is I'd like to pass a path separated list of files to textlint only if those files have changed. Something like:

- name: Get changed files
  uses: dorny/paths-filter@v2.2.0
  id: filter
  with:
  filters: |
    markdown:
      - '*.md'
- name: Lint Markdown
    if: ${{ steps.filter.outputs.markdown == 'true' }}
    run: npx textlint ${{ steps.filter.outputs.all_files }}  # where all_files would equal a space separated list of markdown file paths

@dorny
Copy link
Owner Author

dorny commented Aug 13, 2020

Unfortunately right now this wouldn't work
What's implemented on the develop branch returns JSON object with lists for all added, modified and deleted files.
Provided path filters are not considered for this output, what I see now, is not very useful.

I will change it so it could support your use case. Maybe I will get to it tomorrow. If not, then it will take some more time as I'm going for a vacation afterwards.

Anyway, to avoid problems with files with white-space characters, the output will be definitely in the JSON format.
You will have to use jq tool to transform it to space-delimited list.

@robdodson
Copy link
Contributor

Sounds good, thank you :)

I'm not familiar with the jq tool, do you happen to have a link with an explainer?

@dorny
Copy link
Owner Author

dorny commented Aug 15, 2020

Here's the proposal. I already implemented in a PR #32
Given your example, it would work like this:

- uses: dorny/paths-filter@export-files
  id: filter
  with:
    list-files: shell
    filters: |
      markdown:
        - added|modified: '*.md'
- name: Lint Markdown
  if: ${{ steps.filter.outputs.markdown == 'true' }}
  run: npx textlint ${{ steps.filter.outputs.markdown_files }}

Input parameter list-files set to shell enables listing of matching files for each rule.
Output is provides as ${RULE_NAME}_files output variable, in this case it's markdown_files .
The shell format wraps each path in single quotes so the output can be directly used in shell scrips.
Therefore the jq tool I mention earlier won't be needed.

Another part of the solution is the added|modified specifier in the rule.
Normally deleted files are also considered as "changed". For example if this action it's used to conditionally run tests, deletion of matching file should trigger it.

For linting it obviously doesn't make sense to consider removed files and linting tools would probably error on non-existent files.

Would this work for you?
I still have to update the documentation but then I could release it as v2.3.0

@robdodson
Copy link
Contributor

This looks great! Yeah we would totally use this :)

@dorny
Copy link
Owner Author

dorny commented Sep 14, 2020

Implemented in release v2.3.0

@dorny dorny closed this as completed Sep 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants