Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Diff code coverage of different branchs using codecov app #2310

Merged
merged 12 commits into from
Nov 1, 2024
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 [ ! -z "${{ inputs.volume }}" ]; then
bettinaheim marked this conversation as resolved.
Show resolved Hide resolved
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::"
37 changes: 36 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,26 @@ jobs:
# needed only for the cloudposse GitHub action
matrix_key: ${{ matrix.platform }}-python

ccovdeps:
bettinaheim marked this conversation as resolved.
Show resolved Hide resolved
name: Load code coverage dependencies
needs: metadata
strategy:
matrix:
platform: [amd64]
toolchain: [clang16]
fail-fast: false
uses: ./.github/workflows/dev_environment.yml
secrets:
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
DOCKERHUB_READONLY_TOKEN: ${{ secrets.DOCKERHUB_READONLY_TOKEN }}
with:
platforms: linux/${{ matrix.platform }}
dockerfile: build/devdeps.Dockerfile
toolchain: ${{ matrix.toolchain }}
registry_cache_from: ${{ inputs.cache_base || needs.metadata.outputs.cache_base }}
# needed only for the cloudposse GitHub action
matrix_key: ${{ matrix.platform }}-${{ matrix.toolchain }}-cc

source_build:
name: Load source build cache
needs: metadata
Expand Down Expand Up @@ -151,7 +171,7 @@ jobs:
config:
name: Configure build
runs-on: ubuntu-latest
needs: [devdeps, wheeldeps, source_build]
needs: [devdeps, wheeldeps, ccovdeps, source_build]

outputs:
json: "${{ steps.read_json.outputs.result }}"
Expand Down Expand Up @@ -185,6 +205,21 @@ 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
with:
platform: linux/${{ matrix.platform }}
devdeps_cache: ${{ fromJson(needs.config.outputs.json).cache_key[format('{0}-{1}-cc', matrix.platform, matrix.toolchain)] }}
devdeps_archive: ${{ fromJson(needs.config.outputs.json).tar_archive[format('{0}-{1}-cc', matrix.platform, matrix.toolchain)] }}
export_environment: ${{ github.event_name == 'workflow_dispatch' && inputs.export_environment }}
bettinaheim marked this conversation as resolved.
Show resolved Hide resolved

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


name: Show Code Coverage Diff

jobs:
gen_code_coverage:
runs-on: 'linux-amd64-cpu8'
permissions:
contents: read

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

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

- 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: |
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`
devdeps_tag=`echo $base_image | rev | cut -d ":" -f 1 | rev`
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
tag_prefix=`echo $devdeps_tag | cut -d "_" -f 1`
echo "tag_prefix=$tag_prefix" >> $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.tag_prefix }}_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
Loading