├── go-test-app-02 ├── go-test-app-01 ├── go.mod ├── foo.go ├── main_test.go ├── Makefile └── main.go ├── .gitignore ├── .github ├── FUNDING.yaml └── workflows │ └── ci.yaml ├── scripts ├── pull.sh ├── beautify-html.sh └── push.sh ├── src ├── check-threshold.js ├── normalize-path.js └── update-comment.js ├── Makefile ├── LICENSE.md ├── assets ├── index.html ├── index.css └── index.js ├── action.yaml └── README.md /go-test-app-02: -------------------------------------------------------------------------------- 1 | go-test-app-01 -------------------------------------------------------------------------------- /go-test-app-01/go.mod: -------------------------------------------------------------------------------- 1 | module cointoss 2 | 3 | go 1.22.2 4 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .vscode 2 | *.out 3 | cover-test 4 | cover.html 5 | cover.txt 6 | -------------------------------------------------------------------------------- /go-test-app-01/foo.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | func foo() string { 4 | return "foo" 5 | } 6 | -------------------------------------------------------------------------------- /.github/FUNDING.yaml: -------------------------------------------------------------------------------- 1 | github: kilianc 2 | buy_me_a_coffee: kilianciuffolo 3 | custom: "https://tinyurl.com/kilian-venmo-me" 4 | -------------------------------------------------------------------------------- /go-test-app-01/main_test.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "testing" 4 | 5 | func TestC(t *testing.T) { 6 | main() 7 | } 8 | -------------------------------------------------------------------------------- /go-test-app-01/Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: test 2 | test: 3 | @go test -coverprofile=cover.out ./... 4 | 5 | .PHONY: clean 6 | clean: 7 | @rm -f cover.* 8 | -------------------------------------------------------------------------------- /scripts/pull.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -xeo pipefail 4 | 5 | cd go-cover 6 | git fetch origin 7 | 8 | # if branch exists, pull it, otherwise create it 9 | if git rev-parse --verify "origin/${INPUTS_BRANCH}"; then 10 | git checkout "${INPUTS_BRANCH}" 11 | git pull origin "${INPUTS_BRANCH}" 12 | else 13 | git checkout --orphan "${INPUTS_BRANCH}" 14 | rm .git/index 15 | git clean -fdx 16 | mkdir -p "./${INPUTS_PATH}/head" 17 | touch "./${INPUTS_PATH}/head/head.html" 18 | touch "./${INPUTS_PATH}/head/head.txt" 19 | echo "mode: set" > "./${INPUTS_PATH}/head/head.out" 20 | fi 21 | -------------------------------------------------------------------------------- /src/check-threshold.js: -------------------------------------------------------------------------------- 1 | const fs = require('fs') 2 | const normalizePath = require('./normalize-path') 3 | 4 | const checkThreshold = module.exports = async ({ threshold, path, revision }) => { 5 | path = normalizePath(path) 6 | 7 | const coverageText = fs.readFileSync(`go-cover/${path}/revisions/${revision}.txt`, 'utf8').split('\n').slice(0, -1) 8 | const coverageTextSummary = coverageText[coverageText.length-1].split('\t').pop() 9 | 10 | const coverage = parseFloat(coverageTextSummary.replace('%', ''), 10) 11 | 12 | if (coverage < threshold) { 13 | console.log(`\x1b[91m✘ coverage ${coverage}% < ${threshold}%`) 14 | process.exit(1) 15 | } 16 | 17 | console.log(`\x1b[92m✔ coverage ${coverage}% >= ${threshold}%`) 18 | } 19 | -------------------------------------------------------------------------------- /go-test-app-01/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "math/rand" 6 | ) 7 | 8 | const side = "right" 9 | 10 | func main() { 11 | if tossCoin() == "heads" { 12 | 13 | 14 | fmt.Println("Heads") } else { fmt.Println(` 15 | Tails`) } 16 | 17 | printColor("red") 18 | 19 | fmt.Println("Maybe:", maybe()) 20 | fmt.Println("Foo:", foo()) 21 | } 22 | 23 | func tossCoin() string { 24 | if rand.Intn(2) == 0 { 25 | return "heads" 26 | } else { 27 | return "tails" 28 | } 29 | } 30 | 31 | func maybe() bool { 32 | if side == "right" { 33 | return true 34 | } else { 35 | return false 36 | } 37 | } 38 | 39 | func printColor(color string) { 40 | switch color { 41 | case "red": fmt.Println("Red") 42 | case "blue": fmt.Println("Blue") 43 | case "green": fmt.Println("Green") 44 | default: fmt.Println("Unknown color") 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /.github/workflows/ci.yaml: -------------------------------------------------------------------------------- 1 | name: CI 2 | 3 | on: 4 | push: 5 | branches: [ "main" ] 6 | pull_request: 7 | branches: [ "main" ] 8 | 9 | jobs: 10 | test: 11 | name: Test 12 | runs-on: ubuntu-latest 13 | permissions: 14 | pull-requests: write 15 | contents: write 16 | steps: 17 | - uses: actions/checkout@v4 18 | 19 | - name: Set up Go 20 | uses: actions/setup-go@v5 21 | with: 22 | go-version: '1.22' 23 | 24 | - name: Generate Coverage Files 25 | run: | 26 | cd go-test-app-01 27 | make test 28 | 29 | - name: Go Beautiful HTML Coverage 30 | if: always() 31 | uses: './' 32 | with: 33 | path: go-test-app-01/ 34 | threshold: 66.7 35 | 36 | - name: Go Beautiful HTML Coverage 37 | uses: './' 38 | with: 39 | path: go-test-app-02/ 40 | -------------------------------------------------------------------------------- /scripts/beautify-html.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | if [ "${REVISION}" = "local" ]; then 4 | set -eo pipefail 5 | else 6 | set -xeo pipefail 7 | fi 8 | 9 | if [ -z "${REVISION}" ]; then 10 | echo "REVISION is not set" 11 | exit 1 12 | fi 13 | 14 | # this is useful for browser caching 15 | hash=$(cat index.css index.js | md5sum | awk '{print $1}') 16 | 17 | for file in "revisions/${REVISION}.html" "revisions/${REVISION}-inc.html"; do 18 | ex -sc '%s/\n\t\t 47 | 85 | 86 |
87 | 88 |Waiting for GitHub Pages Deployment
89 | 90 |