File: checks.bash

package info (click to toggle)
golang-golang-x-vuln 1.0.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 4,400 kB
  • sloc: sh: 161; asm: 40; makefile: 7
file content (73 lines) | stat: -rwxr-xr-x 1,585 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
73
#!/usr/bin/env bash
# Copyright 2021 The Go Authors. All rights reserved.
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.

# This file will be run by `go test`.
# See all_test.go in this directory.

# Ensure that installed go binaries are on the path.
# This bash expression follows the algorithm described at the top of
# `go install help`: first try $GOBIN, then $GOPATH/bin, then $HOME/go/bin.
go_install_dir=${GOBIN:-${GOPATH:-$HOME/go}/bin}
PATH=$PATH:$go_install_dir

source devtools/lib.sh

# check_shellcheck runs shellcheck on .bash and .sh files.
check_shellcheck() {
  if ! [ -x "$(command -v shellcheck)" ]; then
    echo "Please install shellcheck. See https://github.com/koalaman/shellcheck#installing."
  fi
  runcmd shellcheck -x checks.bash
  runcmd shellcheck ./**/*.sh
}

go_modtidy() {
  runcmd go mod tidy
}

# runchecks runs all checks and is intended to run as a precommit hook.
runchecks() {
  trybots "$@"

  # These checks only run locally due to a limitation with TryBots.
  check_shellcheck
}

# trybots runs checks supported by TryBots.
trybots() {
  go_modtidy
}

usage() {
  cat <<EOUSAGE
Usage: $0 [subcommand]
Available subcommands:
  help           - display this help message
EOUSAGE
}

main() {
  case "$1" in
    "-h" | "--help" | "help")
      usage
      exit 0
      ;;
    "")
      runchecks "$@"
      ;;
    trybots)
      trybots
      ;;
    *)
      usage
      exit 1
  esac
  if [[ "$EXIT_CODE" != 0 ]]; then
    err "FAILED; see errors above"
  fi
  exit "$EXIT_CODE"
}

main "$@"