Skip to content

Commit

Permalink
Diff code coverage of different branchs using codecov app (#2310)
Browse files Browse the repository at this point in the history
Signed-off-by: huaweil <[email protected]>
Signed-off-by: Bettina Heim <[email protected]>
Co-authored-by: Bettina Heim <[email protected]>
  • Loading branch information
actione and bettinaheim authored Nov 1, 2024
1 parent a9e2324 commit 1ca93a3
Show file tree
Hide file tree
Showing 5 changed files with 315 additions and 85 deletions.
12 changes: 11 additions & 1 deletion .github/actions/run-in-docker/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ inputs:
shell:
default: "bash"
required: false
# Adding a new optional parameter for directory mapping
volume:
default: ""
required: false

runs:
using: "composite"
Expand All @@ -21,6 +25,12 @@ runs:
then additional_run_args="--gpus all"
fi
# Check if a volume mapping is specified and set the option
volume_option=""
if [ -n "${{ inputs.volume }}" ]; then
volume_option="-v ${{ inputs.volume }}"
fi
# Note: "bash -s << EOF" does not play nice with mpirun/mpiexec. It
# silently skips any shell commands that come after the mpirun/mpiexec,
# so don't use it. Use this instead, which seems to work better.
Expand All @@ -29,7 +39,7 @@ runs:
${{ inputs.run }}
EOF
container=$(docker run --user ${{ inputs.user }} $additional_run_args -id ${{ inputs.image }})
container=$(docker run --user ${{ inputs.user }} $additional_run_args $volume_option -id ${{ inputs.image }})
docker cp $tmpFile $container:$tmpFile
docker exec --user root $container chown -R ${{ inputs.user }} $tmpFile
docker exec $container ${{ inputs.shell }} $tmpFile
Expand Down
10 changes: 10 additions & 0 deletions .github/codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
coverage:
status:
project:
default:
target: 70%
threshold: 1%
ignore:
- "tpls"
fixes:
- "/workspaces/cuda-quantum::"
18 changes: 18 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,24 @@ jobs:
devdeps_archive: ${{ fromJson(needs.config.outputs.json).tar_archive[format('{0}-{1}', matrix.platform, matrix.toolchain)] }}
export_environment: ${{ github.event_name == 'workflow_dispatch' && inputs.export_environment }}

gen_code_coverage:
name: Gen code coverage
needs: config
strategy:
matrix:
platform: [amd64]
toolchain: [clang16]
fail-fast: false
uses: ./.github/workflows/generate_cc.yml
secrets:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
with:
platform: linux/${{ matrix.platform }}
devdeps_image: ${{ fromJson(needs.config.outputs.json).image_hash[format('{0}-{1}', matrix.platform, matrix.toolchain)] }}
devdeps_cache: ${{ fromJson(needs.config.outputs.json).cache_key[format('{0}-{1}', matrix.platform, matrix.toolchain)] }}
devdeps_archive: ${{ fromJson(needs.config.outputs.json).tar_archive[format('{0}-{1}', matrix.platform, matrix.toolchain)] }}
export_environment: ${{ github.event_name == 'workflow_dispatch' && inputs.export_environment }}

docker_image:
name: Create Docker images
needs: config
Expand Down
135 changes: 135 additions & 0 deletions .github/workflows/generate_cc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
on:
workflow_call:
inputs:
platform:
type: string
required: false
default: linux/amd64
devdeps_image:
required: false
type: string
devdeps_cache:
required: true
type: string
devdeps_archive:
required: true
type: string
export_environment:
required: false
type: boolean
secrets:
CODECOV_TOKEN:
required: false

name: Show Code Coverage Diff

jobs:
gen_code_coverage:
runs-on: ${{ (contains(inputs.platform, 'arm') && 'linux-arm64-cpu8') || 'linux-amd64-cpu8' }}
permissions:
contents: read
packages: read

steps:
- name: Checkout Repository
uses: actions/checkout@v4

- name: Restore environment
id: restore_devdeps
if: inputs.devdeps_image == ''
uses: actions/cache/restore@v4
with:
path: ${{ inputs.devdeps_archive }}
key: ${{ inputs.devdeps_cache }}
fail-on-cache-miss: true

- name: Log in to GitHub CR
if: inputs.devdeps_image != ''
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ github.token }}

- name: Set up context for buildx
run: |
docker context create builder_context
- name: Set up buildx runner
uses: docker/setup-buildx-action@v3
with:
endpoint: builder_context

- name: Build CUDA Quantum
id: cudaq_build
run: |
if ${{ steps.restore_devdeps.outcome != 'skipped' }}; then
load_output=`docker load --input "${{ inputs.devdeps_archive }}"`
base_image=`echo "$load_output" | grep -o 'Loaded image: \S*:\S*' | head -1 | cut -d ' ' -f 3`
elif ${{ inputs.devdeps_image != '' }}; then
base_image=${{ inputs.devdeps_image }}
else
echo "::error file=generate_cc.yml::Missing configuration for development dependencies. Either specify the image (i.e. provide devdeps_image) or cache (i.e. provide devdeps_cache and devdeps_archive) that should be used for the build."
exit 1
fi
DOCKER_BUILDKIT=1 docker build --platform ${{ inputs.platform }} \
-t cuda-quantum-cc:local -f docker/build/cudaq.dev.Dockerfile . \
--build-arg base_image=$base_image
devdeps_tag=`echo $base_image | rev | cut -d ":" -f 1 | rev`
echo "devdeps_tag=$devdeps_tag" >> $GITHUB_OUTPUT
- name: Create Shared Dir
run: |
mkdir -p ${{ github.workspace }}/shared
- name: Test CUDA Quantum And Generate CC
uses: ./.github/actions/run-in-docker
with:
image: cuda-quantum-cc:local
shell: bash
volume: ${{ github.workspace }}/shared:/shared
run: |
cd $CUDAQ_REPO_ROOT
bash scripts/generate_cc.sh -v -c -p
if [ ! $? -eq 0 ]; then
echo "generate_cc status = " $?
else
chmod -R 777 ./build/ccoverage
chmod -R 777 ./build/pycoverage
cp ./build/ccoverage/coverage.txt /shared
cp ./build/pycoverage/coverage.xml /shared
fi
- name: Upload C/C++ & Python Coverage To Codecov
uses: codecov/codecov-action@v4
with:
fail_ci_if_error: false
files: ${{ github.workspace }}/shared/coverage.txt,${{ github.workspace }}/shared/coverage.xml
token: ${{ secrets.CODECOV_TOKEN }}
verbose: true

- name: Delete Shared Dir
run: |
rm -r ${{ github.workspace }}/shared
- name: Save environment
id: env_save
if: inputs.export_environment
run: |
output_directory=/tmp
filename=${{ steps.cudaq_build.outputs.devdeps_tag }}_cc_build
docker run --name cuda-quantum-cc cuda-quantum-cc:local
docker export cuda-quantum-cc > $output_directory/$filename.tar
docker rm -f cuda-quantum-cc
echo "filename=$filename" >> $GITHUB_OUTPUT
echo "output_directory=$output_directory" >> $GITHUB_OUTPUT
- name: Upload environment
uses: actions/upload-artifact@v4
if: inputs.export_environment
with:
name: ${{ steps.env_save.outputs.filename }}
path: ${{ steps.env_save.outputs.output_directory }}/${{ steps.env_save.outputs.filename }}.tar
retention-days: 1
Loading

0 comments on commit 1ca93a3

Please sign in to comment.