asyncapi / github-action-for-cli

GitHub Action with generator, validator, converter and others - all in one for your AsyncAPI documents with AsyncAPI CLI as backbone
Apache License 2.0
50 stars 19 forks source link

mark the job as failed when errors are found in asyncapi spec when validating #400

Closed luisvillalobossalgado1987 closed 3 months ago

luisvillalobossalgado1987 commented 4 months ago

Why do we need this improvement?

I want to break the pipeline flow so that developers are forced to fix the asyncapi specification

How will this change help?

This would cause the complete execution of the pipeline or workflow to be marked as failed and therefore the following steps or jobs would not be executed.

Screenshots

The image shows that during validation 1 error was found:

/github/workspace/bx-poc-prdr-asyncapi-validation/aas/aas.yaml
   73:25 error asyncapi-document-resolved "receivePaginatedOrder" property must have required property "action" operations.receivePaginatedOrder

  ✖ 1 problem (1 error, 0 warnings, 0 infos, 0 hints)

However, the step or job is marked as successful.

image

How could it be implemented/designed?

It could be implemented depending on the output.

🚧 Breaking changes

Yes

👀 Have you checked for similar open issues?

🏢 Have you read the Contributing Guidelines?

Are you willing to work on this issue?

None

github-actions[bot] commented 4 months ago

Welcome to AsyncAPI. Thanks a lot for reporting your first issue. Please check out our contributors guide and the instructions about a basic recommended setup useful for opening a pull request.
Keep in mind there are also other channels you can use to interact with AsyncAPI community. For more details check out this issue.

luisvillalobossalgado1987 commented 4 months ago

I think something like this could work:

handle_validate() {
  echo -e "${BLUE}Validating AsyncAPI file...${NC}"
  echo "::group::Debug information"

  if [ ! -f "$FILEPATH" ]; then 
    handle_file_error "$FILEPATH"
    exit 1
  fi

  echo -e "${BLUE}Executing command:${NC}" "asyncapi validate $FILEPATH $PARAMETERS"
  eval "asyncapi validate $FILEPATH $PARAMETERS"

  # Fix: Check exit code after validation
  if [ $? -ne 0 ]; then
    echo "::endgroup::" # Close the debug group before exiting
    echo "Validation failed."
    exit 1
  fi

  echo "::endgroup::"
}
Shurtu-gal commented 4 months ago

Great suggestion @luisvillalobossalgado1987 do you wish to work on this issue ?

GarvitSinghal47 commented 4 months ago

@Shurtu-gal I would like to work on this ,if it is up for contribution

Shurtu-gal commented 4 months ago

@Shurtu-gal I would like to work on this ,if it is up for contribution

Sure, you can do so.

Shurtu-gal commented 3 months ago

@Shurtu-gal I would like to work on this ,if it is up for contribution

Do you need any help regarding this ?

Shurtu-gal commented 3 months ago

I think the change is simple, but I'm not sure how to test it. And since the issue is still open, I understand that a new version has not been released with this. How can I help move forward?

You can implement the change and add a test case in the github workflow which tests it failing. Please let me know if you need any help.

luisvillalobossalgado1987 commented 3 months ago

Version 3.1.2 has already implemented the requested feature. My apologies for not noticing it earlier. Please close the issue.

Shurtu-gal commented 3 months ago

Sure.