From 6d0f5ffae3d4d0cf214c8762742a3412d31577a5 Mon Sep 17 00:00:00 2001 From: Alexey Palazhchenko Date: Tue, 21 Feb 2023 15:16:40 +0400 Subject: [PATCH] Speed-up Go installation (#138) --- go.mod | 2 +- go.sum | 4 ++-- setup-go/action.yml | 9 +++------ setup-go/main.go | 37 +++++++++++++++++++++++++++---------- tools/go.mod | 2 +- tools/go.sum | 4 ++-- 6 files changed, 36 insertions(+), 22 deletions(-) diff --git a/go.mod b/go.mod index bc65238..b85fc12 100644 --- a/go.mod +++ b/go.mod @@ -19,7 +19,7 @@ require ( github.com/sethvargo/go-envconfig v0.8.0 // indirect github.com/shurcooL/graphql v0.0.0-20220606043923-3cf50f8a0a29 // indirect golang.org/x/crypto v0.0.0-20210817164053-32db794688a5 // indirect - golang.org/x/net v0.6.0 // indirect + golang.org/x/net v0.7.0 // indirect google.golang.org/appengine v1.6.7 // indirect google.golang.org/protobuf v1.28.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect diff --git a/go.sum b/go.sum index ea04755..9a060e5 100644 --- a/go.sum +++ b/go.sum @@ -35,8 +35,8 @@ golang.org/x/crypto v0.0.0-20210817164053-32db794688a5/go.mod h1:GvvjBRRGRdwPK5y golang.org/x/exp v0.0.0-20230213192124-5e25df0256eb h1:PaBZQdo+iSDyHT053FjUCgZQ/9uqVwPOcl7KSWhKn6w= golang.org/x/exp v0.0.0-20230213192124-5e25df0256eb/go.mod h1:CxIveKay+FTh1D0yPZemJVgC/95VzuuOLq5Qi4xnoYc= golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= -golang.org/x/net v0.6.0 h1:L4ZwwTvKW9gr0ZMS1yrHD9GZhIuVjOBBnaKH+SPQK0Q= -golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= +golang.org/x/net v0.7.0 h1:rJrUqqhjsgNp7KqAIc25s9pZnjU7TUcSY7HcVZjdn1g= +golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= golang.org/x/oauth2 v0.5.0 h1:HuArIo48skDwlrvM3sEdHXElYslAMsf3KwRkkW4MC4s= golang.org/x/oauth2 v0.5.0/go.mod h1:9/XBHVqLaWO3/BRHs5jbpYCnOZVjj5V0ndyaAM7KB4I= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= diff --git a/setup-go/action.yml b/setup-go/action.yml index af6f5b3..8d56e98 100644 --- a/setup-go/action.yml +++ b/setup-go/action.yml @@ -24,14 +24,11 @@ runs: uses: actions/cache@v3 with: path: ${{ steps.run.outputs.cache_path }} - key: ${{ inputs.cache-key }}-${{ steps.run.outputs.cache_week }}-${{ hashFiles('**/go.mod') }}-${{ hashFiles('**') }} + key: ${{ inputs.cache-key }}-${{ steps.run.outputs.cache_week }}-${{ hashFiles('**/go.mod') }} restore-keys: | - ${{ inputs.cache-key }}-${{ steps.run.outputs.cache_week }}-${{ hashFiles('**/go.mod') }} - ${{ inputs.cache-key }}-${{ steps.run.outputs.cache_week }} + ${{ inputs.cache-key }}-${{ steps.run.outputs.cache_week }}- # we don't want them on CI - name: Clean test and fuzz caches - run: | - go clean -testcache - go clean -fuzzcache + run: go clean -testcache -fuzzcache shell: bash diff --git a/setup-go/main.go b/setup-go/main.go index da712c7..ccebd1b 100644 --- a/setup-go/main.go +++ b/setup-go/main.go @@ -22,6 +22,7 @@ import ( "path/filepath" "strconv" "strings" + "sync" "time" "github.com/sethvargo/go-githubactions" @@ -29,6 +30,24 @@ import ( "github.com/FerretDB/github-actions/internal" ) +// tidyDir runs `go mod tidy` in the specified directory. +func tidyDir(action *githubactions.Action, dir string) { + cmd := exec.Command("go", "mod", "tidy") + cmd.Dir = dir + cmd.Stdout = os.Stdout + cmd.Stderr = os.Stderr + + start := time.Now() + + action.Infof("Running `%s` in %s ...", strings.Join(cmd.Args, " "), cmd.Dir) + + if err := cmd.Run(); err != nil { + action.Fatalf("%s", err) + } + + action.Infof("Done in %s.", time.Since(start)) +} + func main() { flag.Parse() @@ -82,6 +101,7 @@ func main() { action.SetOutput("cache_path", gocache) // download modules in directories with `go.mod` file + var wg sync.WaitGroup err := filepath.Walk(workspace, func(path string, info fs.FileInfo, err error) error { if err != nil { return err @@ -101,20 +121,17 @@ func main() { return nil } - cmd := exec.Command("go", "mod", "tidy") - cmd.Dir = filepath.Dir(path) - cmd.Stdout = os.Stdout - cmd.Stderr = os.Stderr - start := time.Now() - action.Infof("Running `%s` in %s ...", strings.Join(cmd.Args, " "), cmd.Dir) - if err = cmd.Run(); err != nil { - return err - } - action.Infof("Done in %s.", time.Since(start)) + wg.Add(1) + go func() { + defer wg.Done() + tidyDir(action, filepath.Dir(path)) + }() return nil }) if err != nil { action.Fatalf("Error walking directory: %s", err) } + + wg.Wait() } diff --git a/tools/go.mod b/tools/go.mod index 6fe29f3..49aab31 100644 --- a/tools/go.mod +++ b/tools/go.mod @@ -201,7 +201,7 @@ require ( golang.org/x/exp v0.0.0-20220930202632-ec3f01382ef9 // indirect golang.org/x/exp/typeparams v0.0.0-20220827204233-334a2380cb91 // indirect golang.org/x/mod v0.8.0 // indirect - golang.org/x/net v0.6.0 // indirect + golang.org/x/net v0.7.0 // indirect golang.org/x/oauth2 v0.0.0-20220411215720-9780585627b5 // indirect golang.org/x/sync v0.1.0 // indirect golang.org/x/sys v0.5.0 // indirect diff --git a/tools/go.sum b/tools/go.sum index aae44de..38b0ed9 100644 --- a/tools/go.sum +++ b/tools/go.sum @@ -856,8 +856,8 @@ golang.org/x/net v0.0.0-20220412020605-290c469a71a5/go.mod h1:CfG3xpIq0wQ8r1q4Su golang.org/x/net v0.0.0-20220425223048-2871e0cb64e4/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk= golang.org/x/net v0.0.0-20220520000938-2e3eb7b945c2/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk= golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= -golang.org/x/net v0.6.0 h1:L4ZwwTvKW9gr0ZMS1yrHD9GZhIuVjOBBnaKH+SPQK0Q= -golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= +golang.org/x/net v0.7.0 h1:rJrUqqhjsgNp7KqAIc25s9pZnjU7TUcSY7HcVZjdn1g= +golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= golang.org/x/oauth2 v0.0.0-20170207211851-4464e7848382/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=