Add Codecov to GitHub actions
This commit is contained in:

committed by
Sebastian Serth

parent
a720553dd1
commit
5c2b53f4bc
6
.github/codecov.yml
vendored
Normal file
6
.github/codecov.yml
vendored
Normal file
@ -0,0 +1,6 @@
|
||||
codecov:
|
||||
notify:
|
||||
after_n_builds: 2
|
||||
|
||||
ignore:
|
||||
- "**/*_mock.go"
|
30
.github/workflows/ci.yml
vendored
30
.github/workflows/ci.yml
vendored
@ -37,7 +37,7 @@ jobs:
|
||||
run: date +%s > ~/.cache/go-build/trim.txt
|
||||
continue-on-error: true
|
||||
- name: Build
|
||||
run: make build
|
||||
run: make build-cover
|
||||
- name: Upload Poseidon binary
|
||||
uses: actions/upload-artifact@v3
|
||||
with:
|
||||
@ -84,19 +84,26 @@ jobs:
|
||||
continue-on-error: true
|
||||
- name: Run tests
|
||||
run: make coverhtml
|
||||
- name: Upload coverage reports to Codecov
|
||||
uses: codecov/codecov-action@v3
|
||||
if: ${{ success() || failure() }}
|
||||
with:
|
||||
token: ${{ secrets.CODECOV_TOKEN }}
|
||||
- name: Publish code coverage
|
||||
uses: paambaati/codeclimate-action@v3.2.0
|
||||
if: ${{ success() || failure() }}
|
||||
env:
|
||||
CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }}
|
||||
with:
|
||||
prefix: github.com/openHPI/poseidon/
|
||||
coverageLocations: |
|
||||
${{github.workspace}}/coverage_cleaned.cov:gocov
|
||||
${{github.workspace}}/coverage/coverage.cov:gocov
|
||||
- name: Upload coverage report
|
||||
uses: actions/upload-artifact@v3
|
||||
if: ${{ success() || failure() }}
|
||||
with:
|
||||
name: coverage
|
||||
path: coverage_unit.html
|
||||
path: coverage/coverage_unit.html
|
||||
|
||||
dep-scan:
|
||||
runs-on: ubuntu-latest
|
||||
@ -130,6 +137,7 @@ jobs:
|
||||
POSEIDON_AWS_ENDPOINT: ${{ secrets.POSEIDON_AWS_ENDPOINT }}
|
||||
POSEIDON_AWS_FUNCTIONS: ""
|
||||
POSEIDON_NOMAD_DISABLEFORCEPULL: true
|
||||
GOCOVERDIR: coverage
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v3
|
||||
@ -204,6 +212,7 @@ jobs:
|
||||
sudo ./nomad agent -dev -log-level=WARN -config e2e-config.hcl &
|
||||
until curl -s --fail http://localhost:4646/v1/agent/health ; do sleep 1; done
|
||||
chmod +x ./poseidon
|
||||
mkdir -p ${GOCOVERDIR}
|
||||
./poseidon &
|
||||
until curl -s --fail http://localhost:7200/api/v1/health ; do sleep 1; done
|
||||
make e2e-test
|
||||
@ -211,3 +220,18 @@ jobs:
|
||||
run: |
|
||||
killall poseidon
|
||||
make e2e-test-recovery
|
||||
if: ${{ success() || failure() }}
|
||||
- name: Convert coverage reports
|
||||
run: make convert-run-coverage
|
||||
if: ${{ success() || failure() }}
|
||||
- name: Upload coverage reports to Codecov
|
||||
uses: codecov/codecov-action@v3
|
||||
if: ${{ success() || failure() }}
|
||||
with:
|
||||
token: ${{ secrets.CODECOV_TOKEN }}
|
||||
- name: Upload coverage report
|
||||
uses: actions/upload-artifact@v3
|
||||
if: ${{ success() || failure() }}
|
||||
with:
|
||||
name: coverage
|
||||
path: coverage/coverage_run.html
|
||||
|
3
.gitignore
vendored
3
.gitignore
vendored
@ -16,6 +16,9 @@ tests/e2e/configuration.yaml
|
||||
# trivy artifacts
|
||||
.trivy
|
||||
|
||||
# coverage reports
|
||||
/coverage
|
||||
|
||||
# IDE files
|
||||
/.idea
|
||||
*.iml
|
||||
|
25
Makefile
25
Makefile
@ -2,6 +2,7 @@ PROJECT_NAME = poseidon
|
||||
REPOSITORY_OWNER = openHPI
|
||||
PKG = github.com/$(REPOSITORY_OWNER)/$(PROJECT_NAME)/cmd/$(PROJECT_NAME)
|
||||
UNIT_TESTS = $(shell go list ./... | grep -v /e2e | grep -v /recovery)
|
||||
GOCOVERDIR=coverage
|
||||
|
||||
# Define the PGO file to be used for the build
|
||||
PGO_FILE = ./cmd/$(PROJECT_NAME)/default.pgo
|
||||
@ -57,6 +58,10 @@ else
|
||||
@go build -o $(PROJECT_NAME) -v $(PKG)
|
||||
endif
|
||||
|
||||
.PHONY: build-cover
|
||||
build-cover: deps ## Build the binary and with coverage support for e2e-tests
|
||||
@go build -cover -o $(PROJECT_NAME) -v $(PKG)
|
||||
|
||||
.PHONY: clean
|
||||
clean: ## Remove previous build
|
||||
@rm -f poseidon
|
||||
@ -97,18 +102,30 @@ race: deps ## Run data race detector
|
||||
|
||||
.PHONY: coverage
|
||||
coverage: deps ## Generate code coverage report
|
||||
@go test $(UNIT_TESTS) -v -coverprofile coverage.cov
|
||||
@mkdir -p $(GOCOVERDIR)
|
||||
@go test $(UNIT_TESTS) -v -coverprofile $(GOCOVERDIR)/coverage_output.cov -covermode atomic
|
||||
# exclude mock files from coverage
|
||||
@cat coverage.cov | grep -v _mock.go > coverage_cleaned.cov || true
|
||||
@go tool cover -func=coverage_cleaned.cov
|
||||
@cat $(GOCOVERDIR)/coverage_output.cov | grep -v _mock.go > $(GOCOVERDIR)/coverage.cov || true
|
||||
@rm $(GOCOVERDIR)/coverage_output.cov
|
||||
@go tool cover -func=$(GOCOVERDIR)/coverage.cov
|
||||
|
||||
.PHONY: coverhtml
|
||||
coverhtml: coverage ## Generate HTML coverage report
|
||||
@go tool cover -html=coverage_cleaned.cov -o coverage_unit.html
|
||||
@go tool cover -html=$(GOCOVERDIR)/coverage.cov -o $(GOCOVERDIR)/coverage_unit.html
|
||||
|
||||
deploy/dockerfiles: ## Clone Dockerfiles repository
|
||||
@git clone git@github.com:$(REPOSITORY_OWNER)/dockerfiles.git deploy/dockerfiles
|
||||
|
||||
.PHONY: run-with-coverage
|
||||
run-with-coverage: build-cover ## Run binary and capture code coverage (during e2e tests)
|
||||
@mkdir -p $(GOCOVERDIR)
|
||||
@GOCOVERDIR=$(GOCOVERDIR) ./$(PROJECT_NAME)
|
||||
|
||||
.PHONY: convert-run-coverage
|
||||
convert-run-coverage: ## Convert coverage data (created by `run-with-coverage`) to legacy text format
|
||||
@go tool covdata textfmt -i $(GOCOVERDIR) -o $(GOCOVERDIR)/coverage_run.cov
|
||||
@go tool cover -html=$(GOCOVERDIR)/coverage_run.cov -o $(GOCOVERDIR)/coverage_run.html
|
||||
|
||||
.PHONY: e2e-test-docker-image
|
||||
e2e-test-docker-image: deploy/dockerfiles ## Build Docker image that is used in e2e tests
|
||||
@docker build -t $(E2E_TEST_BASE_IMAGE) deploy/dockerfiles/$(E2E_TEST_BASE_CONTAINER)
|
||||
|
Reference in New Issue
Block a user