forked from gwatts/go-coverage-action
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 0a5a013
Showing
20 changed files
with
11,933 additions
and
0 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 |
---|---|---|
@@ -0,0 +1 @@ | ||
dist/ |
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 @@ | ||
{ | ||
"env": { | ||
"commonjs": true, | ||
"es6": true, | ||
"node": true | ||
}, | ||
"extends": "eslint:recommended", | ||
"globals": { | ||
"Atomics": "readonly", | ||
"SharedArrayBuffer": "readonly" | ||
}, | ||
"parserOptions": { | ||
"ecmaVersion": 2018 | ||
}, | ||
"rules": {} | ||
} |
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 @@ | ||
dist/** -diff linguist-generated=true |
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,11 @@ | ||
version: 2 | ||
updates: | ||
- package-ecosystem: github-actions | ||
directory: / | ||
schedule: | ||
interval: daily | ||
|
||
- package-ecosystem: npm | ||
directory: / | ||
schedule: | ||
interval: daily |
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,51 @@ | ||
# `dist/index.js` is a special file in Actions. | ||
# When you reference an action with `uses:` in a workflow, | ||
# `index.js` is the code that will run. | ||
# For our project, we generate this file through a build process from other source files. | ||
# We need to make sure the checked-in `index.js` actually matches what we expect it to be. | ||
name: Check dist/ | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
paths-ignore: | ||
- '**.md' | ||
pull_request: | ||
paths-ignore: | ||
- '**.md' | ||
workflow_dispatch: | ||
|
||
jobs: | ||
check-dist: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- name: Set Node.js 16.x | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: 16.x | ||
|
||
- name: Install dependencies | ||
run: npm ci | ||
|
||
- name: Rebuild the dist/ directory | ||
run: npm run prepare | ||
|
||
- name: Compare the expected and actual dist/ directories | ||
run: | | ||
if [ "$(git diff --ignore-space-at-eol dist/ | wc -l)" -gt "0" ]; then | ||
echo "Detected uncommitted changes after build. See status below:" | ||
git diff | ||
exit 1 | ||
fi | ||
id: diff | ||
|
||
# If index.js was different than expected, upload the expected version as an artifact | ||
- uses: actions/upload-artifact@v2 | ||
if: ${{ failure() && steps.diff.conclusion == 'failure' }} | ||
with: | ||
name: dist | ||
path: dist/ |
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,29 @@ | ||
name: "CI" | ||
on: | ||
workflow_dispatch: | ||
pull_request: | ||
push: | ||
branches: | ||
- main | ||
- 'releases/*' | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
with: | ||
fetch-depth: 10 | ||
- uses: actions/setup-go@v2 | ||
with: | ||
go-version: 1.18 | ||
- uses: ./ | ||
id: coverage | ||
with: | ||
working-directory: test-go-module | ||
coverage-threshold: 0 | ||
- if: steps.coverage.outputs.coverage-pct < 40 | ||
uses: actions/github-script@v3 | ||
with: | ||
script: | | ||
core.setFailed('Incorrect coverage-pct: ${{ steps.coverage.outputs.coverage-pct }}') |
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,69 @@ | ||
node_modules/ | ||
|
||
# Editors | ||
.vscode/ | ||
.idea/ | ||
*.iml | ||
*~ | ||
*.sw? | ||
|
||
# Logs | ||
logs | ||
*.log | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
|
||
# Runtime data | ||
pids | ||
*.pid | ||
*.seed | ||
*.pid.lock | ||
|
||
# Directory for instrumented libs generated by jscoverage/JSCover | ||
lib-cov | ||
|
||
# Coverage directory used by tools like istanbul | ||
coverage | ||
|
||
# nyc test coverage | ||
.nyc_output | ||
|
||
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) | ||
.grunt | ||
|
||
# Bower dependency directory (https://bower.io/) | ||
bower_components | ||
|
||
# node-waf configuration | ||
.lock-wscript | ||
|
||
# Compiled binary addons (https://nodejs.org/api/addons.html) | ||
build/Release | ||
|
||
# Other Dependency directories | ||
jspm_packages/ | ||
|
||
# TypeScript v1 declaration files | ||
typings/ | ||
|
||
# Optional npm cache directory | ||
.npm | ||
|
||
# Optional eslint cache | ||
.eslintcache | ||
|
||
# Optional REPL history | ||
.node_repl_history | ||
|
||
# Output of 'npm pack' | ||
*.tgz | ||
|
||
# Yarn Integrity file | ||
.yarn-integrity | ||
|
||
# dotenv environment variables file | ||
.env | ||
|
||
# next.js build output | ||
.next |
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,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2022 Gareth Watts | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
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,64 @@ | ||
# Go Coverage Action | ||
|
||
A Github action for generating Go coverage reports. | ||
|
||
## Overview | ||
|
||
This action will generate Go coverage reports without using any third party services, rendinerg it suitable for use with private repos. | ||
|
||
It stores previous coverage data as git commit notes associated with previous shas, so that they can be compared with changes in open pull requests. | ||
|
||
It's a rough and ready work in progress. | ||
|
||
## Usage | ||
|
||
The action will generate a temporary file containing the html report. It's expected that your workflow will uploaded this report somewhere to make it accessible/viewable, or store it as an artifact. | ||
|
||
e.g. | ||
|
||
```yaml | ||
name: "Go Coverage" | ||
on: | ||
pull_request: | ||
push: | ||
branches: | ||
- main | ||
- 'releases/* | ||
jobs: | ||
coverage: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
with: | ||
fetch-depth: 10 | ||
- uses: gwatts/go-coverage-action@v1 | ||
id: coverage | ||
with: | ||
# Optional coverage threshold; check will fail if coverage is below this number | ||
coverage-threshold: 80 | ||
# A url that the html report will be accessible at, once your workflow uploads it | ||
# used in the pull request comment. | ||
report-url: https://artifacts.example.com/go-coverage/${{ github.sha}}.html | ||
# Github token to give permission to post the comment | ||
# token: ${{ github.token }} | ||
# Directory to execute go test from; defaults to the current directory | ||
# working-directory: ./my-go-files | ||
# Override the report filename | ||
# report-filename: coverage.html | ||
# Additional arguments to pass to go test, must be a JSON array | ||
# test-args: '["-tags", "mytag"]' | ||
|
||
- name: Upload coverage to s3 | ||
# ensure this runs whether the threshold is met, or not using always() | ||
if: always() && steps.coverage.outputs.report-pathname != '' | ||
run: | | ||
aws s3 cp ${{ steps.coverage.outputs.report-pathname }} s3://artifacts.example.com-bucket/go-coverage/${{ github.sha}}.html | ||
``` | ||
## |
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,45 @@ | ||
name: 'Go Coverage' | ||
description: 'Generates Go coverage reports' | ||
inputs: | ||
token: | ||
description: github token | ||
default: ${{ github.token }} | ||
report-url-template: | ||
description: URL of final uploaded report. e.g. https://reports.example.com/{{sha}}/cover.html | ||
required: false | ||
working-directory: | ||
description: 'working directory. defaults to project root' | ||
required: false | ||
default: '' | ||
report-filename: | ||
description: 'filename for the resulting html coverage report' | ||
required: false | ||
default: 'go-coverage.html' | ||
test-args: | ||
description: 'Additional arguments to pass to go test as a JSON array - e.g. ["-tags", "integration"]' | ||
default: '[]' | ||
required: false | ||
coverage-threshold: | ||
description: 'Fail the build if the coverage drops below supplied percentage' | ||
required: false | ||
default: 0 | ||
outputs: | ||
report-pathname: | ||
description: 'The full pathname of the generated coverage report' | ||
gocov-pathanme: | ||
description: 'The full path of the generated raw go.cov file' | ||
coverage-pct: | ||
description: 'The coverage figure for the whole project. e.g "83.4"' | ||
coverage-last-pct: | ||
description: 'The prior coverage percentage' | ||
coverage-last-sha: | ||
description: 'Commit sha prior coverage was recorded at' | ||
coverage-delta: | ||
description: 'Amount coverage has changed' | ||
package-count: | ||
description: 'Number of Go packages scanned' | ||
uncovered-packages: | ||
description: 'Number of Go packages with no test coverage' | ||
runs: | ||
using: 'node16' | ||
main: 'dist/index.js' |
Oops, something went wrong.