Skip to content

Commit

Permalink
Merge pull request #56 from dorny/artifacts-support
Browse files Browse the repository at this point in the history
Support public repo PR workflow
  • Loading branch information
dorny authored Feb 20, 2021
2 parents 71f2f95 + 9a38483 commit 603e845
Show file tree
Hide file tree
Showing 24 changed files with 14,873 additions and 3,303 deletions.
15 changes: 11 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
name: 'build-test'
name: 'CI'
on:
pull_request:
paths-ignore: [ 'README.md' ]
paths-ignore: [ '*.md' ]
push:
paths-ignore: [ 'README.md' ]
paths-ignore: [ '*.md' ]
branches:
- main
workflow_dispatch:
Expand All @@ -19,9 +19,16 @@ jobs:
- run: npm run format-check
- run: npm run lint
- run: npm test

- name: Upload test results
uses: actions/upload-artifact@v2
with:
name: test-results
path: __tests__/__results__/*.xml

- name: Create test report
if: success() || failure()
uses: ./
if: success() || failure()
with:
name: JEST Tests
path: __tests__/__results__/*.xml
Expand Down
19 changes: 19 additions & 0 deletions .github/workflows/test-report.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Test Report

on:
workflow_run:
workflows: ['CI']
types:
- completed

jobs:
report:
name: Workflow test
runs-on: ubuntu-latest
steps:
- uses: ./
with:
artifact: test-results
name: Workflow Report
path: '*.xml'
reporter: jest-junit
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Changelog

## v1.1.0
- [Support public repo PR workflow](https://github.com/dorny/test-reporter/pull/56)

# v1.0.0
Supported languages / frameworks:
- .NET / xUnit / NUnit / MSTest
- Dart / test
- Flutter / test
- JavaScript / JEST
72 changes: 64 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ This [Github Action](https://github.com/features/actions) displays test results

✔️ Provides final `conclusion` and counts of `passed`, `failed` and `skipped` tests as output parameters


**How it looks:**
|![](assets/fluent-validation-report.png)|![](assets/provider-error-summary.png)|![](assets/provider-error-details.png)|![](assets/provider-groups.png)|
|:--:|:--:|:--:|:--:|
Expand All @@ -21,15 +20,18 @@ This [Github Action](https://github.com/features/actions) displays test results

For more information see [Supported formats](#supported-formats) section.

**Support is planned for:**
- Java / [JUnit 5](https://junit.org/junit5/)

Do you miss support for your favorite language or framework?
Please create [Issue](https://github.com/dorny/test-reporter/issues/new) or contribute with PR.

## Example

Following setup does not work in workflows triggered by pull request from forked repository.
If that's fine for you, using this action is as simple as:

```yaml
on:
pull_request:
push:
jobs:
build-test:
name: Build & Test
Expand All @@ -44,8 +46,53 @@ jobs:
if: success() || failure() # run this step even if previous step failed
with:
name: JEST Tests # Name of the check run which will be created
path: reports/jest-*.xml # Path to test report
reporter: jest-junit # Format of test report
path: reports/jest-*.xml # Path to test results
reporter: jest-junit # Format of test results
```
## Recommended setup for public repositories
Workflows triggered by pull requests from forked repositories are executed with read-only token and therefore can't create check runs.
To workaround this security restriction it's required to use two separate workflows:
1. `CI` runs in the context of PR head branch with read-only token. It executes the tests and uploads test results as build artifact
2. `Test Report` runs in the context of repository main branch with read/write token. It will download test results and create reports

**PR head branch:** *.github/workflows/ci.yml*
```yaml
name: 'CI'
on:
pull_request:
jobs:
build-test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2 # checkout the repo
- run: npm ci # install packages
- run: npm test # run tests (configured to use jest-junit reporter)
- uses: actions/upload-artifact@v2 # upload test results
if: success() || failure() # run this step even if previous step failed
with:
name: test-results
path: jest-junit.xml
```
**default branch:** *.github/workflows/test-report.yml*
```yaml
name: 'Test Report'
on:
workflow_run:
workflows: ['CI'] # runs after CI workflow
types:
- completed
jobs:
report:
runs-on: ubuntu-latest
steps:
- uses: dorny/test-reporter@v1
with:
artifact: test-results # artifact name
name: JEST Tests # Name of the check run which will be created
path: '*.xml' # Path to test results (inside artifact .zip)
reporter: jest-junit # Format of test results
```

## Usage
Expand All @@ -54,15 +101,24 @@ jobs:
- uses: dorny/test-reporter@v1
with:
# Name or regex of artifact containing test results
# Regular expression must be enclosed in '/'.
# Values from captured groups will replace occurrences of $N in report name.
# Example:
# artifact: /test-results-(.*)/
# name: 'Test report $1'
# -> Artifact 'test-result-ubuntu' would create report 'Test report ubuntu'
artifact: ''
# Name of the Check Run which will be created
name: ''
# Coma separated list of paths to test reports
# Coma separated list of paths to test results
# Supports wildcards via [fast-glob](https://github.com/mrmlnc/fast-glob)
# All matched result files must be of same format
path: ''
# Format of test report. Supported options:
# Format of test results. Supported options:
# dart-json
# dotnet-trx
# flutter-json
Expand Down
10 changes: 5 additions & 5 deletions __tests__/dart-json.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ import * as path from 'path'
import {DartJsonParser} from '../src/parsers/dart-json/dart-json-parser'
import {ParseOptions} from '../src/test-parser'
import {getReport} from '../src/report/get-report'
import {normalizeFilePath} from '../src/utils/file-utils'
import {normalizeFilePath} from '../src/utils/path-utils'

describe('dart-json tests', () => {
it('matches report snapshot', async () => {
const opts: ParseOptions = {
parseErrors: true,
trackedFiles: ['lib/main.dart', 'test/main_test.dart', 'test/second_test.dart'],
workDir: 'C:/Users/Michal/Workspace/dorny/test-check/reports/dart/'
trackedFiles: ['lib/main.dart', 'test/main_test.dart', 'test/second_test.dart']
//workDir: 'C:/Users/Michal/Workspace/dorny/test-check/reports/dart/'
}

const fixturePath = path.join(__dirname, 'fixtures', 'dart-json.json')
Expand All @@ -38,8 +38,8 @@ describe('dart-json tests', () => {
const trackedFiles = fs.readFileSync(trackedFilesPath, {encoding: 'utf8'}).split(/\n\r?/g)
const opts: ParseOptions = {
trackedFiles,
parseErrors: true,
workDir: '/__w/provider/provider/'
parseErrors: true
//workDir: '/__w/provider/provider/'
}

const parser = new DartJsonParser(opts, 'flutter')
Expand Down
9 changes: 4 additions & 5 deletions __tests__/dotnet-trx.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as path from 'path'
import {DotnetTrxParser} from '../src/parsers/dotnet-trx/dotnet-trx-parser'
import {ParseOptions} from '../src/test-parser'
import {getReport} from '../src/report/get-report'
import {normalizeFilePath} from '../src/utils/file-utils'
import {normalizeFilePath} from '../src/utils/path-utils'

describe('dotnet-trx tests', () => {
it('matches report snapshot', async () => {
Expand All @@ -15,8 +15,8 @@ describe('dotnet-trx tests', () => {

const opts: ParseOptions = {
parseErrors: true,
trackedFiles: ['DotnetTests.Unit/Calculator.cs', 'DotnetTests.XUnitTests/CalculatorTests.cs'],
workDir: 'C:/Users/Michal/Workspace/dorny/test-check/reports/dotnet/'
trackedFiles: ['DotnetTests.Unit/Calculator.cs', 'DotnetTests.XUnitTests/CalculatorTests.cs']
//workDir: 'C:/Users/Michal/Workspace/dorny/test-check/reports/dotnet/'
}

const parser = new DotnetTrxParser(opts)
Expand All @@ -36,8 +36,7 @@ describe('dotnet-trx tests', () => {

const opts: ParseOptions = {
trackedFiles: [],
parseErrors: true,
workDir: ''
parseErrors: true
}

const parser = new DotnetTrxParser(opts)
Expand Down
10 changes: 5 additions & 5 deletions __tests__/jest-junit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as path from 'path'
import {JestJunitParser} from '../src/parsers/jest-junit/jest-junit-parser'
import {ParseOptions} from '../src/test-parser'
import {getReport} from '../src/report/get-report'
import {normalizeFilePath} from '../src/utils/file-utils'
import {normalizeFilePath} from '../src/utils/path-utils'

describe('jest-junit tests', () => {
it('report from ./reports/jest test results matches snapshot', async () => {
Expand All @@ -15,8 +15,8 @@ describe('jest-junit tests', () => {

const opts: ParseOptions = {
parseErrors: true,
trackedFiles: ['__tests__/main.test.js', '__tests__/second.test.js', 'lib/main.js'],
workDir: 'C:/Users/Michal/Workspace/dorny/test-check/reports/jest/'
trackedFiles: ['__tests__/main.test.js', '__tests__/second.test.js', 'lib/main.js']
//workDir: 'C:/Users/Michal/Workspace/dorny/test-check/reports/jest/'
}

const parser = new JestJunitParser(opts)
Expand All @@ -38,8 +38,8 @@ describe('jest-junit tests', () => {
const trackedFiles = fs.readFileSync(trackedFilesPath, {encoding: 'utf8'}).split(/\n\r?/g)
const opts: ParseOptions = {
parseErrors: true,
trackedFiles,
workDir: '/home/dorny/dorny/jest/'
trackedFiles
//workDir: '/home/dorny/dorny/jest/'
}

const parser = new JestJunitParser(opts)
Expand Down
7 changes: 5 additions & 2 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,21 @@ description: |
Displays test results directly in GitHub. Supports .NET (xUnit, NUnit, MSTest), Dart, Flutter and JavaScript (JEST).
author: Michal Dorner <dorner.michal@gmail.com>
inputs:
artifact:
description: Name or regex of artifact containing test results
required: false
name:
description: Name of the check run
required: true
path:
description: |
Coma separated list of paths to test reports
Coma separated list of paths to test results
Supports wildcards via [fast-glob](https://github.com/mrmlnc/fast-glob)
All matched result files must be of same format
required: true
reporter:
description: |
Format of test report. Supported options:
Format of test results. Supported options:
- dart-json
- dotnet-trx
- flutter-json
Expand Down
Loading

0 comments on commit 603e845

Please sign in to comment.