Skip to content

Commit

Permalink
Use gimme
Browse files Browse the repository at this point in the history
  • Loading branch information
chaodaiG committed Sep 30, 2021
1 parent 198a5e0 commit 0a65c79
Show file tree
Hide file tree
Showing 5 changed files with 995 additions and 24 deletions.
30 changes: 13 additions & 17 deletions hack/build/setup-go.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,31 +13,27 @@
# See the License for the specific language governing permissions and
# limitations under the License.

set -o nounset
set -o errexit
set -o pipefail

# cd to the repo root and setup go
REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd -P)"
cd "${REPO_ROOT}"
# script to setup go version with gimme as needed
# MUST BE RUN FROM THE REPO ROOT DIRECTORY

# read go-version file unless GO_VERSION is set
GO_VERSION="${GO_VERSION:-"$(cat .go-version)"}"

# we don't actually care where the .env files are
# however, GIMME_SILENT_ENV doesn't trigger re-generating a .env if it
# already exists and isn't "silent" (no `go version` command in it)
# so we fix that by changing where the .env is written, ensuring ours
# is generated from this repo and silent.
export GIMME_ENV_PREFIX=./_bin/.gimme/
export GIMME_SILENT_ENV=y

# only setup go if we haven't set FORCE_HOST_GO, or `go version` doesn't match
# go version output looks like:
# go version go1.14.5 darwin/amd64
if ! ([ -n "${FORCE_HOST_GO:-}" ] ||
if ! ([ -n "${FORCE_HOST_GO:-}" ] || \
(command -v go >/dev/null && [ "$(go version | cut -d' ' -f3)" = "go${GO_VERSION}" ])); then

if ! (command -v gvm >/dev/null); then
apt-get install bison
bash -c "$(curl -s -S -L https://raw.githubusercontent.com/moovweb/gvm/master/binscripts/gvm-installer)"
source /root/.gvm/scripts/gvm
fi

gvm install go${GO_VERSION}
gvm use go${GO_VERSION}
# eval because the output of this is shell to set PATH etc.
eval "$(hack/third_party/gimme/gimme "${GO_VERSION}")"
fi

# force go modules
Expand Down
15 changes: 8 additions & 7 deletions hack/make-rules/go-test/unit.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,16 @@ cd 'hack/tools'
go build -o "${REPO_ROOT}/_bin/gotestsum" gotest.tools/gotestsum
cd "${REPO_ROOT}"

JUNIT_RESULT_DIR="${REPO_ROOT}/_output"
# if we are in CI, copy to the artifact upload location
if [[ -n "${ARTIFACTS:-}" ]]; then
JUNIT_RESULT_DIR="${ARTIFACTS}"
fi

# run unit tests with junit output
(
set -x;
mkdir -p "${REPO_ROOT}/_output"
"${REPO_ROOT}/_bin/gotestsum" --junitfile="${REPO_ROOT}/_output/unit-junit.xml" \
mkdir -p "${JUNIT_RESULT_DIR}"
"${REPO_ROOT}/_bin/gotestsum" --junitfile="${JUNIT_RESULT_DIR}/junit-unit.xml" \
-- './...'
)

# if we are in CI, copy to the artifact upload location
if [[ -n "${ARTIFACTS:-}" ]]; then
cp "_output/unit-junit.xml" "${ARTIFACTS:?}/unit-junit.xml"
fi
21 changes: 21 additions & 0 deletions hack/third_party/gimme/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2015-2018 gimme contributors

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
6 changes: 6 additions & 0 deletions hack/third_party/gimme/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# gimme

This is an unmodified copy of [gimme], so we don't have to download it
from the internet.

[gimme]: https://github.com/travis-ci/gimme
Loading

0 comments on commit 0a65c79

Please sign in to comment.