-
Notifications
You must be signed in to change notification settings - Fork 695
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
Add if-no-files-found option to merge action #521
base: main
Are you sure you want to change the base?
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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"]
@@ -32,7 +33,28 @@ export async function run(): Promise<void> { | |||
) | |||
|
|||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
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: