diff --git a/README.md b/README.md index 2eaf52a..7357d22 100644 --- a/README.md +++ b/README.md @@ -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 +``` diff --git a/src/main.ts b/src/main.ts index 99e3b59..ad64a1b 100644 --- a/src/main.ts +++ b/src/main.ts @@ -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); } }