Skip to content
This repository has been archived by the owner on Oct 25, 2023. It is now read-only.

Commit

Permalink
Add Coverage to the project (Buildpacks and Invokers) (#203)
Browse files Browse the repository at this point in the history
  • Loading branch information
Rodolfo Sanchez authored Jun 21, 2023
1 parent eb90073 commit 6a479dd
Show file tree
Hide file tree
Showing 12 changed files with 135 additions and 15 deletions.
34 changes: 34 additions & 0 deletions .github/workflows/code-coverage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Copyright 2021-2022 VMware, Inc.
# SPDX-License-Identifier: BSD-2-Clause

name: CodeCov
on:
workflow_dispatch: {}
push:
paths:
- 'buildpacks/**'
- 'invokers/**'
schedule:
- cron: '0 6 * * 1'

jobs:
code-cov:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Setup Go
uses: actions/setup-go@v2
with:
go-version: '1.19'
- run: go version
- name: Run Buildpack Tests
run: make buildpacks.tests
- name: Run Python Invoker Tests
id: python-invoker-tests
run: make invokers.python.tests
- name: Run Java Invoker Tests
run: make invokers.java.tests
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN}}
6 changes: 6 additions & 0 deletions .github/workflows/test-buildpacks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,9 @@ jobs:
- run: go version
- name: Run Buildpack Tests
run: make buildpacks.tests
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN}}
files: ./buildpacks/common/coverage.out, ./buildpacks/java/coverage.out, ./buildpacks/python/coverage.out
flags: test-buildpacks
11 changes: 9 additions & 2 deletions .github/workflows/test-invokers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,16 @@ jobs:
steps:
- uses: actions/checkout@v2
- name: Run Python Invoker Tests
id: python-invoker-tests
run: make invokers.python.tests
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v3
with:
files: ./coverage.txt
token: ${{ secrets.CODECOV_TOKEN}}
file: ./invokers/python/coverage.xml
flags: test-invokers-python
name: test-invoker-python
network_prefix: test-invoker-python

test-java-invoker:
name: Test Java Invoker
Expand All @@ -40,6 +44,9 @@ jobs:
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v3
with:
files: ./coverage.txt
token: ${{ secrets.CODECOV_TOKEN}}
file: ./invokers/java/target/reports/jacoco.xml
flags: test-invokers-java
name: test-invoker-java
network_prefix: test-invoker-java

4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ local.mk
__pycache__/
*.py[cod]
*$py.class

*.lcov
# C extensions
*.so

Expand Down Expand Up @@ -46,6 +46,8 @@ htmlcov/
.cache
nosetests.xml
coverage.xml
coverage.txt
coverage.out
*.cover
.hypothesis/
.pytest_cache/
Expand Down
2 changes: 1 addition & 1 deletion buildpacks/common/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ buildpacks.common.tests.sources := \
#########

buildpacks.common.tests: $(buildpacks.common.tests.sources)
cd $(buildpacks.common.path) && go test -v -count=1 -timeout 30s kn-fn/buildpacks/tests
cd $(buildpacks.common.path) && go test -v -count=1 -timeout 30s -race -covermode=atomic -coverprofile=coverage.out kn-fn/buildpacks/tests

buildpacks.tests .PHONY: buildpacks.common.tests
2 changes: 1 addition & 1 deletion buildpacks/java/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ buildpacks.java.images.publish: buildpacks.java.images.offline.publish buildpack
buildpacks.java.commit.prep: $(buildpacks.java.path)/buildpack.toml

buildpacks.java.tests: $(buildpacks.java.bin.sources) $(buildpacks.java.tests.sources)
cd $(buildpacks.java.path) && go test -v -count=1 -timeout 30s kn-fn/java-function-buildpack/tests
cd $(buildpacks.java.path) && go test -v -count=1 -timeout 30s -race -coverprofile=coverage.out -covermode=atomic kn-fn/java-function-buildpack/tests

buildpacks.java.clean:
rm -rf $(buildpacks.java.build_dir)
Expand Down
2 changes: 1 addition & 1 deletion buildpacks/python/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ buildpacks.python.images.publish: buildpacks.python.images.offline.publish build
buildpacks.python.commit.prep: $(buildpacks.python.path)/buildpack.toml

buildpacks.python.tests: $(buildpacks.python.bin.sources) $(buildpacks.python.tests.sources)
cd $(buildpacks.python.path) && go test -v -count=1 -timeout 30s kn-fn/python-function-buildpack/tests
cd $(buildpacks.python.path) && go test -v -count=1 -timeout 30s -race -coverprofile=coverage.out -covermode=atomic kn-fn/python-function-buildpack/tests

buildpacks.python.clean:
rm -rf $(buildpacks.python.build_dir)
Expand Down
39 changes: 39 additions & 0 deletions codecov.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Copyright 2021-2022 VMware, Inc.
# SPDX-License-Identifier: BSD-2-Clause
codecov:
disable_default_path_fixes: true
coverage:
status:
project:
default: off
buildpacks:
target: auto
flags:
- buildpacks
invokers:
target: auto
flags:
- invokers
comment:
layout: "reach, diff, flags, files"
behavior: default
require_changes: false
require_base: yes
require_head: yes
branches: null

flags:
buildpacks:
paths:
- buildpacks/common
- buildpacks/java
- buildpacks/python
carryforward: true
invokers:
paths:
- invokers/java
- invokers/python
carryforward: true
tests:
paths:
- tests/
2 changes: 1 addition & 1 deletion invokers/java/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ $(invokers.java.publish): $(GSUTIL) $(invokers.java.artifacts)

.PHONY: invokers.java.tests
invokers.java.tests: $(invokers.java.builder.image) $(invokers.java.sources)
docker run $(shell cat $<)
docker run -v $(invokers.java.path)/target:/usr/src/invoker/target $(shell cat $<)

.PHONY: invokers.java.clean
invokers.java.clean:
Expand Down
41 changes: 36 additions & 5 deletions invokers/java/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.1.0</version>
<version>3.0.5</version>
</parent>
<groupId>com.vmware</groupId>
<artifactId>java-function-invoker</artifactId>
Expand All @@ -19,7 +19,7 @@
<description>Detect and run a function by leveraging Spring Cloud Functions.</description>
<properties>
<java.version>17</java.version>
<spring-cloud-function.version>4.0.3</spring-cloud-function.version>
<spring-cloud-function.version>4.0.2</spring-cloud-function.version>
</properties>

<dependencies>
Expand Down Expand Up @@ -59,7 +59,12 @@
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
<dependency>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.10</version>
</dependency>
</dependencies>
</dependencyManagement>

<repositories>
Expand All @@ -82,6 +87,32 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.10</version>
<executions>
<execution>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>generate-code-coverage-report</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
<configuration>
<!-- Sets the path to the file which contains the execution data. -->

<dataFile>target/jacoco.exec</dataFile>
<!-- Sets the output directory for the code coverage report. -->
<outputDirectory>target/reports</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
2 changes: 1 addition & 1 deletion invokers/python/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ $(invokers.python.publish): $(GSUTIL) $(invokers.python.artifacts)

.PHONY: invokers.python.tests
invokers.python.tests: $(invokers.python.builder.image) $(invokers.python.sources)
docker run $(shell cat $<)
docker run -v $(invokers.python.path)/:/workspace/invoker/ $(shell cat $<)

.PHONY: invokers.python.clean
invokers.python.clean:
Expand Down
5 changes: 3 additions & 2 deletions invokers/python/tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ isolated_build = True

[testenv]
deps = pytest
commands = pytest
pytest-cov
commands = pytest --cov=pyfunc --cov-report xml:coverage.xml tests/

[flake8]
# Ignore line-too-long
ignore = E501
ignore = E501

0 comments on commit 6a479dd

Please sign in to comment.