Skip to content

Commit

Permalink
CI: generate coverage report for multiple jobs. (#5436)
Browse files Browse the repository at this point in the history
  • Loading branch information
zhoucheng361 authored Dec 25, 2024
1 parent 066ac4f commit c743889
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 13 deletions.
14 changes: 7 additions & 7 deletions .github/actions/mount-coverage-dir/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@ runs:
branch=${GITHUB_REF#refs/heads/} # 对于 schedule 和 workflow_dispatch
fi
echo input.subdir is ${{inputs.subdir}}
if [ -z "${{inputs.subdir}}" ]; then
if [[ "${{github.event_name}}" == "schedule" ]]; then
subdir=juicefs/schedule/$(date +"%Y%m%d")/${{github.workflow}}
else
subdir=juicefs/pr/$branch/${{github.workflow}}/${job_id}
fi
else
if [ -n "${{inputs.subdir}}" ]; then
subdir=${{inputs.subdir}}
elif [[ "${{github.event_name}}" == "schedule" ]]; then
subdir=juicefs/schedule/$(date +"%Y%m%d")/${{github.workflow}}
elif [[ "${{github.job}}" == "success-all-test" ]]; then
subdir=juicefs/pr/$branch/${{github.workflow}}/${{github.run_id}}
else
subdir=juicefs/pr/$branch/${{github.workflow}}/${{github.run_id}}/${job_id}
fi
echo "subdir=$subdir"
echo "subdir=$subdir" >> $GITHUB_ENV
Expand Down
14 changes: 12 additions & 2 deletions .github/actions/upload-coverage/action.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: 'upload_coverage_report'
description: 'upload coverage report to oss'
description: 'upload coverage report of one job'
inputs:
type:
description: 'type of the test'
Expand All @@ -21,6 +21,16 @@ runs:
sudo umount /tmp/jfs || true
sleep 3s
- name: get job id
shell: bash
env:
GH_TOKEN: ${{ github.token }}
run: |
jobs=$(gh api repos/${{ github.repository }}/actions/runs/${{ github.run_id}}/attempts/${{ github.run_attempt }}/jobs)
job_id=$(echo $jobs | jq -r '.jobs[] | select(.runner_name=="${{ runner.name }}") | select(.status=="in_progress") | .id')
echo Job ID is: ${job_id}
echo "job_id=$job_id" >> $GITHUB_ENV
- name: generate mount coverage report
shell: bash
run: |
Expand All @@ -30,4 +40,4 @@ runs:
sudo go tool covdata textfmt -i=cover/ -o cover/cover.txt
echo "generate coverage html report"
sudo go tool cover -html=cover/cover.txt -o cover/cover.html
.github/scripts/upload_coverage_report.sh cover/cover.html juicefs_${{github.workflow}}_${{github.run_id}}.html ${{inputs.UPLOAD_TOKEN}}
.github/scripts/upload_coverage_report.sh cover/cover.html juicefs_${{github.workflow}}_${{github.run_id}}_${job_id}.html ${{inputs.UPLOAD_TOKEN}}
42 changes: 42 additions & 0 deletions .github/actions/upload-total-coverage/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: 'upload_total_coverage_report'
description: 'upload total coverage report of all jobs in workflow'
inputs:
type:
description: 'type of the test'
required: true
default: 'integration'
type: string

UPLOAD_TOKEN:
description: 'upload token'
required: true
type: string

runs:
using: "composite"
steps:
- name: generate coverage report
working-directory: cover
shell: bash
run: |
echo "current dir is $(pwd)"
coverdirs=""
for dir in $(find . -mindepth 1 -maxdepth 1 -type d -exec basename {} \;); do
coverdirs+="$dir/,"
done
coverdirs=${coverdirs%,}
echo coverdirs is $coverdirs
[[ -z "$coverdirs" ]] && echo "no coverage dir found" && exit 1
sudo go tool covdata percent -i=$coverdirs | sudo tee cover.percent
echo "generated coverage percent report:" $(realpath cover.percent)
sudo go tool covdata textfmt -o cover.txt -i=$coverdirs
echo "generated coverage report in text format:" $(realpath cover.txt)
sudo go tool cover -html=cover.txt -o cover.html
echo "generated coverage report in html format:" $(realpath cover.html)
ls -l cover*
- name: upload coverage report
shell: bash
run: |
.github/scripts/upload_coverage_report.sh cover/cover.html ${{github.workflow}}_${{github.run_id}}.html ${{inputs.UPLOAD_TOKEN}}
9 changes: 5 additions & 4 deletions .github/workflows/coverage-report.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
fail-fast: false
matrix:
branch: ['main']
test: ['it']
test: ['ut', 'it', 'all']

timeout-minutes: 60
runs-on: ubuntu-22.04
Expand Down Expand Up @@ -76,11 +76,11 @@ jobs:
coverdirs=""
for dir in $(find . -mindepth 1 -maxdepth 1 -type d -exec basename {} \;); do
if [[ ${{matrix.test}} == "ut" ]]; then
if [[ "$dir" == "unit-test" || "$dir" == "unit-random-test" ]]; then
if [[ "$dir" == "unittests" ]]; then
coverdirs+="$dir,"
fi
elif [[ ${{matrix.test}} == "it" ]]; then
if [[ "$dir" != "unit-test" && "$dir" != "unit-random-test" ]]; then
if [[ "$dir" != "unittests" ]]; then
coverdirs+="$dir,"
fi
elif [[ ${{matrix.test}} == "all" ]]; then
Expand All @@ -89,7 +89,7 @@ jobs:
done
coverdirs=${coverdirs%,}
echo coverdirs is $coverdirs
[[ -z "$coverdirs" ]] && echo "no coverage dir found" && exit 1
[[ -z "$coverdirs" ]] && echo "no coverage dir found" && exit 0
name=cover_${{matrix.test}}
sudo go tool covdata percent -i=$coverdirs | sudo tee ${name}.percent
echo "generated coverage percent report:" $(realpath ${name}.percent)
Expand All @@ -104,6 +104,7 @@ jobs:
timeout-minutes: 10
run: |
echo "current dir is $(pwd)"
[[ ! -f "cover_${{matrix.test}}.html" ]] && echo "no coverage report found" && exit 0
UPLOAD_PATH=${{github.workflow}}_${{github.run_id}}_${{matrix.test}}.html
response=$(curl -w '%{http_code}' -s -o /dev/null --form 'file=@cover_${{matrix.test}}.html' https://juicefs.com/upload-file-u80sdvuke/${UPLOAD_PATH}?token=${{secrets.CI_COVERAGE_FILE_UPLOAD_AUTH_TOKEN}})
if [ "$response" -eq 200 ]; then
Expand Down
15 changes: 15 additions & 0 deletions .github/workflows/sync.yml
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,21 @@ jobs:
- name: Check Failure
if: env.WORKFLOW_CONCLUSION == 'failure'
run: exit 1

- name: mount coverage dir
timeout-minutes: 5
uses: ./.github/actions/mount-coverage-dir
with:
mount_point: cover
access_key: ${{ secrets.CI_COVERAGE_AWS_AK }}
secret_key: ${{ secrets.CI_COVERAGE_AWS_SK }}
token: ${{ secrets.CI_COVERAGE_AWS_TOKEN }}

- name: upload total coverage report
timeout-minutes: 5
uses: ./.github/actions/upload-total-coverage
with:
UPLOAD_TOKEN: ${{ secrets.CI_COVERAGE_FILE_UPLOAD_AUTH_TOKEN }}

- name: Send Slack Notification
if: failure() && github.event_name != 'workflow_dispatch'
Expand Down

0 comments on commit c743889

Please sign in to comment.