travis: refresh runtests.sh and Travis config (#174)

This commit is contained in:
Robert van Gent
2019-05-14 11:31:53 -07:00
committed by GitHub
parent c1a359a7ca
commit c1be6ec0d8
6 changed files with 165 additions and 41 deletions

View File

@@ -12,14 +12,8 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
os:
- linux
- osx
- windows
language: go language: go
go_import_path: github.com/google/wire go_import_path: github.com/google/wire
go: "1.11.x"
before_install: before_install:
# The Bash that comes with OS X is ancient. # The Bash that comes with OS X is ancient.
@@ -34,13 +28,8 @@ before_install:
install: install:
# Re-checkout files preserving line feeds. This prevents Windows builds from # Re-checkout files preserving line feeds. This prevents Windows builds from
# converting \n to \r\n. # converting \n to \r\n.
- if [[ "$TRAVIS_OS_NAME" == "windows" ]]; then - "git config --global core.autocrlf input"
cd ../..; - "git checkout -- ."
mv $TRAVIS_REPO_SLUG _old;
git config --global core.autocrlf false;
git clone _old $TRAVIS_REPO_SLUG;
cd $TRAVIS_REPO_SLUG;
fi
script: script:
- 'internal/runtests.sh' - 'internal/runtests.sh'
@@ -48,3 +37,19 @@ script:
env: env:
global: global:
- GO111MODULE=on - GO111MODULE=on
- GOPROXY=https://proxy.golang.org
# When updating Go versions:
# In addition to changing the "go:" versions below, edit the version
# test in internal/runtests.sh.
jobs:
include:
- go: "1.11.x"
os: linux
- go: "1.12.x"
os: linux
- go: "1.12.x"
os: osx
- go: "1.12.x"
os: windows

3
go.mod
View File

@@ -3,8 +3,5 @@ module github.com/google/wire
require ( require (
github.com/google/go-cmp v0.2.0 github.com/google/go-cmp v0.2.0
github.com/pmezard/go-difflib v1.0.0 github.com/pmezard/go-difflib v1.0.0
golang.org/x/crypto v0.0.0-20190422183909-d864b10871cd // indirect
golang.org/x/net v0.0.0-20190420063019-afa5a82059c6 // indirect
golang.org/x/sys v0.0.0-20190422165155-953cdadca894 // indirect
golang.org/x/tools v0.0.0-20190422233926-fe54fb35175b golang.org/x/tools v0.0.0-20190422233926-fe54fb35175b
) )

9
go.sum
View File

@@ -3,17 +3,8 @@ github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5a
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20190422183909-d864b10871cd/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190420063019-afa5a82059c6/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/tools v0.0.0-20181017214349-06f26fdaaa28 h1:vnbqcYKfOxPnXXUlBo7t+R4pVIh0wInyOSNxih1S9Dc=
golang.org/x/tools v0.0.0-20181017214349-06f26fdaaa28/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190205201329-379209517ffe h1:wgpl8ZFbbyCTwUEyUPYafSzqRqUUGAuN9JSXU9iBjts=
golang.org/x/tools v0.0.0-20190205201329-379209517ffe/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190422233926-fe54fb35175b h1:NVD8gBK33xpdqCaZVVtd6OFJp+3dxkXuz7+U7KaVN6s= golang.org/x/tools v0.0.0-20190422233926-fe54fb35175b h1:NVD8gBK33xpdqCaZVVtd6OFJp+3dxkXuz7+U7KaVN6s=
golang.org/x/tools v0.0.0-20190422233926-fe54fb35175b/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= golang.org/x/tools v0.0.0-20190422233926-fe54fb35175b/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=

96
internal/check_api_change.sh Executable file
View File

@@ -0,0 +1,96 @@
#!/usr/bin/env bash
# Copyright 2019 The Wire Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# This script checks to see if there are any incompatible API changes on the
# current branch relative to the upstream branch.
# It fails if it finds any, unless there is a commit with BREAKING_CHANGE_OK
# in the first line of the commit message.
# This script expects:
# a) to be run at the root of the repository
# b) HEAD is pointing to a commit that merges between the pull request and the
# upstream branch (TRAVIS_BRANCH). This is what Travis does (see
# https://docs.travis-ci.com/user/pull-requests/ for details), but if you
# are testing this script manually, you may need to manually create a merge
# commit.
set -euo pipefail
UPSTREAM_BRANCH="${TRAVIS_BRANCH:-master}"
echo "Checking for incompatible API changes relative to ${UPSTREAM_BRANCH}..."
INSTALL_DIR="$(mktemp -d)"
MASTER_CLONE_DIR="$(mktemp -d)"
PKGINFO_BRANCH=$(mktemp)
PKGINFO_MASTER=$(mktemp)
function cleanup() {
rm -rf "$INSTALL_DIR"
rm -rf "$MASTER_CLONE_DIR"
rm -f "$PKGINFO_BRANCH"
rm -f "$PKGINFO_MASTER"
}
trap cleanup EXIT
# Move to a temporary directory while installing apidiff to avoid changing
# the local .mod file.
( cd "$INSTALL_DIR" && exec go mod init unused )
( cd "$INSTALL_DIR" && exec go install golang.org/x/exp/cmd/apidiff )
git clone -b "$UPSTREAM_BRANCH" . "$MASTER_CLONE_DIR" &> /dev/null
incompatible_change_pkgs=()
PKGS=$(cd "$MASTER_CLONE_DIR"; go list ./... | grep -v test)
for pkg in $PKGS; do
echo " Testing ${pkg}..."
# Compute export data for the current branch.
package_deleted=0
apidiff -w "$PKGINFO_BRANCH" "$pkg" || package_deleted=1
if [[ $package_deleted -eq 1 ]]; then
echo " Package ${pkg} was deleted! Recording as an incompatible change.";
incompatible_change_pkgs+=(${pkg});
continue;
fi
# Compute export data for master@HEAD.
(cd "$MASTER_CLONE_DIR"; apidiff -w "$PKGINFO_MASTER" "$pkg")
# Print all changes for posterity.
apidiff "$PKGINFO_MASTER" "$PKGINFO_BRANCH"
# Note if there's an incompatible change.
ic=$(apidiff -incompatible "$PKGINFO_MASTER" "$PKGINFO_BRANCH")
if [ ! -z "$ic" ]; then
incompatible_change_pkgs+=("$pkg");
fi
done
if [ ${#incompatible_change_pkgs[@]} -eq 0 ]; then
# No incompatible changes, we are good.
echo "OK: No incompatible changes found."
exit 0;
fi
echo "Found breaking API change(s) in: ${incompatible_change_pkgs[*]}."
# Found incompatible changes; see if they were declared as OK via a commit.
if git cherry -v master | grep -q "BREAKING_CHANGE_OK"; then
echo "Allowing them due to a commit message with BREAKING_CHANGE_OK.";
exit 0;
fi
echo "FAIL. If this is expected and OK, you can pass this check by adding a commit with BREAKING_CHANGE_OK in the first line of the message."
exit 1

View File

@@ -14,32 +14,67 @@
# limitations under the License. # limitations under the License.
# https://coderwall.com/p/fkfaqq/safer-bash-scripts-with-set-euxo-pipefail # https://coderwall.com/p/fkfaqq/safer-bash-scripts-with-set-euxo-pipefail
set -euxo pipefail set -euo pipefail
if [[ $# -gt 0 ]]; then if [[ $# -gt 0 ]]; then
echo "usage: runtests.sh" 1>&2 echo "usage: runtests.sh" 1>&2
exit 64 exit 64
fi fi
result=0
# Run Go tests. Only do coverage for the Linux build # Run Go tests. Only do coverage for the Linux build
# because it is slow, and codecov will only save the last one anyway. # because it is slow, and codecov will only save the last one anyway.
if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then result=0
go test -race -coverpkg=./... -coverprofile=coverage.out ./... || result=1 if [[ "${TRAVIS_OS_NAME:-}" == "linux" ]]; then
if [ -f coverage.out ]; then echo "Running Go tests (with coverage)..."
go test -mod=readonly -race -coverpkg=./... -coverprofile=coverage.out ./... || result=1
if [ -f coverage.out ] && [ $result -eq 0 ]; then
bash <(curl -s https://codecov.io/bash) bash <(curl -s https://codecov.io/bash)
fi fi
# Ensure that the code has no extra dependencies (including transitive
# dependencies) that we're not already aware of by comparing with
# ./internal/alldeps
#
# Whenever project dependencies change, rerun ./internal/listdeps.sh
./internal/listdeps.sh | diff ./internal/alldeps - || {
echo "FAIL: dependencies changed; compare listdeps.sh output with alldeps" && result=1
}
else else
go test -race ./... || result=1 echo "Running Go tests..."
go test -mod=readonly -race ./... || result=1
fi
# No need to run other checks on OSs other than linux.
# We default TRAVIS_OS_NAME to "linux" so that we don't abort here when run locally.
if [[ "${TRAVIS_OS_NAME:-linux}" != "linux" ]]; then
exit $result
fi
echo
echo "Ensuring .go files are formatted with gofmt -s..."
DIFF=$(gofmt -s -d `find . -name '*.go' -type f | grep -v testdata`)
if [ -n "$DIFF" ]; then
echo "FAIL: please run gofmt -s and commit the result"
echo "$DIFF";
result=1;
else
echo "OK"
fi;
# Ensure that the code has no extra dependencies (including transitive
# dependencies) that we're not already aware of by comparing with
# ./internal/alldeps
#
# Whenever project dependencies change, rerun ./internal/listdeps.sh
if [[ $(go version) == *go1\.12* ]]; then
echo
echo "Ensuring that there are no dependencies not listed in ./internal/alldeps..."
./internal/listdeps.sh | diff ./internal/alldeps - && echo "OK" || {
echo "FAIL: dependencies changed; run: internal/listdeps.sh > internal/alldeps"
# Module behavior may differ across versions.
echo "using go version 1.12."
result=1
}
fi
# For pull requests, check if there are undeclared incompatible API changes.
# Skip this if we're already going to fail since it is expensive.
if [[ ${result} -eq 0 ]] && [[ ! -z "${TRAVIS_BRANCH:-x}" ]] && [[ ! -z "${TRAVIS_PULL_REQUEST_SHA:-x}" ]]; then
echo
./internal/check_api_change.sh || result=1;
fi fi
exit $result exit $result

View File

@@ -276,7 +276,7 @@ func verifyArgsUsed(set *ProviderSet, used []*providerSetSrc) []error {
} }
} }
if !found { if !found {
errs = append(errs, fmt.Errorf("unused provider %q", p.Pkg.Name() + "." + p.Name)) errs = append(errs, fmt.Errorf("unused provider %q", p.Pkg.Name()+"."+p.Name))
} }
} }
for _, v := range set.Values { for _, v := range set.Values {