-
-
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
Showing
12 changed files
with
138 additions
and
28 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
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,4 +1,4 @@ | ||
.vscode | ||
cover.out | ||
*.out | ||
cover.txt | ||
cover.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
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
File renamed without changes.
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 |
---|---|---|
@@ -1,30 +1,53 @@ | ||
#!/bin/bash | ||
|
||
set -eo pipefail | ||
set -xeo pipefail | ||
|
||
# create cover directory | ||
|
||
cover_dir="${GITHUB_WORKSPACE}/go-cover/${INPUTS_PATH}" | ||
mkdir -p "${cover_dir}/revisions" | ||
mkdir -p "${cover_dir}/head" | ||
|
||
# generate coverage files | ||
cd "${INPUTS_PATH}" | ||
go tool cover -html=cover.out -o "${GITHUB_WORKSPACE}/go-cover/${REVISION}.html" | ||
go tool cover -func=cover.out -o "${GITHUB_WORKSPACE}/go-cover/${REVISION}.txt" | ||
cp cover.out "${GITHUB_WORKSPACE}/go-cover/${REVISION}.out" | ||
|
||
# if we are on the main branch, copy files to main.* | ||
if [ "${REF_NAME}" = "main" ]; then | ||
cp "${GITHUB_WORKSPACE}/go-cover/${REVISION}.html" "${GITHUB_WORKSPACE}/go-cover/main.html" | ||
cp "${GITHUB_WORKSPACE}/go-cover/${REVISION}.txt" "${GITHUB_WORKSPACE}/go-cover/main.txt" | ||
cp "${GITHUB_WORKSPACE}/go-cover/${REVISION}.out" "${GITHUB_WORKSPACE}/go-cover/main.out" | ||
fi | ||
# generate coverage files | ||
|
||
go tool cover -html=cover.out -o "${cover_dir}/revisions/${REVISION}.html" | ||
go tool cover -func=cover.out -o "${cover_dir}/revisions/${REVISION}.txt" | ||
cp cover.out "${cover_dir}/revisions/${REVISION}.out" | ||
|
||
# generate incremental coverage files | ||
|
||
cd "${GITHUB_WORKSPACE}/go-cover" | ||
echo "mode: set" > incremental.out | ||
# grep exits with 1 if no lines are found, so we need to ignore that | ||
grep -F -v -x -f "${GITHUB_WORKSPACE}/go-cover/head/head.out" cover.out >> incremental.out || true | ||
go tool cover -html=incremental.out -o "${cover_dir}/revisions/${REVISION}-inc.html" | ||
go tool cover -func=incremental.out -o "${cover_dir}/revisions/${REVISION}-inc.txt" | ||
cp incremental.out "${cover_dir}/revisions/${REVISION}-inc.out" | ||
|
||
cd "${cover_dir}" | ||
|
||
# beautify html | ||
ex -sc '%s/<style>/<style>@import url("nord.css");/' -c 'x' "${REVISION}.html" | ||
ex -sc '%s/<\/script>/<\/script><script src="ln.js"><\/script>/' -c 'x' "${REVISION}.html" | ||
|
||
for file in "revisions/${REVISION}.html" "revisions/${REVISION}-inc.html"; do | ||
ex -sc '%s/<style>/<style>@import url("..\/nord.css");/' -c 'x' "${file}" | ||
ex -sc '%s/<\/script>/<\/script><script src="..\/index.js"><\/script>/' -c 'x' "${file}" | ||
done | ||
|
||
# if we are on the main branch, copy files to main.* | ||
|
||
if [ "${REF_NAME}" = "main" ]; then | ||
cp "revisions/${REVISION}.html" "${cover_dir}/head/head.html" | ||
cp "revisions/${REVISION}.txt" "${cover_dir}/head/head.txt" | ||
cp "revisions/${REVISION}.out" "${cover_dir}/head/head.out" | ||
fi | ||
|
||
# copy assets | ||
cp "${GITHUB_ACTION_PATH}"/assets/* . | ||
|
||
cp "${GITHUB_ACTION_PATH}"/assets/* "${cover_dir}" | ||
|
||
# push to branch | ||
|
||
git add . | ||
git config user.email "[email protected]" | ||
git config user.name "go-coverage-action" | ||
|
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,62 @@ | ||
const path = require('path') | ||
|
||
const normalizePath = module.exports = (dir) => { | ||
dir = path.normalize(dir) | ||
|
||
if (dir === '/' || dir === './' || dir === '.') { | ||
return '' | ||
} | ||
|
||
if (dir.startsWith('./')) { | ||
dir = dir.substring(2) | ||
} | ||
|
||
if (dir.startsWith('/')) { | ||
dir = dir.substring(1) | ||
} | ||
|
||
if (dir.endsWith('/')) { | ||
dir = dir.substring(0, dir.length - 1) | ||
} | ||
|
||
return dir | ||
} | ||
|
||
const test = async () => { | ||
let pass = true | ||
|
||
const tests = [ | ||
{ input: '/', expected: '' }, | ||
{ input: '/foo', expected: 'foo' }, | ||
|
||
{ input: './', expected: '' }, | ||
{ input: './foo', expected: 'foo' }, | ||
{ input: './foo/', expected: 'foo' }, | ||
{ input: './foo/bar', expected: 'foo/bar' }, | ||
{ input: './foo/bar/', expected: 'foo/bar' }, | ||
|
||
{ input: '', expected: '' }, | ||
{ input: 'foo', expected: 'foo' }, | ||
{ input: 'foo/', expected: 'foo' }, | ||
{ input: 'foo/bar', expected: 'foo/bar' }, | ||
{ input: 'foo/bar/', expected: 'foo/bar' }, | ||
] | ||
|
||
for (const { input, expected } of tests) { | ||
const result = normalizePath(input) | ||
if (result !== expected) { | ||
console.error(`error("${input}"): expected "${expected}" but got "${result}"`) | ||
pass = false | ||
} | ||
} | ||
|
||
if (!pass) { | ||
process.exit(1) | ||
} else { | ||
console.log('All tests passed') | ||
} | ||
} | ||
|
||
if (require.main === module) { | ||
test() | ||
} |
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