Skip to content
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

add summary as an action output #22

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

jannon
Copy link

@jannon jannon commented Aug 19, 2020

Purpose

This PR adds the string obtained from testSummary.toFormattedMessage() as an action out named "summary".

Additionally, it adds a test for the new output parameter and sets up the framework for additional tests providing coverage of the actual action logic.

Implementation

The changes are implemented in two parts: the declaration of the output parameter and the workflow command actually setting the output parameter

Declaration

The declaration of the output parameter in the action.yml file is optional as described in the Github metadata syntax documentation. It is good practice and communicates clearly what outputs are provided to consumers of the action

...
outputs:
  summary:
    description: "The test run summary"
...

Workflow Command

The output parameter is actually set by the one line addition to index.js:

core.setOutput("summary", testSummary.toFormattedMessage());

This uses the Github toolkit to execute a workflow command to set the output parameter as described in the Github workflow commands reference documentation.

Example

This would allow a user to, for instance, take the summary output from the action and use it in a slack notification action later in the workflow

...
jobs:
  job1:
    runs-on: ubuntu-latest
    steps:
      - name: Run Tests
        uses: actions/checkout@v2
      - name: Parse Report
        id: report
        uses: ashley-taylor/junit-report-annotations-action@v1
        with:
          name: "unit tests"
          access-token: ${{ secrets.GITHUB_TOKEN }}
          path: "**/TEST-*.xml"
      - name: Notify Slack
        uses: 8398a7/action-slack@v3
        with:
          status: custom
          fields: workflow,job,commit,repo,ref,author,took
          custom_payload: |
          {
            username: 'action-slack',
            icon_emoji: ':octocat:',
            attachments: [{
              color: '${{ job.status }}' === 'success' ? 'good' : '${{ job.status }}' === 'failure' ? 'danger' : 'warning',
              text: '${{ steps.report.outputs.summary }}'
          }]
        }
      env:
        GITHUB_TOKEN: ${{ github.token }}
        SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
...

The above example of an imaginary workflow job contains three steps:

  1. Run Tests wherein (we pretend) the developer's code is checked out and tests are run
  2. Parse Report, which is given the id report for later reference, uses this action to read the test results, annotate the job, and output a summary
  3. Notify Slack which sends a slack notification, the content of which is the summary provided by the previous step.
text: '${{ steps.report.outputs.summary }}'

It will be something like:

Screen Shot 2020-08-27 at 1 52 44 PM

index.test.js Outdated
const ip = path.join(__dirname, 'index.js');
cp.exec(`node ${ip}`, {env: process.env}, (error, stdout, stderr) => {
try {
console.log(`STDOUT: ${stdout}`);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you need to log the stdout here ? In case of failure, the assertion should already give a helpful message to identify the root cause.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, that was just an oversight. Will correct.

@TurpIF
Copy link
Contributor

TurpIF commented Aug 19, 2020

Hello and thank you for this contribution

The CI does not work on PR coming from fork. To see the visual result of your PR, do you mind activating the GitHub Action on your fork repository (you need to go in the Action tab if I remember well). So we might be able to see visually what this is providing.

@jannon jannon force-pushed the feature-add-summary-output branch from 47407ed to ab495f1 Compare August 21, 2020 00:21
@jannon
Copy link
Author

jannon commented Aug 21, 2020

I've removed the errant debug statement and enabled actions/workflows on the repo:
https://github.com/Tellagami-Labs/junit-report-annotations-action/actions

@TurpIF
Copy link
Contributor

TurpIF commented Aug 21, 2020

Thank you fo the updates. Although, could you provide a link or a screenshot of the new feature. I'm really sorry but I didn't find it in your actions.

@jannon
Copy link
Author

jannon commented Aug 21, 2020

Sorry, I was in a hurry before and didn't give the original PR description my usual level of attention. I have updated it to hopefully provide a better sense of the change. There is no visible change, per se. It just uses the github mechanisms to provide an output variable containing the test results summary that can be used by a workflow author in other steps in their workflow

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants