Skip to content

Commit

Permalink
Add code coverage to blueprint-operator BOP-1133 (#100)
Browse files Browse the repository at this point in the history
* Add code coverage to blueprint-operator BOP-1133

* Bump download artifact actions to v4

* Update baseline workflow to test.yml

* Fix test artifact ref
  • Loading branch information
tppolkow authored Dec 11, 2024
1 parent e857ff3 commit 5e91c51
Show file tree
Hide file tree
Showing 9 changed files with 78 additions and 10 deletions.
7 changes: 7 additions & 0 deletions .github/workflows/PR.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ jobs:
if: ${{ always() && contains(join(needs.*.result, ','), 'success') }} # when all `needs` jobs are successful
needs: [ vet, test, build ]
uses: ./.github/workflows/e2e.yml
code-coverage-report:
needs: [ test ]
uses: ./.github/workflows/code-coverage.yml
with:
artifact_url: ${{ needs.test.outputs.coverage_artifact_url }}
pr_number: ${{ github.event.pull_request.number }}
secrets: inherit
cleanup:
if: ${{ always() }}
needs: [vet, test, e2e, build]
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
run: docker save ${{ env.REGISTRY }}/${{ env.ORG }}/${{ env.IMAGE }}:latest -o /tmp/${{ env.IMAGE }}.tar

- name: Upload image artifact
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: ${{ env.IMAGE }}
retention-days: 1
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/cleanup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
env-file: .github/development.env

- name: Delete artifacts
uses: geekyeggo/delete-artifact@v4
uses: geekyeggo/delete-artifact@v5
with:
name: ${{ env.IMAGE }}
token: ${{ secrets.PAT_CI_BOUNDLESS }}
43 changes: 43 additions & 0 deletions .github/workflows/code-coverage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Code Coverage

on:
workflow_call:
inputs:
artifact_url:
description: 'url of coverage artifact'
required: true
type: string
pr_number:
description: 'Pull Request Number'
required: true
type: number

jobs:
code-coverage:
runs-on: ubuntu-latest
steps:
- name: Code coverage Report
uses: fgrosse/[email protected]
id: report-step
with:
github-baseline-workflow-ref: test.yml
root-package: github.com/mirantiscontainers/blueprint-operator/
skip-comment: true # Skip comment from this action since it fails due to permissions and use different action for comment instead
- name: Find Comment
uses: peter-evans/find-comment@v3
id: fc
with:
issue-number: ${{ inputs.pr_number }}
comment-author: 'mirantiscontainers-bot'
body-includes: Coverage Report
- name: Comment on the PR
uses: peter-evans/create-or-update-comment@v3
if: ${{ steps.report-step.outputs.coverage_report != '' }}
with:
comment-id: ${{ steps.fc.outputs.comment-id }}
token: ${{ secrets.PAT_CI_BOUNDLESS }}
issue-number: ${{ inputs.pr_number }}
edit-mode: replace
body: |
[Coverage Report](${{ inputs.artifact_url }})
${{ steps.report-step.outputs.coverage_report }}
2 changes: 1 addition & 1 deletion .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
go-version: ${{ env.GO_VERSION }}

- name: Download artifact
uses: actions/download-artifact@v3
uses: actions/download-artifact@v4
with:
name: ${{ env.IMAGE }}
path: /tmp
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/push-to-ghcr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
password: ${{ secrets.PAT_CI_BOUNDLESS }}

- name: Download artifact
uses: actions/download-artifact@v3
uses: actions/download-artifact@v4
with:
name: ${{ env.IMAGE }}
path: /tmp
Expand Down Expand Up @@ -57,7 +57,7 @@ jobs:
password: ${{ secrets.PAT_CI_BOUNDLESS }}

- name: Download artifact
uses: actions/download-artifact@v3
uses: actions/download-artifact@v4
with:
name: ${{ env.IMAGE }}
path: /tmp
Expand Down Expand Up @@ -94,7 +94,7 @@ jobs:
password: ${{ secrets.PAT_CI_BOUNDLESS }}

- name: Download artifact
uses: actions/download-artifact@v3
uses: actions/download-artifact@v4
with:
name: ${{ env.IMAGE }}
path: /tmp
Expand Down Expand Up @@ -131,7 +131,7 @@ jobs:
password: ${{ secrets.PAT_CI_BOUNDLESS }}

- name: Download artifact
uses: actions/download-artifact@v3
uses: actions/download-artifact@v4
with:
name: ${{ env.IMAGE }}
path: /tmp
Expand Down
16 changes: 16 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,19 @@ name: Run Unit and Integration Tests

on:
workflow_call:
outputs:
coverage_artifact_url:
description: 'url of coverage artifact'
value: ${{ jobs.tests.outputs.artifact-url }}
push:
branches:
- 'main'

jobs:
tests:
runs-on: ubuntu-latest
outputs:
artifact-url: ${{ steps.artifact_upload.outputs.artifact-url }}
steps:
- name: Checkout
uses: actions/checkout@v3
Expand All @@ -24,6 +33,13 @@ jobs:
working-directory: .
run: make unit

- name: Archive code coverage results
uses: actions/upload-artifact@v4
id: artifact_upload
with:
name: code-coverage
path: coverage.*

- name: Run Integration Tests
working-directory: .
run: make integration
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ Dockerfile.cross
# Test binary, build with `go test -c`
*.test

# Output of the go coverage tool, specifically when used with LiteIDE
*.out
# Go test coverage files
coverage.html
coverage.txt

# Kubernetes Generated files - skip generated files, except for vendored files

Expand Down
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ test: unit integration ## Run unit and integration tests

.PHONY: unit
unit: manifests generate fmt vet ## Run unit tests.
go test $(UNIT_DIR) -coverprofile cover.out
go test $(UNIT_DIR) -coverprofile coverage.txt
go tool cover -html=coverage.txt -o coverage.html

.PHONY: integration
integration: manifests generate fmt vet envtest ginkgo ## Run integration tests.
Expand Down

0 comments on commit 5e91c51

Please sign in to comment.