File: code-climate.sh

package info (click to toggle)
ruby-nokogiri 1.11.1%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 5,576 kB
  • sloc: xml: 28,086; ruby: 18,456; java: 13,067; ansic: 5,138; yacc: 265; sh: 208; makefile: 27
file content (72 lines) | stat: -rw-r--r-- 1,662 bytes parent folder | download
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
#
#  Source this file to have access to two functions:
#
#    code-climate-setup
#
#      * downloads the CC CLI
#      * sets up CC environment variables
#      * invokes CC's `before-build`
#
#
#    code-climate-shipit
#
#      * invokes CC's `after-build`
#
#  Note that the env var CC_TEST_REPORTER_ID will need to be set. You
#  can find this on your Code Climate project's "Repo Settings" page.
#

CC_CLI_URI="https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64"
CC_CLI=$(basename ${CC_CLI_URI})

function code-climate-setup {
  save-option-xtrace-off

  if [ -z "${CC_TEST_REPORTER_ID:-}" ] ; then
    echo "WARNING: code-climate-setup: CC_TEST_REPORTER_ID is not set, skipping."
  else
    wget --no-verbose ${CC_CLI_URI}
    chmod +x ${CC_CLI}

    export CI_NAME="concourse"

    ./${CC_CLI} env || true
    ./${CC_CLI} before-build || true
  fi

  restore-option-xtrace
}

function code-climate-shipit {
  save-option-xtrace-off

  if [ -z "${CC_TEST_REPORTER_ID:-}" ] ; then
    echo "WARNING: code-climate-shipit: CC_TEST_REPORTER_ID is not set, skipping."
  else
    ./${CC_CLI} after-build || true
  fi

  restore-option-xtrace
}


#
#  utilities to save and restore the `xtrace` setting so we don't leak credentials
#  https://unix.stackexchange.com/questions/310957/how-to-restore-the-value-of-shell-options-like-set-x/310963
#
OLD_OPTION_XTRACE=""

function save-option-xtrace {
  OLD_OPTION_XTRACE="$(shopt -po xtrace)"
  set +x
}

function save-option-xtrace-off {
  save-option-xtrace
  set +x
}

function restore-option-xtrace {
  set +vx # suppress the following eval statement
  eval "${OLD_OPTION_XTRACE}"
}