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

Add if-no-files-found option to merge action #521

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

comp615
Copy link

@comp615 comp615 commented Feb 13, 2024

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:

  • It uses an input of the same name for consistency
  • IMPORTANT: It uses error as the default (instead of warn as in the root action) to prevent breaking changes...however, I would love to change the default to warn for consistency...input welcome
  • It factors out a reused constant...in theory some input/error parsing could be shared too, but it might be just distinct enough to not matter
  • Added tests to merge to exercise the behavior
  • Updated all documentation (I think?)

@comp615 comp615 requested a review from a team as a code owner February 13, 2024 17:19
DanTup added a commit to Dart-Code/Dart-Code that referenced this pull request Feb 22, 2024
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.
Copy link

@roehrijn roehrijn left a 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 [email protected], 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:
Copy link

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) {
Copy link

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.

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.

[feat req] Merge action should support if-no-files-found
2 participants