Skip to content

Commit 0a5a013

Browse files
committed
Initial commit
0 parents  commit 0a5a013

20 files changed

+11933
-0
lines changed

.eslintignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
dist/

.eslintrc.json

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"env": {
3+
"commonjs": true,
4+
"es6": true,
5+
"node": true
6+
},
7+
"extends": "eslint:recommended",
8+
"globals": {
9+
"Atomics": "readonly",
10+
"SharedArrayBuffer": "readonly"
11+
},
12+
"parserOptions": {
13+
"ecmaVersion": 2018
14+
},
15+
"rules": {}
16+
}

.gitattributes

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
dist/** -diff linguist-generated=true

.github/dependabot.yml

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: github-actions
4+
directory: /
5+
schedule:
6+
interval: daily
7+
8+
- package-ecosystem: npm
9+
directory: /
10+
schedule:
11+
interval: daily

.github/workflows/check-dist.yml

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# `dist/index.js` is a special file in Actions.
2+
# When you reference an action with `uses:` in a workflow,
3+
# `index.js` is the code that will run.
4+
# For our project, we generate this file through a build process from other source files.
5+
# We need to make sure the checked-in `index.js` actually matches what we expect it to be.
6+
name: Check dist/
7+
8+
on:
9+
push:
10+
branches:
11+
- main
12+
paths-ignore:
13+
- '**.md'
14+
pull_request:
15+
paths-ignore:
16+
- '**.md'
17+
workflow_dispatch:
18+
19+
jobs:
20+
check-dist:
21+
runs-on: ubuntu-latest
22+
23+
steps:
24+
- uses: actions/checkout@v3
25+
26+
- name: Set Node.js 16.x
27+
uses: actions/setup-node@v3
28+
with:
29+
node-version: 16.x
30+
31+
- name: Install dependencies
32+
run: npm ci
33+
34+
- name: Rebuild the dist/ directory
35+
run: npm run prepare
36+
37+
- name: Compare the expected and actual dist/ directories
38+
run: |
39+
if [ "$(git diff --ignore-space-at-eol dist/ | wc -l)" -gt "0" ]; then
40+
echo "Detected uncommitted changes after build. See status below:"
41+
git diff
42+
exit 1
43+
fi
44+
id: diff
45+
46+
# If index.js was different than expected, upload the expected version as an artifact
47+
- uses: actions/upload-artifact@v2
48+
if: ${{ failure() && steps.diff.conclusion == 'failure' }}
49+
with:
50+
name: dist
51+
path: dist/

.github/workflows/ci.yml

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: "CI"
2+
on:
3+
workflow_dispatch:
4+
pull_request:
5+
push:
6+
branches:
7+
- main
8+
- 'releases/*'
9+
10+
jobs:
11+
test:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v3
15+
with:
16+
fetch-depth: 10
17+
- uses: actions/setup-go@v2
18+
with:
19+
go-version: 1.18
20+
- uses: ./
21+
id: coverage
22+
with:
23+
working-directory: test-go-module
24+
coverage-threshold: 0
25+
- if: steps.coverage.outputs.coverage-pct < 40
26+
uses: actions/github-script@v3
27+
with:
28+
script: |
29+
core.setFailed('Incorrect coverage-pct: ${{ steps.coverage.outputs.coverage-pct }}')

.gitignore

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
node_modules/
2+
3+
# Editors
4+
.vscode/
5+
.idea/
6+
*.iml
7+
*~
8+
*.sw?
9+
10+
# Logs
11+
logs
12+
*.log
13+
npm-debug.log*
14+
yarn-debug.log*
15+
yarn-error.log*
16+
17+
# Runtime data
18+
pids
19+
*.pid
20+
*.seed
21+
*.pid.lock
22+
23+
# Directory for instrumented libs generated by jscoverage/JSCover
24+
lib-cov
25+
26+
# Coverage directory used by tools like istanbul
27+
coverage
28+
29+
# nyc test coverage
30+
.nyc_output
31+
32+
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
33+
.grunt
34+
35+
# Bower dependency directory (https://bower.io/)
36+
bower_components
37+
38+
# node-waf configuration
39+
.lock-wscript
40+
41+
# Compiled binary addons (https://nodejs.org/api/addons.html)
42+
build/Release
43+
44+
# Other Dependency directories
45+
jspm_packages/
46+
47+
# TypeScript v1 declaration files
48+
typings/
49+
50+
# Optional npm cache directory
51+
.npm
52+
53+
# Optional eslint cache
54+
.eslintcache
55+
56+
# Optional REPL history
57+
.node_repl_history
58+
59+
# Output of 'npm pack'
60+
*.tgz
61+
62+
# Yarn Integrity file
63+
.yarn-integrity
64+
65+
# dotenv environment variables file
66+
.env
67+
68+
# next.js build output
69+
.next

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2022 Gareth Watts
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# Go Coverage Action
2+
3+
A Github action for generating Go coverage reports.
4+
5+
## Overview
6+
7+
This action will generate Go coverage reports without using any third party services, rendinerg it suitable for use with private repos.
8+
9+
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.
10+
11+
It's a rough and ready work in progress.
12+
13+
## Usage
14+
15+
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.
16+
17+
e.g.
18+
19+
```yaml
20+
name: "Go Coverage"
21+
on:
22+
pull_request:
23+
push:
24+
branches:
25+
- main
26+
- 'releases/*
27+
28+
jobs:
29+
coverage:
30+
runs-on: ubuntu-latest
31+
steps:
32+
- uses: actions/checkout@v3
33+
with:
34+
fetch-depth: 10
35+
- uses: gwatts/go-coverage-action@v1
36+
id: coverage
37+
with:
38+
# Optional coverage threshold; check will fail if coverage is below this number
39+
coverage-threshold: 80
40+
41+
# A url that the html report will be accessible at, once your workflow uploads it
42+
# used in the pull request comment.
43+
report-url: https://artifacts.example.com/go-coverage/${{ github.sha}}.html
44+
45+
# Github token to give permission to post the comment
46+
# token: ${{ github.token }}
47+
48+
# Directory to execute go test from; defaults to the current directory
49+
# working-directory: ./my-go-files
50+
51+
# Override the report filename
52+
# report-filename: coverage.html
53+
54+
# Additional arguments to pass to go test, must be a JSON array
55+
# test-args: '["-tags", "mytag"]'
56+
57+
- name: Upload coverage to s3
58+
# ensure this runs whether the threshold is met, or not using always()
59+
if: always() && steps.coverage.outputs.report-pathname != ''
60+
run: |
61+
aws s3 cp ${{ steps.coverage.outputs.report-pathname }} s3://artifacts.example.com-bucket/go-coverage/${{ github.sha}}.html
62+
```
63+
64+
##

action.yml

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
name: 'Go Coverage'
2+
description: 'Generates Go coverage reports'
3+
inputs:
4+
token:
5+
description: github token
6+
default: ${{ github.token }}
7+
report-url-template:
8+
description: URL of final uploaded report. e.g. https://reports.example.com/{{sha}}/cover.html
9+
required: false
10+
working-directory:
11+
description: 'working directory. defaults to project root'
12+
required: false
13+
default: ''
14+
report-filename:
15+
description: 'filename for the resulting html coverage report'
16+
required: false
17+
default: 'go-coverage.html'
18+
test-args:
19+
description: 'Additional arguments to pass to go test as a JSON array - e.g. ["-tags", "integration"]'
20+
default: '[]'
21+
required: false
22+
coverage-threshold:
23+
description: 'Fail the build if the coverage drops below supplied percentage'
24+
required: false
25+
default: 0
26+
outputs:
27+
report-pathname:
28+
description: 'The full pathname of the generated coverage report'
29+
gocov-pathanme:
30+
description: 'The full path of the generated raw go.cov file'
31+
coverage-pct:
32+
description: 'The coverage figure for the whole project. e.g "83.4"'
33+
coverage-last-pct:
34+
description: 'The prior coverage percentage'
35+
coverage-last-sha:
36+
description: 'Commit sha prior coverage was recorded at'
37+
coverage-delta:
38+
description: 'Amount coverage has changed'
39+
package-count:
40+
description: 'Number of Go packages scanned'
41+
uncovered-packages:
42+
description: 'Number of Go packages with no test coverage'
43+
runs:
44+
using: 'node16'
45+
main: 'dist/index.js'

0 commit comments

Comments
 (0)