├── .github └── workflows │ ├── enforce-license-compliance.yml │ └── go-standard.yml ├── .gitignore ├── Dockerfile ├── LICENSE.md ├── README.md ├── codecov.yml ├── docker-compose.yml ├── entrypoint.sh ├── go.mod ├── local.sh ├── main.go ├── main_test.go └── request.py /.github/workflows/enforce-license-compliance.yml: -------------------------------------------------------------------------------- 1 | name: Enforce License Compliance 2 | 3 | on: 4 | pull_request: 5 | branches: [main, master] 6 | 7 | jobs: 8 | enforce-license-compliance: 9 | runs-on: ubuntu-latest 10 | steps: 11 | - name: 'Enforce License Compliance' 12 | uses: getsentry/action-enforce-license-compliance@57ba820387a1a9315a46115ee276b2968da51f3d # main 13 | with: 14 | fossa_api_key: ${{ secrets.FOSSA_API_KEY }} 15 | -------------------------------------------------------------------------------- /.github/workflows/go-standard.yml: -------------------------------------------------------------------------------- 1 | name: Github Actions Go Standard 2 | on: 3 | push: 4 | branches: 5 | - main 6 | pull_request: 7 | branches: 8 | - main 9 | jobs: 10 | test-and-upstream: 11 | runs-on: ubuntu-latest 12 | steps: 13 | - uses: actions/checkout@v4 14 | with: 15 | token: ${{ secrets.STANDARDS_TOKEN }} 16 | - name: Set up Python 3.10 17 | uses: actions/setup-python@v2 18 | with: 19 | python-version: '3.10' 20 | - name: Set up JDK 11 21 | uses: actions/setup-java@v2 22 | with: 23 | java-version: '11' 24 | distribution: 'adopt' 25 | - name: Before Install 26 | run: pip install requests 27 | - name: Run Tests 28 | run: go test -race -coverprofile=coverage.txt -covermode=atomic 29 | env: 30 | GO111MODULE: 'auto' 31 | - name: Upload coverage to Codecov 32 | uses: codecov/codecov-action@v5 33 | env: 34 | CODECOV_TOKEN: ${{ secrets.CODECOV_ORG_TOKEN }} 35 | - name: Check coverage 36 | run: python request.py 37 | env: 38 | API_KEY: ${{ secrets.API_KEY }} 39 | EXPECTED_COVERAGE: ${{ secrets.EXPECTED_COVERAGE }} 40 | - name: Upstream to Standards 41 | env: 42 | GH_TOKEN: ${{ secrets.STANDARDS_TOKEN }} 43 | COVERAGE_SOURCE_FILE: ${{ secrets.COVERAGE_SOURCE_FILE }} 44 | if: ${{ github.event_name == 'push'}} 45 | run: | 46 | wget --header "Authorization: token ${GH_TOKEN}" \ 47 | --header "Accept: application/vnd.github.v3.raw" \ 48 | https://api.github.com/repos/codecov/standards/contents/upstream.sh 49 | bash upstream.sh 50 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | coverage.txt -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM golang:latest 2 | 3 | WORKDIR /app 4 | 5 | COPY . ./ 6 | 7 | RUN go mod download 8 | 9 | ENTRYPOINT [ "/app/entrypoint.sh" ] 10 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 Codecov 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. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # go-standard 2 | 3 | [![Workflow for Go Standard Action](https://github.com/codecov/go-standard/actions/workflows/go-standard.yml/badge.svg)](https://github.com/codecov/go-standard/actions/workflows/go-standard.yml)[![codecov](https://codecov.io/gh/codecov/go-Standard/branch/master/graph/badge.svg)](https://codecov.io/gh/codecov/go-Standard) 4 | [![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2Fcodecov%2Fgo-standard.svg?type=shield)](https://app.fossa.com/projects/git%2Bgithub.com%2Fcodecov%2Fgo-standard?ref=badge_shield) 5 | 6 | ### Last Updated: 09/14/23 00:12:55 7 | 8 | ## What is this? 9 | 10 | This is a **Go** application, with basic unit tests, for which coverage is uploaded to Codecov on a daily basis. It can also serve as an example for how to integrate Codecov into your Go project. If the build is passing for this project, then Codecov's Go report processing is functional and correct on codecov.io. 11 | 12 | ## Configuration 13 | 14 | This project is written in `Go`. Unit test are written using the go `testing` framework and coverage reports are generated using the `go` CLI. 15 | 16 | ## Usage 17 | 18 | ### The Docker Way 19 | 20 | Run unit tests inside a Docker container 21 | ```bash 22 | chmod +x local.sh 23 | ./local.sh 24 | ``` 25 | 26 | ### The Local Way 27 | 28 | Run tests 29 | ``` 30 | go test -race -coverprofile=coverage.txt -covermode=atomic 31 | ``` 32 | 33 | ## Reporting Issues 34 | 35 | If you've discovered an issue with this repository or with Go processing in general, it is recommended to email support@codecov.io rather than post an issue here. This repository will not be checked regularly for open issues. 36 | 37 | ## Contributing 38 | 39 | Contributions are welcome! If you'd like to contribute to this repository, feel free to open a pull request or flag an issue. If you would like to contribute a new lanaguage standard, [you can get more information here](https://github.com/codecov/standards-scripts/blob/master/README.md#contributing). 40 | 41 | 42 | ## License 43 | [![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2Fcodecov%2Fgo-standard.svg?type=large)](https://app.fossa.com/projects/git%2Bgithub.com%2Fcodecov%2Fgo-standard?ref=badge_large) -------------------------------------------------------------------------------- /codecov.yml: -------------------------------------------------------------------------------- 1 | ignore: 2 | - "request.py" 3 | -------------------------------------------------------------------------------- /docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: "3" 2 | services: 3 | go: 4 | build: ./ 5 | command: ./entrypoint.sh -------------------------------------------------------------------------------- /entrypoint.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | go test -race -coverprofile=coverage.txt -covermode=atomic -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module goStandard 2 | 3 | go 1.18 4 | -------------------------------------------------------------------------------- /local.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | docker-compose build 3 | docker-compose up 4 | docker cp go-standard-go-1:/app/coverage.txt ./coverage.txt 5 | echo "Copied coverage file to folder `pwd`/coverage.txt" -------------------------------------------------------------------------------- /main.go: -------------------------------------------------------------------------------- 1 | package goStandard 2 | 3 | // I'm a comment! 4 | 5 | func UncoveredIf(a bool) bool { 6 | if a { 7 | return false 8 | } 9 | // I'm also a comment 10 | return true 11 | } 12 | 13 | 14 | func FullyCovered() bool { 15 | return true 16 | } 17 | /* Comment 3 18 | * space 19 | */ 20 | 21 | func Uncovered() bool { 22 | return true 23 | } 24 | -------------------------------------------------------------------------------- /main_test.go: -------------------------------------------------------------------------------- 1 | package goStandard 2 | 3 | import "testing" 4 | 5 | func TestGoStandard(t *testing.T) { 6 | result1 := UncoveredIf(true) 7 | if result1 { 8 | t.Error("Failed UncoveredIf test") 9 | } 10 | 11 | result2 := FullyCovered() 12 | if !result2 { 13 | t.Error("Failed FullyCovered test") 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /request.py: -------------------------------------------------------------------------------- 1 | # Function: this is a python script that checks to see if coverage reported from the Codecov API is accurate 2 | 3 | import requests 4 | import time 5 | import os 6 | 7 | payload = {'token': os.environ['API_KEY']} 8 | 9 | link = 'https://api.codecov.io/api/v2/github/codecov/repos/java-standard/commits' 10 | 11 | print("Waiting 60 seconds for report to upload before pinging API...") 12 | 13 | # night night 14 | time.sleep(60) 15 | 16 | print("Pinging Codecov's API..") 17 | #get latest coverage data 18 | all_data = requests.get(link, params=payload).json() 19 | commit_data = all_data['results'][0] 20 | coverage_percentage = commit_data['totals']['coverage'] 21 | 22 | print("Ensuring coverage percentage is accurate...") 23 | # result should return 85.71429 as its coverage metric 24 | if(str(coverage_percentage) == os.environ['EXPECTED_COVERAGE']): 25 | print("Success! Codecov's API returned the correct coverage percentage, " + os.environ['EXPECTED_COVERAGE']) 26 | exit(0) 27 | else: 28 | print("Whoops, something is wrong D: Codecov did not return the correct coverage percentage. Coverage percentage should be " + os.environ['EXPECTED_COVERAGE']+" but Codecov returned "+ str(coverage_percentage)) 29 | exit(1) 30 | --------------------------------------------------------------------------------