|
| 1 | +#!/bin/bash |
| 2 | +# Copyright 2020 Google LLC |
| 3 | +# |
| 4 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +# you may not use this file except in compliance with the License. |
| 6 | +# You may obtain a copy of the License at |
| 7 | +# |
| 8 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +# |
| 10 | +# Unless required by applicable law or agreed to in writing, software |
| 11 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +# See the License for the specific language governing permissions and |
| 14 | +# limitations under the License.. |
| 15 | + |
| 16 | +# Fail on any error |
| 17 | +set -eo pipefail |
| 18 | + |
| 19 | +# Display commands being run |
| 20 | +set -x |
| 21 | + |
| 22 | +# Where google-cloud-go code is located. |
| 23 | +gcwd=$PWD/github/google-cloud-go |
| 24 | + |
| 25 | +cd github/golang-samples |
| 26 | + |
| 27 | +# Returns 0 if the test should be skipped because the current Go |
| 28 | +# version is too old for the current module. |
| 29 | +goVersionShouldSkip() { |
| 30 | + echo "Downloading modules and checking versions" |
| 31 | + modVersion="$(go list -m -f '{{.GoVersion}}')" |
| 32 | + if [ -z "$modVersion" ]; then |
| 33 | + # Not in a module or minimum Go version not specified, don't skip. |
| 34 | + return 1 |
| 35 | + fi |
| 36 | + |
| 37 | + go list -f "{{context.ReleaseTags}}" | grep -q -v "go$modVersion\b" |
| 38 | +} |
| 39 | + |
| 40 | +# For each module, build the code with local google-cloud-go changes. |
| 41 | +for i in $(find . -name go.mod); do |
| 42 | + # internal: this does not need to be built to test compatibility |
| 43 | + # run/events_pubsub: module requires go1.13 for cloudevents |
| 44 | + if [[ $i == *"/internal/"* ]]; then |
| 45 | + continue |
| 46 | + fi |
| 47 | + |
| 48 | + pushd $(dirname $i) |
| 49 | + if goVersionShouldSkip; then |
| 50 | + popd |
| 51 | + continue |
| 52 | + fi |
| 53 | + # TODO(codyoss): if we spilt out modules someday we should make this programmatic. |
| 54 | + go mod edit -replace cloud.google.com/go=$gcwd |
| 55 | + go mod edit -replace cloud.google.com/go/bigtable=$gcwd/bigtable |
| 56 | + go mod edit -replace cloud.google.com/go/bigquery=$gcwd/bigquery |
| 57 | + go mod edit -replace cloud.google.com/go/datastore=$gcwd/datastore |
| 58 | + go mod edit -replace cloud.google.com/go/firestore=$gcwd/firestore |
| 59 | + go mod edit -replace cloud.google.com/go/logging=$gcwd/logging |
| 60 | + go mod edit -replace cloud.google.com/go/pubsub=$gcwd/pubsub |
| 61 | + go mod edit -replace cloud.google.com/go/spanner=$gcwd/spanner |
| 62 | + go mod edit -replace cloud.google.com/go/storage=$gcwd/storage |
| 63 | + echo "Building module $i" |
| 64 | + go build ./... |
| 65 | + popd |
| 66 | +done |
0 commit comments