github.com/rliebz/gometalinter@v2.0.2-0.20171206234108-d5a071029e07+incompatible/package.sh (about)

     1  #!/bin/bash -e
     2  
     3  # Only build packages for tagged releases
     4  TAG="$(git tag -l --points-at HEAD)"
     5  
     6  export CGO_ENABLED=0
     7  
     8  GO_VERSION="$(go version | awk '{print $3}' | cut -d. -f1-2)"
     9  
    10  if [ "$GO_VERSION" != "go1.9" ]; then
    11    echo "$0: not packaging; not on Go 1.9"
    12    exit 0
    13  fi
    14  
    15  if echo "$TAG" | grep -q '^v[0-9]\.[0-9]\.[0-9]\(-.*\)?$' && false; then
    16    echo "$0: not packaging; no tag or tag not in semver format"
    17    exit 0
    18  fi
    19  
    20  LINTERS="
    21    github.com/alecthomas/gocyclo
    22    github.com/alexkohler/nakedret
    23    github.com/client9/misspell/cmd/misspell
    24    github.com/dnephin/govet
    25    github.com/GoASTScanner/gas
    26    github.com/golang/lint/golint
    27    github.com/gordonklaus/ineffassign
    28    github.com/jgautheron/goconst/cmd/goconst
    29    github.com/kisielk/errcheck
    30    github.com/mdempsky/maligned
    31    github.com/mdempsky/unconvert
    32    github.com/mibk/dupl
    33    github.com/opennota/check/cmd/structcheck
    34    github.com/opennota/check/cmd/varcheck
    35    github.com/stripe/safesql
    36    github.com/tsenart/deadcode
    37    github.com/walle/lll/cmd/lll
    38    golang.org/x/tools/cmd/goimports
    39    golang.org/x/tools/cmd/gotype
    40    honnef.co/go/tools/cmd/gosimple
    41    honnef.co/go/tools/cmd/megacheck
    42    honnef.co/go/tools/cmd/staticcheck
    43    honnef.co/go/tools/cmd/unused
    44    mvdan.cc/interfacer
    45    mvdan.cc/unparam
    46  "
    47  
    48  eval "$(go env | FS='' awk '{printf "REAL_%s\n", $0}')"
    49  
    50  function install_go_binary() {
    51    local SRC
    52    if [ "$GOOS" = "$REAL_GOOS" -a "$GOARCH" = "$REAL_GOARCH" ]; then
    53      SRC="${GOPATH}/bin"
    54    else
    55      SRC="${GOPATH}/bin/${GOOS}_${GOARCH}"
    56    fi
    57    install -m 755 "${SRC}/${1}${SUFFIX}" "${2}"
    58  }
    59  
    60  function packager() {
    61    if [ "$GOOS" = "windows" ]; then
    62      zip -9 -r -o "${1}".zip "${1}"
    63    else
    64      tar cvfj "${1}".tar.bz2 "${1}"
    65    fi
    66  }
    67  
    68  rm -rf "${PWD}/dist"
    69  
    70  for GOOS in linux darwin windows; do
    71    SUFFIX=""
    72    if [ "$GOOS" = "windows" ]; then
    73      SUFFIX=".exe"
    74    fi
    75  
    76    for GOARCH in 386 amd64; do
    77      export GOPATH="${REAL_GOPATH}"
    78      DEST="${PWD}/dist/gometalinter-${TAG}-${GOOS}-${GOARCH}"
    79      install -d -m 755 "${DEST}/linters"
    80      install -m 644 COPYING "${DEST}"
    81      cat << EOF > "${DEST}/README.txt"
    82  gometalinter is a tool to normalise the output of Go linters.
    83  See https://github.com/alecthomas/gometalinter for more information.
    84  
    85  This is a binary distribution of gometalinter ${TAG}.
    86  
    87  All binaries must be installed in the PATH for gometalinter to operate correctly.
    88  EOF
    89      echo "${DEST}"
    90      export GOOS GOARCH
    91  
    92      go build -i .
    93      go build -o "${DEST}/gometalinter${SUFFIX}" -ldflags="-X main.Version=${TAG}" .
    94  
    95      export GOPATH="$PWD/_linters"
    96  
    97      go install -v ${LINTERS}
    98      for LINTER in ${LINTERS}; do
    99        install_go_binary $(basename ${LINTER}) "${DEST}/linters"
   100      done
   101  
   102      (cd "${DEST}/.." && packager "$(basename ${DEST})")
   103    done
   104  done