Skip to content

Commit

Permalink
ci: add workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
Ma11hewThomas committed Apr 26, 2024
1 parent b907a25 commit 40fd1e2
Show file tree
Hide file tree
Showing 5 changed files with 146 additions and 38 deletions.
12 changes: 12 additions & 0 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: Example

on: [push]

jobs:
testing:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Run CTRF annotations
run: npx github-actions-ctrf ctrf-report.json
83 changes: 48 additions & 35 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,99 +14,112 @@ It means a lot to us and helps us grow this open source library.

- View test results on Github Actions summary
- Several views available, `Test Summary`, `Test Details`, `Failed Tests`, `Flaky Tests`
- Run with a single command `npx github-actions-ctrf report.json`
- Run with a single command `npx github-actions-ctrf your-report.json`
- Detect flaky tests

## Usage

Before using the commands, ensure that your GitHub Actions runner has Node.js installed. If not, here's how you can set up Node.js in your workflow:
Add to your Github Actions workfile file:

```yaml
- name: Setup Node.js
uses: actions/setup-node@v2
with:
node-version: '20'
``` bash
npx github-actions-ctrf path-to-your-ctrf-report.json
```

Before using the commands, ensure that your GitHub Actions runner has Node.js installed.

You'll need a CTRF report generated by your testing framework. [CTRF reporters](https://www.ctrf.io/docs/category/reporters) are available for most testing frameworks and easy to install.

Full example:

``` yaml
name: Example workflow file

on: [push]

jobs:
testing:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Run CTRF annotations
run: npx github-actions-ctrf path-to-your-ctrf-report.json
```
### Generating All Tables
For a all tables, add the following to your workflow YAML:
``` yaml
- name: Publish CTRF Test Summary Results
run: npx github-actions-ctrf path-to-your-ctrf-report.json
```
### Generating Test Summary Table
For a test summary table, add the following to your workflow YAML:
For a test summary table, add the `summary` argument to your workflow yaml:

``` yaml
- name: Publish CTRF Test Summary Results
run: npx github-actions-ctrf summary path/to/your/ctrf-report.json
run: npx github-actions-ctrf summary path-to-your-ctrf-report.json
```

### Generating Detailed Test Table

For a test details table, add the following to your workflow YAML:
For a test details table, add the `tests` argument to your workflow yaml:

``` yaml
- name: Publish CTRF Detailed Test Summary Results
run: npx github-actions-ctrf tests path/to/your/ctrf-report.json
run: npx github-actions-ctrf tests path-to-your-ctrf-report.json
```

### Generating Failed Test Details Table

For a failed test details table, add the following to your workflow yaml:
For a failed test details table, add the `failed` argument to your workflow yaml:

``` yaml
- name: Publish CTRF Failed Test Summary Results
run: npx github-actions-ctrf failed path/to/your/ctrf-report.json
run: npx github-actions-ctrf failed path-to-your-ctrf-report.json
```

### Generating Flaky Test Details Table

For a flaky test details table, add the following to your workflow yaml:
For a flaky test details table, add the `flaky` argument to your workflow yaml:

``` yaml
- name: Publish CTRF Flaky Test Summary Results
run: npx github-actions-ctrf flaky path/to/your/ctrf-report.json
run: npx github-actions-ctrf flaky path-to-your-ctrf-report.json
```

### Generating Fail annotations

``` yaml
- name: Annotate failed tests
run: npx github-actions-ctrf annotate path/to/your/ctrf-report.json
```
### Notes
For test annotations, add the `annotate` argument to your workflow yaml:

You can use multiple summaries in the same job, for example:

``` yaml
- name: Publish CTRF Test Summary Results
run: npx github-actions-ctrf summary path/to/your/ctrf-report.json
- name: Publish CTRF Failed Test Summary Results
run: npx github-actions-ctrf failed path/to/your/ctrf-report.json
- name: Publish CTRF Flaky Test Summary Results
run: npx github-actions-ctrf flaky path/to/your/ctrf-report.json
- name: Publish CTRF Detailed Test Summary Results
run: npx github-actions-ctrf tests path/to/your/ctrf-report.json
- name: Annotate failed tests
run: npx github-actions-ctrf annotate path/to/your/ctrf-report.json
run: npx github-actions-ctrf annotate path-to-your-ctrf-report.json
```

## Components

[Click here](https://github.com/github-actions-ctrf/actions) to see the Actions of this repository for a full example

### Summary

![Project Logo](images/summary.png)
![Summary](images/summary.png)

### Test details

![Project Logo](images/tests.png)
![Tests](images/tests.png)

### Failed details

![Project Logo](images/failed.png)
![Failed](images/failed.png)

### Flaky details

![Project Logo](images/flaky.png)
![Flaky](images/flaky.png)

## What is CTRF?

Expand Down
80 changes: 80 additions & 0 deletions ctrf-report.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
{
"results": {
"tool": {
"name": "jest"
},
"summary": {
"tests": 10,
"passed": 5,
"failed": 2,
"pending": 1,
"skipped": 1,
"other": 1,
"start": 1706644023,
"stop": 1706644048
},
"tests": [
{
"name": "should be able to login",
"status": "passed",
"duration": 1200
},
{
"name": "should display profile information",
"status": "failed",
"duration": 800,
"message": "Assertion Failure: profile mismatch",
"trace": "ProfileTest.js:45"
},
{
"name": "should be able to update profile",
"status": "passed",
"duration": 1200,
"flaky": true,
"retries": 2
},
{
"name": "should be able to logout",
"status": "skipped",
"duration": 0
},
{
"name": "should validate user settings",
"status": "passed",
"duration": 1100
},
{
"name": "should fail to update profile on network failure",
"status": "failed",
"duration": 900,
"message": "Network Timeout",
"trace": "ProfileUpdateTest.js:60"
},
{
"name": "should load user data",
"status": "pending",
"duration": 0
},
{
"name": "should handle session timeouts",
"status": "passed",
"duration": 950,
"flaky": true,
"retries": 1
},
{
"name": "should clean up user session on logout",
"status": "other",
"duration": 1050
},
{
"name": "should allow user to change password",
"status": "passed",
"duration": 1300,
"flaky": true,
"retries": 3
}
]
}
}

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "github-actions-ctrf",
"version": "0.0.16",
"version": "0.0.17",
"description": "",
"main": "index.js",
"scripts": {
Expand Down
7 changes: 5 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ interface Arguments {
}

const argv: Arguments = yargs(hideBin(process.argv))
.command('all <file>', 'Generate all tables from the specified CTRF file', (yargs) => {
.command(['$0 <file>', 'all <file>'], 'Generate all tables from the specified CTRF file', (yargs) => {
return yargs.positional('file', {
describe: 'Path to the CTRF file',
type: 'string',
Expand Down Expand Up @@ -52,8 +52,11 @@ const argv: Arguments = yargs(hideBin(process.argv))
.help()
.alias('help', 'h')
.parseSync();
// Extract the command used or default to an empty string if none provided
const commandUsed = argv._[0] || '';

if (argv._.includes('all') && argv.file) {
// Check if the command is 'all' or no specific command was given
if ((commandUsed === 'all' || commandUsed === '') && argv.file) {
try {
const data = fs.readFileSync(argv.file, 'utf8');
const report = validateCtrfFile(argv.file)
Expand Down

0 comments on commit 40fd1e2

Please sign in to comment.