github.com/cockroachdb/pebble@v1.1.2/scripts/code-coverage-publish.sh (about)

     1  #!/bin/bash
     2  
     3  # This script runs genhtml (part of lcov) on lcov artifacts generated by the
     4  # code-coverage.sh script and uploads the result to a GCS bucket.
     5  
     6  BUCKET="${BUCKET:-crl-codecover-public}"
     7  
     8  set -euxo pipefail
     9  
    10  publish() {
    11    PROFILE="$1"
    12    TITLE="$2"
    13  
    14    if [ ! -f "$PROFILE" ]; then
    15      echo "$PROFILE does not exist"
    16      exit 1
    17    fi
    18  
    19    DIR="$(date -r "$PROFILE" -u '+%Y-%m-%d %H:%MZ') $(git rev-parse --short=8 HEAD) - $TITLE"
    20  
    21    mkdir -p "artifacts/$DIR"
    22    # The filename shows up on the generated page, let's make it useful.
    23    cp "$PROFILE" "artifacts/$DIR.lcov"
    24    genhtml "artifacts/$DIR.lcov" -o "artifacts/$DIR"
    25  
    26    gsutil -m cp -Z -r "artifacts/$DIR" "gs://$BUCKET/pebble/$DIR"
    27  }
    28  
    29  publish "artifacts/profile-tests.lcov" "tests only"
    30  publish "artifacts/profile-meta.lcov" "meta test only"
    31  publish "artifacts/profile-tests-and-meta.lcov" "tests + meta"
    32  
    33  # Regenerate index.html.
    34  echo '<title>Pebble coverage</title><body><h2>Pebble coverage runs:</h2><ul>' > artifacts/index.html
    35  gsutil ls "gs://$BUCKET/pebble" |
    36    sed "s#gs://$BUCKET/pebble/##" |
    37    sed 's#/$##' |
    38    grep -v index.html |
    39    sort -r |
    40    while read -r d; do
    41      echo "<li><a href=\"$d/index.html\">$d</a>" >> artifacts/index.html
    42    done
    43  
    44  echo '</ul></body>' >> artifacts/index.html
    45  
    46  gsutil cp artifacts/index.html "gs://$BUCKET/pebble/index.html"
    47  gsutil setmeta -h "Cache-Control: public, max-age=300, no-transform" "gs://$BUCKET/pebble/index.html"