Skip to content

Commit

Permalink
Merge pull request #300 from dkhunt27/noGist
Browse files Browse the repository at this point in the history
allowed skipping gist stuff; updated libs to latest
  • Loading branch information
dkhunt27 authored Sep 20, 2023
2 parents c095641 + a492f29 commit 47da7ef
Show file tree
Hide file tree
Showing 19 changed files with 21,039 additions and 20,058 deletions.
4 changes: 3 additions & 1 deletion .github/samples/main-push.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,13 @@ jobs:
if-no-files-found: error

- name: Create Code Coverage Badge
uses: dkhunt27/nx-code-coverage@v0.2.3-beta
uses: dkhunt27/nx-code-coverage@v1
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
no-coverage-ran: false
coverage-folder: ./coverage
coverage-base-folder: ./coverage-base
gist-processing: true
gist-token: ${{ secrets.COVERAGE_BADGES_GIST_TOKEN }}
gist-id: SOME_GIST_ID
color: green
Expand Down
4 changes: 3 additions & 1 deletion .github/samples/pull-request.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,13 @@ jobs:
continue-on-error: true

- name: Comment Code Coverage on PR
uses: dkhunt27/nx-code-coverage@v0.3.0
uses: dkhunt27/nx-code-coverage@v1
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
no-coverage-ran: false
coverage-folder: ./coverage
coverage-base-folder: ./coverage-base
gist-processing: true
gist-token: ${{ secrets.COVERAGE_BADGES_GIST_TOKEN }}
gist-id: SOME_GIST_ID
color: green
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,6 @@ jobs:
no-coverage-ran: false
coverage-folder: ./__tests__/data/coverage
coverage-base-folder: ./__tests__/data/coverage-base
gist-processing: true
gist-token: ${{ secrets.COVERAGE_BADGE_GIST_TOKEN }}
gist-id: e7882d4560f635dce4a889df5e29d209
18 changes: 12 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,24 @@ The report is based on the coverage report generated by your test runner.
description: Github token
no-coverage-ran:
required: true
description: true/false (default false) if no coverage was ran; useful if using nx affected and it returned no projects
description: true/false if no coverage was ran; useful if using nx affected and it returned no projects
type: boolean
coverage-folder:
required: false
description: path to folder containing project folders with coverage data (default 'coverage')
coverage-base-folder:
required: false
description: path to folder containing project folders with coverage data for diff/base comparison (default 'coverage-base')
gist-token:
description: 'Your secret with the gist scope for coverage badge'
gist-processing:
required: true
description: true/false should save results/badge to gist
type: boolean
gist-token:
required: false
description: 'Your secret with the gist scope for coverage badge; required if gist-processing not false'
gist-id:
description: 'The ID of the gist to use'
required: true
required: false
description: 'The ID of the gist to use; required if gist-processing not false'
label-color:
description: 'The left color of the badge'
required: false
Expand Down Expand Up @@ -75,11 +79,13 @@ The report is based on the coverage report generated by your test runner.
```yaml
- name: Comment Code Coverage on PR
uses: dkhunt27/nx-code-coverage@v0.3.0
uses: dkhunt27/nx-code-coverage@v1
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
no-coverage-ran: false
coverage-folder: ./coverage
coverage-base-folder: ./coverage-base
gist-processing: true
gist-token: ${{ secrets.COVERAGE_BADGES_GIST_TOKEN }}
gist-id: d7e6b443a01eba615fd2a7c1215aec91
color: green
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ describe.skip('test-case lib-with-no-coverage', () => {
coverageBaseFolder: 'coverage-base',
token: 'someToken',
githubWorkspace: path.join(__dirname),
gistProcessing: true,
gistToken: 'someGistToken',
gistId: '14be704ddbfb786fbb50a292ee4d75f0'
})
Expand Down
73 changes: 51 additions & 22 deletions __tests__/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,17 @@ import {expect, test} from '@jest/globals'
import {readFileSync, writeFileSync} from 'fs'
import {main} from '../src/main'
import path from 'path'
import * as JsonCoverage from '../src/json-coverage'
import * as Comment from '../src/comment'
import * as Github from '../src/github'
import {JcsMergedType} from '../src/types'

const saveResults = false

describe.skip('main tests', () => {
let outputPath: string
let processCoverageFilesResult: JcsMergedType[]

beforeEach(() => {
outputPath = path.join(__dirname, '../__tests__/data/processed')

Expand All @@ -30,12 +36,24 @@ describe.skip('main tests', () => {
github.context.ref = 'refs/heads/some-ref'
github.context.sha = '1234567890123456789012345678901234567890'

// "pullRequestHeadSha": "296442b005eff46ea5c7fad024d3a8e5c8cda7e3",
// "pullRequestHeadRef": "wip",
// "pullRequestBaseRef": "main",
// "pullRequestNumber": 9,
const filePath = path.join(outputPath, 'processed.json')
processCoverageFilesResult = JSON.parse(readFileSync(filePath).toString())

jest
.spyOn(JsonCoverage, 'processCoverageFiles')
.mockResolvedValue(processCoverageFilesResult)
jest.spyOn(Comment, 'buildComment').mockReturnValue('Code Coverage:<p></p>')
jest.spyOn(Github, 'buildParsedContext').mockReturnValue({
repositoryFullName: 'repoFullName',
pullRequestHeadSha: 'headSha',
pullRequestHeadRef: 'headRef',
pullRequestBaseRef: 'baseRef',
repoOwner: 'repoOwner',
repoRepo: 'repoRepo',
pullRequestNumber: -1
})
})
test('throws invalid number', async () => {
test('full processing as expected', async () => {
const expected = JSON.parse(
readFileSync(path.join(outputPath, 'main.json')).toString()
)
Expand All @@ -46,11 +64,12 @@ describe.skip('main tests', () => {
coverageBaseFolder: './__tests__/data/coverage-base',
token: 'someToken',
githubWorkspace: path.join(__dirname, '..'),
gistProcessing: true,
gistToken: 'someGistToken',
gistId: '14be704ddbfb786fbb50a292ee4d75f0'
gistId: 'someGistId'
})

expect(actual).toStrictEqual(expected)
expect(actual).toStrictEqual(processCoverageFilesResult)

saveResults
? writeFileSync(
Expand All @@ -60,19 +79,29 @@ describe.skip('main tests', () => {
: ''
})

// shows how the runner will run a javascript action with env / stdout protocol
// test('test runs', () => {
// process.env['GITHUB_WORKSPACE'] = '~/nx-code-coverage/'
// const np = process.execPath
// const ip = path.join(__dirname, '..', 'dist', 'index.js')
// const options: cp.ExecFileSyncOptions = {
// env: process.env
// }
// try {
// const result = cp.execFileSync(np, [ip], options).toString()
// console.log(result)
// } catch (err){
// throw err
// }
// })
test('skip gist', async () => {
const expected = JSON.parse(
readFileSync(path.join(outputPath, 'main.json')).toString()
)

const actual = await main({
coverageRan: true,
coverageFolder: './__tests__/data/coverage',
coverageBaseFolder: './__tests__/data/coverage-base',
token: 'someToken',
githubWorkspace: path.join(__dirname, '..'),
gistProcessing: false,
gistToken: 'someGistToken',
gistId: 'someGistId'
})

expect(actual).toStrictEqual(processCoverageFilesResult)

saveResults
? writeFileSync(
path.join(outputPath, 'main.json'),
JSON.stringify(actual, null, 2)
)
: ''
})
})
14 changes: 9 additions & 5 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,24 @@ inputs:
description: Github token
no-coverage-ran:
required: true
description: true/false (default false) if no coverage was ran; useful if using nx affected and it returned no projects
description: true/false if no coverage was ran; useful if using nx affected and it returned no projects
type: boolean
coverage-folder:
required: false
description: path to folder containing project folders with coverage data (default 'coverage')
coverage-base-folder:
required: false
description: path to folder containing project folders with coverage data for diff/base comparison (default 'coverage-base')
gist-token:
description: 'Your secret with the gist scope for coverage badge'
gist-processing:
required: true
description: true/false should save results/badge to gist
type: boolean
gist-token:
required: false
description: 'Your secret with the gist scope for coverage badge; required if gist-processing not false'
gist-id:
description: 'The ID of the gist to use'
required: true
required: false
description: 'The ID of the gist to use; required if gist-processing not false'
label-color:
description: 'The left color of the badge'
required: false
Expand Down
Loading

0 comments on commit 47da7ef

Please sign in to comment.