Add action output for using the error message

This commit is contained in:
Orhun Parmaksız 2024-03-16 21:13:47 +03:00
parent 48f4ef7da6
commit e14ddc395d
No known key found for this signature in database
GPG key ID: F83424824B3E4B90
2 changed files with 51 additions and 1 deletions

View file

@ -182,3 +182,51 @@ as both runs will use separate caches, but providing the shared key will lead to
with:
prefix-key: v1
```
## Using the error message as output
In case the semver check fails, this action will populate the `error_message` output.
[An output can be used in other steps](https://docs.github.com/en/actions/using-jobs/defining-outputs-for-jobs), for example to comment the error message onto the pull request.
```yml
name: "Check PR"
on:
pull_request_target:
types:
- opened
- edited
- synchronize
jobs:
main:
name: Check semver
runs-on: ubuntu-latest
steps:
- name: Run cargo-semver-checks
id: check_semver
uses: obi1kenobi/cargo-semver-checks-action@v2
- 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()
with:
header: pr-semver-check-error
message: |
Thank you for opening this pull request!
There seems to be semver incompatibility issues reported by [cargo-semver-checks](https://github.com/obi1kenobi/cargo-semver-checks).
Details:
> ${{ steps.check_semver.outputs.error_message }}
# Delete a previous comment when the issue has been resolved
- if: ${{ steps.check_semver.outputs.error_message == null }}
uses: marocchino/sticky-pull-request-comment@v2
with:
header: pr-semver-check-error
delete: true
```

View file

@ -168,7 +168,9 @@ async function main() {
try {
await run();
} catch (error) {
core.setFailed(getErrorMessage(error));
const error_message = getErrorMessage(error);
core.setOutput("error_message", error_message);
core.setFailed(error_message);
}
}