Skip to content

Commit

Permalink
chore: adjust ut workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
BytePender committed Dec 16, 2024
1 parent 36cf3d5 commit b4d955b
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 3 deletions.
64 changes: 61 additions & 3 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,70 @@ jobs:
for module in $modules; do go work use $module; list=$module"/... "$list; coverpkg=$module"/...,"$coverpkg; done
go work sync
go test -race -coverprofile=coverage.out -gcflags="all=-l -N" -coverpkg=$coverpkg $list
# Download main (aka base) branch breakdown
- name: Download Artifact (main.breakdown)
id: download-main-breakdown
uses: dawidd6/action-download-artifact@v6
with:
branch: main
workflow_conclusion: success
name: main.breakdown
if_no_artifact_found: warn
- name: "Test Coverage"
uses: vladopajic/go-test-coverage@v2
with:
profile: coverage.out
threshold-total: 75
config: ./.testcoverage.yml
# Save current coverage breakdown if current branch is main. It will be
# uploaded as artifact in step below.
breakdown-file-name: ${{ github.ref_name == 'main' && 'main.breakdown' || '' }}

# If this is not main branch we want to show report including
# file coverage difference from main branch.
diff-base-breakdown-file-name: ${{ steps.download-main-breakdown.outputs.found_artifact && 'main.breakdown' || '' }}
- name: Upload Artifact (main.breakdown)
uses: actions/upload-artifact@v4
if: github.ref_name == 'main'
with:
name: main.breakdown
path: main.breakdown # as specified via `breakdown-file-name`
if-no-files-found: error
# Post coverage report as comment (in 3 steps)
- name: Find PR ID
run: |
PR_DATA=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
"https://api.github.com/repos/${{ github.repository }}/pulls?head=${{ github.repository_owner }}:${{ github.ref_name }}&state=open")
PR_ID=$(echo "$PR_DATA" | jq -r '.[0].number')
if [ "$PR_ID" != "null" ]; then
echo "pull_request_id=$PR_ID" >> $GITHUB_ENV
else
echo "No open pull request found for this branch."
fi
- name: find if coverage report is already present
if: env.pull_request_id
uses: peter-evans/find-comment@v3
id: fc
with:
issue-number: ${{ env.pull_request_id }}
comment-author: 'github-actions[bot]'
body-includes: 'go-test-coverage report:'
- name: post coverage report
if: env.pull_request_id
uses: peter-evans/create-or-update-comment@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
issue-number: ${{ env.pull_request_id }}
comment-id: ${{ steps.fc.outputs.comment-id }}
edit-mode: replace
body: |
go-test-coverage report:
```
${{ fromJSON(steps.coverage.outputs.report) }} ```
- name: "finally check coverage"
if: steps.coverage.outcome == 'failure'
shell: bash
run: echo "coverage check failed" && exit 1
unit-benchmark-test:
runs-on: ubuntu-latest
steps:
Expand Down
27 changes: 27 additions & 0 deletions .testcoverage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# (mandatory)
# Path to coverage profile file (output of `go test -coverprofile` command).
#
# For cases where there are many coverage profiles, such as when running
# unit tests and integration tests separately, you can combine all those
# profiles into one. In this case, the profile should have a comma-separated list
# of profile files, e.g., 'cover_unit.out,cover_integration.out'.
profile: cover.out

# (optional; but recommended to set)
# When specified reported file paths will not contain local prefix in the output.
local-prefix: "github.com/cloudwego/eino"

# Holds coverage thresholds percentages, values should be in range [0-100].
threshold:
# (optional; default 0)
# Minimum overall project coverage percentage required.
total: 75

# Holds regexp rules which will exclude matched files or packages
# from coverage statistics.
exclude:
# Exclude files or packages matching their paths
paths:
- "tests"
- "examples/"
- "mock/"

0 comments on commit b4d955b

Please sign in to comment.