Skip to content

Check the ready status of component before it becomes reachable. #2078

Check the ready status of component before it becomes reachable.

Check the ready status of component before it becomes reachable. #2078

Workflow file for this run

# Copyright 2023 Google LLC
#
# 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
#
# http://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.
name: Build and Test
on:
push:
branches:
- 'main'
pull_request:
jobs:
build:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
version: ["stable"]
command: ["build", "vet", "lint", "test", "testrace"]
steps:
- name: Check out repository
uses: actions/checkout@v3
# The setup-go action's default caching behavior does not work well with
# matrix tests. By default, setup-go caches the contents of `go env
# GOCACHE` and `go env GOMODCACHE` under a key derived from the OS, the
# go version, and a hash of the contents of go.sum [1].
#
# When we run a matrix test, every job uses the same cache key. As a
# result, the jobs race, and the first to finish determines the contents
# of the cache. Because caches are write-once, all other jobs fail to
# update the cache. In subsequent runs, all jobs use the contents of the
# cache, even if the cache was generated by a different job.
#
# For example, if the "lint" job finishes first, then all future jobs
# like "build" and "test" will use the cache produced by the "lint" job.
# However, this cache is likely missing a lot of cached package and build
# outputs, causing to the "build" and "test" jobs to redundantly download
# and build dependencies again and again.
#
# To avoid this problem, we manually cache the contents of `go env
# GOCACHE` and `go env GOMODCACHE` using a key derived from the OS, the
# go version, the contents of go.sum, and the matrix command. See [2] for
# more documentation on custom cache keys and paths.
#
# [1]: https://github.com/actions/setup-go/blob/93397bea11091df50f3d7e59dc26a7711a8bcfbe/docs/adrs/0000-caching-dependencies.md
# [2]: https://github.com/actions/cache#creating-a-cache-key
- name: Set up Go
id: setup-go
uses: actions/setup-go@v4
with:
go-version: ${{ matrix.version }}
cache: false
- name: Get go cache locations
id: get-go-caches
run: |
echo "gocache=$(go env GOCACHE)" >> $GITHUB_OUTPUT
echo "gomodcache=$(go env GOMODCACHE)" >> $GITHUB_OUTPUT
- name: Cache go
uses: actions/cache@v3
with:
path: |
${{ steps.get-go-caches.outputs.gocache }}
${{ steps.get-go-caches.outputs.gomodcache }}
key: ${{ runner.os }}-go${{ steps.setup-go.outputs.go-version }}-${{ hashFiles('go.sum') }}-${{ matrix.command }}
- name: Cache linter
uses: actions/cache@v3
with:
path: ~/go/bin/staticcheck
key: staticcheck-v0.4.6
if: ${{ matrix.command == 'lint' }}
- name: Install linter
run: go install honnef.co/go/tools/cmd/staticcheck@v0.4.6
if: ${{ matrix.command == 'lint' }}
- name: Build the weaver binary
run: cd cmd/weaver; go build .
if: ${{ matrix.command == 'test' || matrix.command == 'testrace' }}
- name: ${{ matrix.command }}
run: ./dev/build_and_test ${{ matrix.command }}
generate:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
version: ["stable"]
steps:
- name: Check out repository
uses: actions/checkout@v3
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: ${{ matrix.version }}
cache: true
- name: Cache protoc-gen-go
uses: actions/cache@v3
with:
path: ~/go/bin/protoc-gen-go
key: protoc-gen-go-v1.26
- name: Cache addlicense
uses: actions/cache@v3
with:
path: ~/go/bin/addlicense
key: addlicense-v1.1.1
- name: Install protoc
run: sudo apt install -y protobuf-compiler
- name: Install protoc-gen-go
run: go install google.golang.org/protobuf/cmd/protoc-gen-go@v1.26
- name: Install addlicense
run: go install github.com/google/addlicense@v1.1.1
- name: Generate code
run: ./dev/build_and_test generate
- name: Check spurious changes
run: |
# TODO(mwhittaker): Check .pb.go files.
# Exclude the weaver binary, which is built by the generate tool.
rm ./cmd/weaver/weaver
# Exclude .pb.go files, as the protoc version may differ.
if [[ $(git ls-files --modified --others | grep -v '.*\.pb\.go') ]]; then
for f in $(git ls-files --modified); do
if ! [[ $f == *.pb.go ]]; then
echo "❌ File $f modified."
git diff "$f"
fi
done
for f in $(git ls-files --others); do
echo "❌ File $f untracked."
done
echo "Run './dev/build_and_test generate' and commit the changes."
exit 1
fi
echo "Success ✅"