Skip to content

Commit

Permalink
feat: support cucumber report message format (#53)
Browse files Browse the repository at this point in the history
  • Loading branch information
deblockt authored Mar 21, 2024
1 parent be7bcca commit 269d53a
Show file tree
Hide file tree
Showing 11 changed files with 3,480 additions and 832 deletions.
45 changes: 24 additions & 21 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ jobs:

ubuntu-action-tests:
runs-on: ubuntu-latest
strategy:
matrix:
extension: ["json", "ndjson"]
steps:
- uses: actions/checkout@v3
- run: npm ci
Expand All @@ -32,83 +35,83 @@ jobs:
- uses: ./
name: "fail because of error"
with:
name: "failed cucumber report"
name: "${{ matrix.extension }}: failed cucumber report"
access-token: ${{ secrets.GITHUB_TOKEN }}
path: "**/cucumber-report.json"
path: "**/cucumber-report.${{ matrix.extension }}"
- uses: ./
name: "fail because of error (without number of error)"
with:
name: "failed (no number of error)"
name: "${{ matrix.extension }}: failed (no number of error)"
access-token: ${{ secrets.GITHUB_TOKEN }}
path: "**/cucumber-report.json"
path: "**/cucumber-report.${{ matrix.extension }}"
show-number-of-error-on-check-title: false
- uses: ./
name: "fail because of error with all annotation"
with:
name: "failed with all annotation"
name: "${{ matrix.extension }}: failed with all annotation"
access-token: ${{ secrets.GITHUB_TOKEN }}
path: "**/cucumber-report.json"
path: "**/cucumber-report.${{ matrix.extension }}"
show-number-of-error-on-check-title: false
annotation-status-on-undefined: notice
annotation-status-on-pending: notice
- uses: ./
name: "fail because of undefined test"
with:
name: "failed because of undefined test"
name: "${{ matrix.extension }}: failed because of undefined test"
access-token: ${{ secrets.GITHUB_TOKEN }}
path: "**/cucumber-report-non-failed.json"
path: "**/cucumber-report-non-failed.${{ matrix.extension }}"
check-status-on-undefined: "failure"
annotation-status-on-undefined: "failure"
- uses: ./
name: "fail because of pending test"
with:
name: "failed because of pending test"
name: "${{ matrix.extension }}: failed because of pending test"
access-token: ${{ secrets.GITHUB_TOKEN }}
path: "**/cucumber-report-non-failed.json"
path: "**/cucumber-report-non-failed.${{ matrix.extension }}"
check-status-on-pending: "failure"
annotation-status-on-pending: "failure"
- uses: ./
name: "neutral because of error"
with:
name: "neutral cucumber report"
name: "${{ matrix.extension }}: neutral cucumber report"
access-token: ${{ secrets.GITHUB_TOKEN }}
path: "**/cucumber-report.json"
path: "**/cucumber-report.${{ matrix.extension }}"
check-status-on-error: 'neutral'
annotation-status-on-error: 'warning'
- uses: ./
name: "sucess because all is ok"
with:
name: "success cucumber report"
name: "${{ matrix.extension }}: success cucumber report"
access-token: ${{ secrets.GITHUB_TOKEN }}
path: "**/cucumber-report-ok.json"
path: "**/cucumber-report-ok.${{ matrix.extension }}"
check-status-on-error: 'neutral'
annotation-status-on-error: 'warning'
- uses: ./
id: success-with-empty-cucumber-report
name: "success with empty cucumber report"
with:
name: "success empty report"
name: "${{ matrix.extension }}: success empty report"
access-token: ${{ secrets.GITHUB_TOKEN }}
path: "**/cucumber-report-empty.json"
path: "**/cucumber-report-empty.${{ matrix.extension }}"
- uses: ./
name: "job with summary"
with:
name: "job with summary"
name: "${{ matrix.extension }}: job with summary"
access-token: ${{ secrets.GITHUB_TOKEN }}
path: "**/cucumber-report.json"
path: "**/cucumber-report.${{ matrix.extension }}"
show-global-summary-report: 'true'
- id: check-output
name: "check output for cucumber-report-empty.json"
name: "check output for cucumber-report-empty"
if: steps.success-with-empty-cucumber-report.output.cucumber-report-empty_failed_scenarios != 0
run: exit 1
- uses: ./
id: job-failed
continue-on-error: true
name: "fail job due to failed test"
with:
name: "fail job due to failed test"
name: "${{ matrix.extension }}: fail job due to failed test"
access-token: ${{ secrets.GITHUB_TOKEN }}
path: "**/cucumber-report-non-failed.json"
path: "**/cucumber-report-non-failed.${{ matrix.extension }}"
check-status-on-pending: "failure"
annotation-status-on-pending: "failure"
number-of-test-error-to-fail-job: 1
Expand Down
65 changes: 36 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# cucumber-report-annotations-action
# Cucumber Report Annotations Action

This action should be used to publish action annotations from cucumber json report.
This GitHub Action is designed to publish action annotations from Cucumber reports.

## Exemple
## Example

``` yml
```yaml
- uses: deblockt/[email protected]
with:
access-token: ${{ secrets.GITHUB_TOKEN }}
Expand All @@ -13,29 +13,36 @@ This action should be used to publish action annotations from cucumber json repo
![demo](doc/demo.png)
## parameters
- **access-token**: mandatory parameter. It's the github token to allow action to add check
- **name** (optional, default: Cucumber report): the check name.
- **path** (optional, default: **/cucumber-report.json): the glob path to get cucumber report on json format
- **check-status-on-error** (optional, default: failure): the check status to use on cucumber error. Can be 'neutral' or 'failure'
- **check-status-on-undefined** (optional, default: success): the check status to use on cucumber undefined steps. Can be 'success', 'neutral' or 'failure'
- **check-status-on-pending** (optional, default: success): the check status to use on cucumber pending steps. Can be 'success', 'neutral' or 'failure'
- **annotation-status-on-error** (optional, default: failure): the annotation status on error. Can be 'notice', 'warning', 'failure'
- **annotation-status-on-undefined** (optional): the annotation status on undefined steps. Can be 'notice', 'warning', 'failure'. if this property is not set, no annotation will be generated for undefined steps
- **annotation-status-on-pending** (optional): the annotation status on pending steps. Can be 'notice', 'warning', 'failure'. if this property is not set, no annotation will be generated for pending steps
- **number-of-test-error-to-fail-job** (optional): indicate the number of test in error to fail the build. If the value is -1 this action will never fail the build. By default, this action will not cause the build to fail.
- **show-global-summary-report** (optional): if it is set to true, a full summary report will be display for each feature file.
## outputs
the following variable are availables as output (where output name if the json file name with ' ' replaced by '_' and wihout '.json'):
- `${output}_failed_scenarios`: number of failed scenario
- `${output}_undefined_scenarios`: number of undefined scenario
- `${output}_pending_scenarios`: number of pending scenario
- `${output}_passed_scenarios`: number of passed scenario
- `${output}_failed_steps`: number of failed steps
- `${output}_undefined_steps`: number of undefined steps
- `${output}_pending_steps`: number of pending steps
- `${output}_passed_steps`: number of passed steps
## Supported Formats
This GitHub Action supports two formats:
- JSON: The deprecated Cucumber report format. Prefer using the message format. If you use this format, the file extension should be `.json`.
- Message: The new Cucumber report format using NDJSON (newline-delimited JSON) format. If you use this format, the file extension should be `.ndjson`.

## Parameters

- **access-token**: Mandatory parameter. It's the GitHub token to allow the action to add checks.
- **name** (optional, default: Cucumber report): The check name.
- **path** (optional, default: **/cucumber-report.json): The glob path to get the Cucumber report in JSON format.
- **check-status-on-error** (optional, default: failure): The check status to use on Cucumber error. Can be 'neutral' or 'failure'.
- **check-status-on-undefined** (optional, default: success): The check status to use on undefined steps. Can be 'success', 'neutral', or 'failure'.
- **check-status-on-pending** (optional, default: success): The check status to use on pending steps. Can be 'success', 'neutral', or 'failure'.
- **annotation-status-on-error** (optional, default: failure): The annotation status on error. Can be 'notice', 'warning', or 'failure'.
- **annotation-status-on-undefined** (optional): The annotation status on undefined steps. Can be 'notice', 'warning', or 'failure'. If this property is not set, no annotation will be generated for undefined steps.
- **annotation-status-on-pending** (optional): The annotation status on pending steps. Can be 'notice', 'warning', or 'failure'. If this property is not set, no annotation will be generated for pending steps.
- **number-of-test-error-to-fail-job** (optional): Indicates the number of tests in error to fail the build. If the value is -1, this action will never fail the build. By default, this action will not cause the build to fail.
- **show-global-summary-report** (optional): If set to true, a full summary report will be displayed for each feature file.

## Outputs

The following variables are available as output (where the output name is the JSON file name with spaces replaced by underscores and without the '.json' extension):

- `${output}_failed_scenarios`: Number of failed scenarios.
- `${output}_undefined_scenarios`: Number of undefined scenarios.
- `${output}_pending_scenarios`: Number of pending scenarios.
- `${output}_passed_scenarios`: Number of passed scenarios.
- `${output}_failed_steps`: Number of failed steps.
- `${output}_undefined_steps`: Number of undefined steps.
- `${output}_pending_steps`: Number of pending steps.
- `${output}_passed_steps`: Number of passed steps.
7 changes: 7 additions & 0 deletions cucumber/js/features/test.feature
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,10 @@ Feature: Test file
@NonFailedTest
Scenario: Scenario with pending step
When this step is pending

Check notice on line 21 in cucumber/js/features/test.feature

View workflow job for this annotation

GitHub Actions / ndjson: failed with all annotation

Scenario with pending step Pending.

Scenario: Scenario with pending step Step: this step is pending Error: undefined

Check failure on line 21 in cucumber/js/features/test.feature

View workflow job for this annotation

GitHub Actions / ndjson: failed because of pending test

Scenario with pending step Pending.

Scenario: Scenario with pending step Step: this step is pending Error: undefined

Check notice on line 21 in cucumber/js/features/test.feature

View workflow job for this annotation

GitHub Actions / json: failed with all annotation

Scenario with pending step Pending.

Scenario: Scenario with pending step Step: this step is pending Error: undefined

Check failure on line 21 in cucumber/js/features/test.feature

View workflow job for this annotation

GitHub Actions / json: failed because of pending test

Scenario with pending step Pending.

Scenario: Scenario with pending step Step: this step is pending Error: undefined

Check failure on line 21 in cucumber/js/features/test.feature

View workflow job for this annotation

GitHub Actions / ndjson: fail job due to failed test

Scenario with pending step Pending.

Scenario: Scenario with pending step Step: this step is pending Error: undefined

Check failure on line 21 in cucumber/js/features/test.feature

View workflow job for this annotation

GitHub Actions / json: fail job due to failed test

Scenario with pending step Pending.

Scenario: Scenario with pending step Step: this step is pending Error: undefined

Scenario Outline: Scenario with Outline
Given this step will success using example <variable>

Check notice on line 24 in cucumber/js/features/test.feature

View workflow job for this annotation

GitHub Actions / ndjson: failed with all annotation

Scenario with Outline Undefined.

Scenario: Scenario with Outline Step: this step will success using example tets Error: undefined

Check notice on line 24 in cucumber/js/features/test.feature

View workflow job for this annotation

GitHub Actions / ndjson: failed with all annotation

Scenario with Outline Undefined.

Scenario: Scenario with Outline Step: this step will success using example test2 Error: undefined

Check notice on line 24 in cucumber/js/features/test.feature

View workflow job for this annotation

GitHub Actions / json: failed with all annotation

Scenario with Outline Undefined.

Scenario: Scenario with Outline Step: this step will success using example tets Error: undefined

Check notice on line 24 in cucumber/js/features/test.feature

View workflow job for this annotation

GitHub Actions / json: failed with all annotation

Scenario with Outline Undefined.

Scenario: Scenario with Outline Step: this step will success using example test2 Error: undefined
Examples:
| variable |
| tets |
| test2 |
5 changes: 4 additions & 1 deletion cucumber/js/step-definitions/stepdefs.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const assert = require('assert');
const { Given, When, Then } = require('cucumber');
const { Given, When, Then } = require('@cucumber/cucumber');

When('this step will fail', function () {
assert.fail('this step allways fail')
Expand All @@ -10,4 +10,7 @@ When('this step will success', function () {

When('this step is pending', function() {
return 'pending';
})

When('this step will success using example {string}', function() {
})
Loading

0 comments on commit 269d53a

Please sign in to comment.