aboutsummaryrefslogtreecommitdiff
path: root/public/templates/bash.template
blob: 08a591356bfa15b909afe33420536825ad5022df (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/usr/bin/env bash

# Licensed under Parity Public License 7.0.0
# The full version of this license can be found here:
# https://git.submelon.dev/kjhoerr/ao-coverage/raw/branch/trunk/LICENSE.md

url="{{TARGET_URL}}"
commit=""
branch=""
repo=""
format="tarpaulin"
report=""
token="$COV_TOKEN"

function verbose_say() {
  if [ -z "$QUIET" ] || [ "$VERBOSE" == "true" ]; then
    echo "$1"
  fi
}

verbose_say "==========================="
verbose_say "        ao-coverage        "
verbose_say "==========================="
verbose_say

verbose_say "Gathering report information . . ."

if [ "$CI" == "drone" ]; then
  verbose_say "Drone CI discovered - using Drone report info"
  commit="$DRONE_COMMIT"
  branch="$DRONE_BRANCH"
  repo="$DRONE_REPO"
else
  verbose_say "Using environment variables for report info"
  commit="$VCS_COMMIT"
  branch="$VCS_BRANCH"
  repo="$VCS_REPO"
fi

verbose_say "Using commit #: $commit"
verbose_say "Using branch: $branch"
verbose_say "Using repo: $repo"
verbose_say

if [ "$format" == "tarpaulin" ]; then
  report="${REPORT_FILE:-tarpaulin-report.html}"
fi

if [[ ! -f "$report" ]]; then
  echo "Report file could not be found."
  exit 1
fi

verbose_say "Uploading $report . . ."

response=$(curl -X POST --data-binary "@$report" \
  -H 'Content-Type: text/html' \
  "$url/v1/$repo/$branch/$commit.html?token=$token&format=$format")

if [ ! -z "$response" ]; then
  echo "Error uploading report: $response"
  exit 1
else
  echo "Successfully uploaded report!"
  verbose_say
  verbose_say "View uploaded report at: $url/v1/$repo/$branch/$commit.html"
  verbose_say "View coverage badge at: $url/v1/$repo/$branch/$commit.svg"
  verbose_say
  verbose_say "Shorthand links are also available, as the latest commit of this branch."
  verbose_say "View latest report for branch $branch: $url/v1/$repo/$branch.html"
  verbose_say "View latest badge for branch $branch: $url/v1/$repo/$branch.svg"
fi