stoplightio / spectral-action

GitHub Action wrapper for Spectral - a JSON/YAML/OpenAPI/AsyncAPI/etc linter with custom rule support.
https://stoplight.io/open-source/spectral
Apache License 2.0
85 stars 46 forks source link

github check created after loading ruleset #643

Closed kaylachun closed 2 years ago

kaylachun commented 2 years ago

Motivation and Context

Fix regression of this: https://github.com/stoplightio/spectral-action/issues/506 Github check Lint(push) remains in progress until it times out.

640

Description

Lint(push) would get stuck if there was an error thrown in createSpectral(), more specifically getRuleset(). If there were no rulesets found in the repo, an error was thrown in getRuleset() but that didn't cause the Lint(push) check to fail. Instead the check would hang because it wasn't able to continue to the next step (updateGithubCheck()). I changed the github check to be created after finding and loading a ruleset. If there were any errors thrown in that process, the github check never gets created. If there is a valid ruleset, the check is created and the linting happens as usual. If there is an error thrown while loading the ruleset, the Run Spectral actions fails with the correct error message.

How Has This Been Tested?

I tested this on a private repo and followed the testing steps in #506. I've tested it with no rulesets in the repo, a ruleset that would return an error after linting, and a ruleset that returned a warning after linting. All had expected behaviors of failing/succeeding when supposed to (and never hanging).

Screenshot(s)/recordings(s)

What happens now when an error is thrown while loading the Spectral ruleset:

image

Types of changes

Checklist