Add if-no-files-found option to merge action#521
Add if-no-files-found option to merge action#521comp615 wants to merge 1 commit intoactions:mainfrom
Conversation
merge has no if-files-not-found so try skipping errors when this happens. actions/upload-artifact#520 / actions/upload-artifact#521 might allow us to change this in future.
roehrijn
left a comment
There was a problem hiding this comment.
Very cool. Just wanted to start implementing exactly this on my on. Good that I had a look into open pull requests first. I'm already using your code in our pipelines.
Jan Roehrich jan.roehrich@mercedes-benz.com, Mercedes-Benz Tech Innovation GmbH, legal info/Impressum
| # error: Fail the action with an error message | ||
| # ignore: Do not output any warnings or errors, the action does not fail | ||
| # Optional. Default is 'error' | ||
| if-no-files-found: |
There was a problem hiding this comment.
AFAIK we're talking about artifacts, not files. That's why I would call it at least if-no-artifacts-found. However, some other wording options (I don't have a strong opinion here, just some thoughts to find a good solution):
no-artifacts-behavior/ options:["warn", "error", "ignore"]no-artifacts-behavior/ options:["exit-with-warning", "fail", "exit-gracefully"]
| if (artifacts.length === 0) { | ||
| throw new Error(`No artifacts found matching pattern '${inputs.pattern}'`) | ||
| // No files were found, different use cases warrant different types of behavior if nothing is found | ||
| switch (inputs.ifNoFilesFound) { |
There was a problem hiding this comment.
I would definitely add a default behavior of the switch statement emitting an error in case the value is something not yet know, even though the values are validated before. Just to make sure somebody implementing a new option can not forget it.
|
@comp615 do you plan to continue on the PR? |
Fixes #520.
Why is this needed?
Many matrixed workflows conditionally generate artifacts (i.e. Cypress videos or snapshots). The previous pattern in v3 was to simply upload artifact and set if-no-files-found: ignore. If there's artifacts, great...if not, no problem.
Given that the solution to accomplish the same task in v4 is to use the merge action. There should be a matching param so that in the event all the matrixed tests pass without issue, the merge job doesn't fail.
Solution
This loosely mirrors the functionality from the root action: