|
1 | 1 | #!/bin/sh |
2 | 2 |
|
| 3 | +# Publish an already-generated coverage report from dd-trace-cpp to |
| 4 | +# dd-trace-cpp-coverage. |
| 5 | +# |
| 6 | +# Overall, here's what we're going to do: |
| 7 | +# |
| 8 | +# Clone as little of the dd-trace-cpp-coverage repository as we can manage. |
| 9 | +# Then, move the rendered coverage report from dd-trace-cpp into a specially |
| 10 | +# named location in dd-trace-cpp-coverage. Commit and push. |
| 11 | + |
| 12 | +set -x |
3 | 13 | set -e |
4 | 14 |
|
5 | | -cd "$(dirname "$0")"/.. |
6 | | - |
7 | | -# See <https://unix.stackexchange.com/a/155077> |
8 | | -if output=$(git status --porcelain) && [ -z "$output" ]; then |
9 | | - : # Working directory clean |
10 | | -else |
11 | | - >&2 echo 'Commit or stash changes to the working tree before running this script.' |
12 | | - >&2 echo 'See `git status` for more info.' |
13 | | - exit 1 |
14 | | -fi |
15 | | - |
16 | | -bin/test --coverage |
17 | | -git switch gh-pages |
18 | | -cp -r .coverage/report/* . |
19 | | -git add -A |
20 | | -git commit -m 'update testing code coverage report' |
| 15 | +tracer_dir=$(pwd) |
| 16 | +temp_dir=$(mktemp -d) |
| 17 | + |
| 18 | +echo "Using temporary directory: $temp_dir" |
| 19 | +cd "$temp_dir" |
| 20 | + |
| 21 | +# Clone directory structure of the most recent commit of one |
| 22 | +# branch (main). Don't fetch any regular files. |
| 23 | +mkdir dd-trace-cpp-coverage |
| 24 | +cd dd-trace-cpp-coverage |
| 25 | + |
| 26 | +git init |
| 27 | + |
| 28 | +git config user.email "[email protected]" |
| 29 | +git config user.name "David Goffredo (via script)" |
| 30 | + |
| 31 | +git remote add origin '[email protected]:DataDog/dd-trace-cpp-coverage.git' |
| 32 | +branch=gh-pages |
| 33 | +git fetch --depth=1 --filter=blob:none origin "$branch" |
| 34 | + |
| 35 | +# "Sparse checkout" some subdirectory of the repo root. |
| 36 | +# The leaves above and below that directory will be fetched, |
| 37 | +# but its sibling directories will not. |
| 38 | +git sparse-checkout set dummy/ |
| 39 | +git checkout "$branch" |
| 40 | + |
| 41 | +# e.g. "2022-12-29 22:09:54 UTC (6c6e440)" |
| 42 | +coverage_report_name() { |
| 43 | + commit_time_iso=$(git show -s --format=%cI) |
| 44 | + commit_hash_short=$(git rev-parse HEAD | head -c 7) |
| 45 | + |
| 46 | + date "--date=$commit_time_iso" --iso-8601=seconds --utc | \ |
| 47 | + sed -e 's/T/ /' -e "s/+.*/ UTC ($commit_hash_short)/" |
| 48 | +} |
| 49 | + |
| 50 | +cd "$tracer_dir" |
| 51 | +report_name=$(coverage_report_name) |
| 52 | +mv .coverage/report "$temp_dir/dd-trace-cpp-coverage/$report_name" |
| 53 | + |
| 54 | +cd "$temp_dir/dd-trace-cpp-coverage" |
| 55 | +git add -A --sparse |
| 56 | +git commit -m "add $report_name" |
21 | 57 | git push |
22 | | -git switch - |
|
0 commit comments