|
| 1 | +#!/bin/sh |
| 2 | + |
| 3 | +set -e |
| 4 | + |
| 5 | +if [ -z "${IMPORT}" ]; then |
| 6 | + IMPORT="${GITHUB_REPOSITORY}" |
| 7 | +fi |
| 8 | +WORKDIR="${GOPATH}/src/github.com/${IMPORT}" |
| 9 | + |
| 10 | +# PROJECT_PATH specifies the subdirectory in the working directory that the Go project is |
| 11 | +if [ -z "${PROJECT_PATH}" ]; then |
| 12 | + PROJECT_PATH="." |
| 13 | +fi |
| 14 | + |
| 15 | +# Go can only find dependencies if they're under $GOPATH/src. |
| 16 | +# GitHub Actions mounts your repository outside of $GOPATH. |
| 17 | +# So symlink the repository into $GOPATH, and then cd to it. |
| 18 | +mkdir -p "$(dirname "${WORKDIR}")" |
| 19 | +ln -s "${PWD}" "${WORKDIR}" |
| 20 | +cd "${WORKDIR}/${PROJECT_PATH}" |
| 21 | + |
| 22 | +# If a command was specified with `args="..."`, then run it. Otherwise, |
| 23 | +# look for something useful to run. |
| 24 | +if [ $# -eq 0 ] || [ "$*" = "" ]; then |
| 25 | + if [ -r Makefile ]; then |
| 26 | + make |
| 27 | + else |
| 28 | + if [ -r go.mod ]; then |
| 29 | + export GO111MODULE=on |
| 30 | + # Check if using vendored dependencies |
| 31 | + if [ -d "vendor" ]; then |
| 32 | + export GOFLAGS="-mod=vendor" |
| 33 | + else |
| 34 | + # Ensure no go.mod changes are made that weren't committed |
| 35 | + export GOFLAGS="-mod=readonly" |
| 36 | + fi |
| 37 | + else |
| 38 | + if [ -r Gopkg.toml ]; then |
| 39 | + # Check if using vendored dependencies |
| 40 | + if [ -d "vendor" ]; then |
| 41 | + # Check that dep is in sync with /vendor dependencies and that running dep ensure doesn't result in modifications to Gopkg.lock/Gopkg.toml |
| 42 | + "$GOPATH/bin/dep" ensure && "$GOPATH/bin/dep" check |
| 43 | + git_workspace_status="$(git status --porcelain)" |
| 44 | + if [ -n "${git_workspace_status}" ]; then |
| 45 | + echo "Unexpected changes were found in dep /vendored. Please run $(dep ensure) and commit changes:"; |
| 46 | + echo "${git_workspace_status}"; |
| 47 | + exit 1; |
| 48 | + fi |
| 49 | + else |
| 50 | + # Run dep ensure to download and sync dependencies |
| 51 | + "$GOPATH/bin/dep" ensure |
| 52 | + fi |
| 53 | + fi |
| 54 | + fi |
| 55 | + go build ./... |
| 56 | + go test ./... |
| 57 | + fi |
| 58 | +else |
| 59 | + sh -c "$*" |
| 60 | +fi |
0 commit comments