-
-
Notifications
You must be signed in to change notification settings - Fork 124
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
feat: outputs the error messages #194
Conversation
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.
Thanks for looking into this!
I left some comments. As for testing, please follow the contributors guide.
src/validatePrTitle.js
Outdated
`No release type found in pull request title "${prTitle}". Add a prefix to indicate what kind of release this pull request corresponds to. For reference, see https://www.conventionalcommits.org/\n\n${printAvailableTypes()}` | ||
); | ||
errorMessage = `No release type found in pull request title "${prTitle}". Add a prefix to indicate what kind of release this pull request corresponds to. For reference, see https://www.conventionalcommits.org/\n\n${printAvailableTypes()}`; | ||
throw new Error(errorMessage); |
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.
When we throw here, the core.setOutput
statement below is never called. You could introduce a new function that makes sure we always do both:
function raiseError(message) {
core.setOutput('errorMessage', message);
throw new Error(message);
}
… and use that for all validation errors here.
That way you also don't need the variable introduced above.
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.
Oh, good catch, a silly mistake on my part. Will refactor that later.
src/validatePrTitle.js
Outdated
@@ -133,4 +134,6 @@ module.exports = async function validatePrTitle( | |||
); | |||
} | |||
} | |||
|
|||
core.setOutput('error_message', errorMessage); |
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.
Do you have some reasoning on why you picked error_message
? Generally we use camelCase, so in doubt I'd go for that here too. It would also be good to do some research if there is some existing convention from other actions that we could align ourselves to.
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.
Well, I only based my choice on the Conventional Changelog Action, which uses snake_case for the outputs.
https://github.com/TriPSs/conventional-changelog-action
I can look into some more famous examples, but the final decision is yours xD what do you prefer? camelCase?
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 recommend using as it is in docs, upper case and underscore
https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions
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.
Good idea, base it on docs seems like the best option imo
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.
Thanks for the suggestion @derberg!
I just checked the docs and it seems like they're a bit inconsistent with the casing:
- Upper case snake case:
- Lower case snake case:
- https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#example-setting-an-output-parameter
- https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#example-toggling-command-echoing
- https://docs.github.com/en/actions/using-jobs/defining-outputs-for-jobs (no snake case since it's a single word, but lowercase)
- https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#example-using-output-as-url
- Kebab case:
It seems like there's unfortunately not really a standard here. However lower case snake case seems to be the most popular one and also what convitional-changelog-action is using, so I'd vote to go for that.
This is so cool feature that we actually need now 😃 thanks so much!!! |
@amannn Worked!!! 🙏 I refactored to a function that first outputs the error message, then throws the error. The problem is that the workflow stops when it receives an error in one of the steps. But this is easily fixed with an "if: always()" in the next step, so it runs the next step (in my case, the action that comments on the PR). You can see I created a new workflow to test that. I also tested irl on my own repo, with that test I created. And it worked perfectly, the action really commented the error message on my PR (now it's u to the user to decide what action to use for the comment, or whatever it wants to do with the output). Link to the PR on my repo to prove the working PR: juninholiveira#2 If you accept the PR, I can make another PR to add the instructions on the README, if you want. |
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.
@juninholiveira Great job and finalising the implementation and your tests – this looks really good! 👏
If you could include some docs in the README that would be fantastic so other users can take advantage of the feature too. I think a brief section mentioning that there's an output, what it's called and then maybe linking to your example workflow you set up in this repository would be helpful. Maybe you can include a link to what a Github Action output is, for those not familiar with the concept.
Many thanks!
- uses: marocchino/sticky-pull-request-comment@v2 | ||
# When the previous steps fails, the workflow would stop. By adding this | ||
# condition you can continue the execution with the populated error message. | ||
if: always() |
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.
@juninholiveira Have you tested what happens when the validation no longer fails with this step? I guess ideally the comment would be removed. It seems like the action would provide an option for a workflow like this, maybe we can set an argument conditionally based on if there's an error_message
?
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.
@amannn proper setup is:
# Comments the error message from the above lint_pr_title action
- if: always()
name: Comment on PR
uses: marocchino/sticky-pull-request-comment@v2
with:
header: pr-title-lint-error
message: |
Hey there 👋🏼 thanks for opening the PR but we need you to adjust the title of the pull request.
We require all PRs to follow [Conventional Commits specification](https://www.conventionalcommits.org/en/v1.0.0/). More details 👇🏼
```
${{ steps.lint_pr_title.outputs.error_message}}
```
# deletes the error comment if the title is correct
- if: ${{ steps.lint_pr_title.outputs.error_message == null }}
name: delete the comment
uses: marocchino/sticky-pull-request-comment@v2
with:
header: pr-title-lint-error
delete: true
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.
@derberg Thanks a lot for sharing your configuration! That looks really good to me, I've just updated this PR accordingly and will merge once CI is green.
Thank you @juninholiveira for taking the lead with this feature! 👏
@amannn Hey, did you decide to drop the feature or closed it because of inactivity from @juninholiveira ? |
@derberg Strange, I must have closed the PR by accident 🤦♂️. I've just reopened it. There was one comment remaining, other than that the PR would be fine. |
🎉 This PR is included in version 4.6.0 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
Resolves #178
Hello! I'm a new guy here. I took a look at the code and saw that with an easy fix I could "maybe" fix this problem that so many users want: outputs the error messages to other steps/jobs.
You already have @actions/core as a dependency. I just...
I must say: I'm new, not very experienced. I ran the tests and everything passed. But I didn't test in a real workflow. This behaviour is very useful for all users, if you could please take a look in it 🙏