I am trying to build a GitHub workflow that performs simple pre-commit checks whenever a PR is created into a certain repository and triggers a message if some check has failed. The problem is that I want that message to be as specific as possible and, therefore, the message has to contain the error that is preventing the check to succeed. To perform the pre-commit check I am using pre-commit action and, to automate the messages, I am using the official actions github-script.
Since I am utilizing the pre-commit action to perform the checks, I think I am not able to use the set-output solution to define the outputs of the step that is validating for the errors and reference those outputs later in my error message. Is there any other way to workaround this problem?
Here is an excerpt of my workflow pipeline:
jobs:
pre-commit:
steps:
- name: Check for changed files
id: file_changes
uses: trilom/file-changes-action@v1.2.3
with:
output: ' '
- name: Set up pre-commit cache
id: commit_check
uses: pre-commit/action@v2.0.0
with:
extra_args: --files ${{steps.file_changes.outputs.files}}
- name: PR comment
if: failure()
uses: actions/github-script@v3
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
github.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: ' Ups, something went wrong. Please checkout the following error: '
});
It is not possible using the provided action. Unless there is some kind of command line argument you can pass to pre-commit to write the error to a file and then pass it around. I went through the doc but didn't find any.
If you really need this, you will have to write your own action.