From e6d2f610867bf43de0702743bb36aad34087fc2a Mon Sep 17 00:00:00 2001 From: David Anderson Date: Thu, 17 Mar 2022 15:18:45 -0700 Subject: [PATCH] .github/workflows: work around golang/go#51629 Incidentally, simplify the go generate CI workflow, by marking the dnsfallback update non-hermetic (so CI will skip it) rather than manually filter it out of `go list`. Updates #4194 Signed-off-by: David Anderson --- .../workflows/go-generate-without-stringer.sh | 18 ++++++++++++++++++ .github/workflows/go_generate.yml | 13 ++++++------- net/dnsfallback/dnsfallback.go | 2 -- net/dnsfallback/generate.go | 10 ++++++++++ net/dnsfallback/update-dns-fallbacks.go | 1 + 5 files changed, 35 insertions(+), 9 deletions(-) create mode 100755 .github/workflows/go-generate-without-stringer.sh create mode 100644 net/dnsfallback/generate.go diff --git a/.github/workflows/go-generate-without-stringer.sh b/.github/workflows/go-generate-without-stringer.sh new file mode 100755 index 0000000000000..070c8ad68f2cc --- /dev/null +++ b/.github/workflows/go-generate-without-stringer.sh @@ -0,0 +1,18 @@ +#!/usr/bin/env sh +# +# This is a temporary hack to work around +# https://github.com/golang/go/issues/51629 , wherein the stringer +# generator doesn't work with generics. +# +# This script is the equivalent of `go generate ./...`, except that it +# only runs generate on packages that don't try to use stringer. + +set -e + +find . -name '*.go' | xargs grep -l go:generate | xargs -n1 dirname | sort -u | while read dir; do + if ! egrep "cmd/(stringer|cloner)" $dir/*.go; then + set -x + go generate -tags=hermetic $dir + set +x + fi +done diff --git a/.github/workflows/go_generate.yml b/.github/workflows/go_generate.yml index 4f98ef9ad36a1..339ea5b91bd2c 100644 --- a/.github/workflows/go_generate.yml +++ b/.github/workflows/go_generate.yml @@ -25,14 +25,13 @@ jobs: fetch-depth: 0 - name: check 'go generate' is clean + # The shell script invocation below is a temporary hack for + # https://github.com/tailscale/tailscale/issues/4194. When + # that issue is fixed, replace its invocation with: + # go generate --tags=hermetic ./... run: | - if [[ "${{github.ref}}" == release-branch/* ]] - then - pkgs=$(go list ./... | grep -v dnsfallback) - else - pkgs=$(go list ./... | grep -v dnsfallback) - fi - go generate $pkgs + set -e + ./.github/workflows/go-generate-without-stringer.sh echo echo git diff --name-only --exit-code || (echo "The files above need updating. Please run 'go generate'."; exit 1) diff --git a/net/dnsfallback/dnsfallback.go b/net/dnsfallback/dnsfallback.go index cdbb268446691..0e09861eb9557 100644 --- a/net/dnsfallback/dnsfallback.go +++ b/net/dnsfallback/dnsfallback.go @@ -2,8 +2,6 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -//go:generate go run update-dns-fallbacks.go - // Package dnsfallback contains a DNS fallback mechanism // for starting up Tailscale when the system DNS is broken or otherwise unavailable. package dnsfallback diff --git a/net/dnsfallback/generate.go b/net/dnsfallback/generate.go new file mode 100644 index 0000000000000..4963a710747e4 --- /dev/null +++ b/net/dnsfallback/generate.go @@ -0,0 +1,10 @@ +// Copyright (c) 2022 Tailscale Inc & AUTHORS All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +//go:build !hermetic +// +build !hermetic + +package dnsfallback + +//go:generate go run update-dns-fallbacks.go diff --git a/net/dnsfallback/update-dns-fallbacks.go b/net/dnsfallback/update-dns-fallbacks.go index db50118aa25d5..b261aa871981e 100644 --- a/net/dnsfallback/update-dns-fallbacks.go +++ b/net/dnsfallback/update-dns-fallbacks.go @@ -19,6 +19,7 @@ import ( ) func main() { + log.Printf("RUN RUN RUN") res, err := http.Get("https://login.tailscale.com/derpmap/default") if err != nil { log.Fatal(err)