-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fail builds based on code coverage (#7)
* add coverage generation commands * use local directory for action * add actions checkout * remove name * update workflow with coverage comparision * comment master branch running * add minimun coverage ration checks * update minimum-coverage-ratio build * use default value as 10
- Loading branch information
1 parent
5e4a18c
commit c51e59d
Showing
7 changed files
with
749 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,80 @@ | ||
on: [pull_request] | ||
name: Code Coverage | ||
|
||
on: | ||
push: | ||
branches: | ||
- master | ||
pull_request: | ||
|
||
jobs: | ||
generate_coverage_job: | ||
base_branch_cov: | ||
runs-on: ubuntu-latest | ||
name: Example of using Code Coverage action | ||
steps: | ||
- name: Generate Code Coverage report | ||
id: code_coverage | ||
uses: barecheck/[email protected] | ||
- uses: actions/checkout@v2 | ||
#TODO: uncommend after merge to master | ||
# with: | ||
# ref: master | ||
- name: Use Node.js 12.13.1 | ||
uses: actions/setup-node@v1 | ||
with: | ||
github-token: ${{ secrets.GITHUB_TOKEN }} | ||
lcov-file: './data/lcov.info' | ||
head-lcov-file: './data/head-lcov.info' | ||
node-version: 12.13.1 | ||
- name: Cache node modules | ||
uses: actions/cache@v1 | ||
with: | ||
path: node_modules | ||
key: node_modules-v1-${{ hashFiles('yarn.lock') }} | ||
# loading an older version is fine here, since it will get an npm install | ||
restore-keys: | | ||
node_modules- | ||
- name: Install dependencies | ||
run: yarn | ||
|
||
- name: Get the output percentage | ||
run: echo "The percentage ${{ steps.code_coverage.outputs.percentage }}" | ||
- name: Run test coverage | ||
run: yarn coverage-lcov | ||
|
||
- name: Get the output diff | ||
run: echo "The percentage diff from head branch ${{ steps.code_coverage.outputs.diff }}" | ||
- name: Upload code coverage for ref branch | ||
uses: actions/upload-artifact@v2 | ||
with: | ||
name: ref-lcov.info | ||
path: ./coverage/lcov.info | ||
|
||
checks: | ||
runs-on: ubuntu-latest | ||
needs: base_branch_cov | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Use Node.js 12.13.1 | ||
uses: actions/setup-node@v1 | ||
with: | ||
node-version: 12.13.1 | ||
- name: Cache node modules | ||
uses: actions/cache@v1 | ||
with: | ||
path: node_modules | ||
key: node_modules-v1-${{ hashFiles('yarn.lock') }} | ||
# loading an older version is fine here, since it will get an npm install | ||
restore-keys: | | ||
node_modules- | ||
- name: Download math result for job 2 | ||
uses: actions/download-artifact@v2 | ||
with: | ||
name: ref-lcov.info | ||
|
||
- name: Install dependencies | ||
run: yarn | ||
|
||
- name: Run test coverage | ||
run: yarn coverage-lcov | ||
|
||
# Testing beta of code coverage checks | ||
# This part can be removed or optimized once barecheck code coverage will be out of beta | ||
- name: Generate Code Coverage report | ||
id: code-coverage | ||
uses: ./ | ||
with: | ||
github-token: ${{ secrets.GITHUB_TOKEN }} | ||
lcov-file: './coverage/lcov.info' | ||
head-lcov-file: './lcov.info' | ||
minimum-coverage-ratio: 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
const core = require('@actions/core'); | ||
|
||
const checkCoverageRation = (coverageDiff) => { | ||
const minCoverageRatio = | ||
parseInt(core.getInput('minimum-coverage-ratio'), 10) || 0; | ||
|
||
const coverageDiffAlert = coverageDiff + minCoverageRatio; | ||
|
||
if (coverageDiffAlert < 0) { | ||
throw new Error(`Your coverage is ${coverageDiffAlert}%`); | ||
} | ||
}; | ||
|
||
module.exports = { | ||
checkCoverageRation | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.