...

Text file src/github.com/golang/mock/ci/test.sh

Documentation: github.com/golang/mock/ci

     1#!/bin/bash
     2# This script is used to ensure that the go.mod file is up to date.
     3
     4set -euo pipefail
     5
     6if [[ $(go version) != *"go1.18"* ]]; then
     7  exit 0
     8fi
     9
    10for i in $(find $PWD -name go.mod); do
    11  pushd $(dirname $i)
    12  go mod tidy
    13  popd
    14done
    15
    16if [ ! -z "$(git status --porcelain)" ]; then
    17  git status
    18  git diff
    19  echo
    20  echo "The go.mod is not up to date."
    21  exit 1
    22fi
    23
    24BASE_DIR="$PWD"
    25TEMP_DIR=$(mktemp -d)
    26function cleanup() {
    27  rm -rf "${TEMP_DIR}"
    28}
    29trap cleanup EXIT
    30
    31cp -r . "${TEMP_DIR}/"
    32cd $TEMP_DIR
    33
    34for i in $(find $PWD -name go.mod); do
    35  pushd $(dirname $i)
    36  go generate ./...
    37  popd
    38done
    39
    40if ! diff -r . "${BASE_DIR}"; then
    41  echo
    42  echo "The generated files aren't up to date."
    43  echo "Update them with the 'go generate ./...' command."
    44  exit 1
    45fi

View as plain text