From 7f5418a9d1dfd727d9a8c486de94478a44b8dfbe Mon Sep 17 00:00:00 2001 From: coffeebeats <108542400+coffeebeats@users.noreply.github.com> Date: Tue, 7 Nov 2023 17:21:38 -0800 Subject: [PATCH 1/2] chore: upgrade github.com/charmbracelet/log --- cmd/gdenv/main.go | 37 ++++++++++++++++++++++++++----------- go.mod | 10 +++++----- go.sum | 10 ++++++++++ 3 files changed, 41 insertions(+), 16 deletions(-) diff --git a/cmd/gdenv/main.go b/cmd/gdenv/main.go index 47506a03..20902d49 100644 --- a/cmd/gdenv/main.go +++ b/cmd/gdenv/main.go @@ -79,7 +79,9 @@ func main() { //nolint:funlen stop() }() - setUpLogger() + if err := setUpLogger(); err != nil { + panic(err) + } if err := app.RunContext(ctx, os.Args); err != nil { var usageErr UsageError @@ -121,19 +123,32 @@ func (e UsageError) Error() string { /* -------------------------------------------------------------------------- */ // setUpLogger configures the package-level charm.sh 'log' logger. -func setUpLogger() { - // Configure the logging level based on an environment variable. - log.SetLevel(log.ParseLevel(os.Getenv(envLogLevel))) - +func setUpLogger() error { // Configure timestamp reporting. log.SetReportTimestamp(false) - // Configure styles - log.DebugLevelStyle = newStyleWithColor("debug", colorCyanBright) - log.InfoLevelStyle = newStyleWithColor("info", colorGreenBright) - log.WarnLevelStyle = newStyleWithColor("warn", colorYellowBright) - log.ErrorLevelStyle = newStyleWithColor("error", colorRedBright) //nolint:reassign - log.FatalLevelStyle = newStyleWithColor("fatal", colorMagentaBright) + // Configure styles for each log level. + s := log.DefaultStyles() + s.Levels[log.DebugLevel] = newStyleWithColor("debug", colorCyanBright) + s.Levels[log.InfoLevel] = newStyleWithColor("info", colorGreenBright) + s.Levels[log.WarnLevel] = newStyleWithColor("warn", colorYellowBright) + s.Levels[log.ErrorLevel] = newStyleWithColor("error", colorRedBright) + s.Levels[log.FatalLevel] = newStyleWithColor("fatal", colorMagentaBright) + + log.SetStyles(s) + + // Try to parse a log level override. + if envLevel := os.Getenv(envLogLevel); envLevel != "" { + level, err := log.ParseLevel(envLevel) + if err != nil { + return err + } + + // Configure the default logging level. + log.SetLevel(level) + } + + return nil } /* ----------------------- Function: newStyleWithColor ---------------------- */ diff --git a/go.mod b/go.mod index c140f93f..979f584f 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ go 1.21 require ( github.com/charmbracelet/lipgloss v0.9.1 - github.com/charmbracelet/log v0.2.5 + github.com/charmbracelet/log v0.3.0 github.com/go-resty/resty/v2 v2.10.0 github.com/golangci/golangci-lint v1.55.2 github.com/goreleaser/goreleaser v1.22.0 @@ -256,7 +256,7 @@ require ( github.com/maratori/testpackage v1.1.1 // indirect github.com/matoous/godox v0.0.0-20230222163458-006bad1f9d26 // indirect github.com/mattn/go-colorable v0.1.13 // indirect - github.com/mattn/go-isatty v0.0.18 // indirect + github.com/mattn/go-isatty v0.0.20 // indirect github.com/mattn/go-mastodon v0.0.6 // indirect github.com/mattn/go-runewidth v0.0.15 // indirect github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect @@ -296,7 +296,7 @@ require ( github.com/quasilyte/gogrep v0.5.0 // indirect github.com/quasilyte/regex/syntax v0.0.0-20210819130434-b3f0c404a727 // indirect github.com/quasilyte/stdinfo v0.0.0-20220114132959-f7386bf02567 // indirect - github.com/rivo/uniseg v0.4.2 // indirect + github.com/rivo/uniseg v0.4.4 // indirect github.com/russross/blackfriday/v2 v2.1.0 // indirect github.com/ryancurrah/gomodguard v1.3.0 // indirect github.com/ryanrolds/sqlclosecheck v0.5.1 // indirect @@ -368,11 +368,11 @@ require ( go.uber.org/zap v1.24.0 // indirect gocloud.dev v0.34.0 // indirect golang.org/x/crypto v0.14.0 // indirect - golang.org/x/exp v0.0.0-20230905200255-921286631fa9 // indirect + golang.org/x/exp v0.0.0-20231006140011-7918f672742d // indirect golang.org/x/exp/typeparams v0.0.0-20230307190834-24139beb5833 // indirect golang.org/x/net v0.17.0 // indirect golang.org/x/oauth2 v0.13.0 // indirect - golang.org/x/sys v0.13.0 // indirect + golang.org/x/sys v0.14.0 // indirect golang.org/x/term v0.13.0 // indirect golang.org/x/text v0.14.0 // indirect golang.org/x/time v0.3.0 // indirect diff --git a/go.sum b/go.sum index a80b49eb..98c7adef 100644 --- a/go.sum +++ b/go.sum @@ -313,6 +313,8 @@ github.com/charmbracelet/lipgloss v0.9.1 h1:PNyd3jvaJbg4jRHKWXnCj1akQm4rh8dbEzN1 github.com/charmbracelet/lipgloss v0.9.1/go.mod h1:1mPmG4cxScwUQALAAnacHaigiiHB9Pmr+v1VEawJl6I= github.com/charmbracelet/log v0.2.5 h1:1yVvyKCKVV639RR4LIq1iy1Cs1AKxuNO+Hx2LJtk7Wc= github.com/charmbracelet/log v0.2.5/go.mod h1:nQGK8tvc4pS9cvVEH/pWJiZ50eUq1aoXUOjGpXvdD0k= +github.com/charmbracelet/log v0.3.0 h1:u5aB2KJDgNZo4WOfOC8C+KvGIkJ2rCFNlPWDu6xhnqI= +github.com/charmbracelet/log v0.3.0/go.mod h1:OR4E1hutLsax3ZKpXbgUqPtTjQfrh1pG3zwHGWuuq8g= github.com/charmbracelet/x/exp/ordered v0.0.0-20231010190216-1cb11efc897d h1:+o+e/8hf7cG0SbAzEAm/usJ8qoZPgFXhudLjop+TM0g= github.com/charmbracelet/x/exp/ordered v0.0.0-20231010190216-1cb11efc897d/go.mod h1:aoG4bThKYIOnyB55r202eHqo6TkN7ZXV+cu4Do3eoBQ= github.com/chavacava/garif v0.1.0 h1:2JHa3hbYf5D9dsgseMKAmc/MZ109otzgNFk5s87H9Pc= @@ -851,6 +853,8 @@ github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27k github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= github.com/mattn/go-isatty v0.0.18 h1:DOKFKCQ7FNG2L1rbrmstDN4QVRdS89Nkh85u68Uwp98= github.com/mattn/go-isatty v0.0.18/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= +github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= +github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= github.com/mattn/go-mastodon v0.0.6 h1:lqU1sOeeIapaDsDUL6udDZIzMb2Wqapo347VZlaOzf0= github.com/mattn/go-mastodon v0.0.6/go.mod h1:cg7RFk2pcUfHZw/IvKe1FUzmlq5KnLFqs7eV2PHplV8= github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI= @@ -996,6 +1000,8 @@ github.com/rivo/uniseg v0.1.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJ github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= github.com/rivo/uniseg v0.4.2 h1:YwD0ulJSJytLpiaWua0sBDusfsCZohxjxzVTYjwxfV8= github.com/rivo/uniseg v0.4.2/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88= +github.com/rivo/uniseg v0.4.4 h1:8TfxU8dW6PdqD27gjM8MVNuicgxIjxpm4K7x4jp8sis= +github.com/rivo/uniseg v0.4.4/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88= github.com/rogpeppe/go-internal v1.1.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= github.com/rogpeppe/go-internal v1.2.2/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= @@ -1255,6 +1261,8 @@ golang.org/x/exp v0.0.0-20200207192155-f17229e696bd/go.mod h1:J/WKrq2StrnmMY6+EH golang.org/x/exp v0.0.0-20200224162631-6cc2880d07d6/go.mod h1:3jZMyOhIsHpP37uCMkUooju7aAi5cS1Q23tOzKc+0MU= golang.org/x/exp v0.0.0-20230905200255-921286631fa9 h1:GoHiUyI/Tp2nVkLI2mCxVkOjsbSXD66ic0XW0js0R9g= golang.org/x/exp v0.0.0-20230905200255-921286631fa9/go.mod h1:S2oDrQGGwySpoQPVqRShND87VCbxmc6bL1Yd2oYrm6k= +golang.org/x/exp v0.0.0-20231006140011-7918f672742d h1:jtJma62tbqLibJ5sFQz8bKtEM8rJBtfilJ2qTU199MI= +golang.org/x/exp v0.0.0-20231006140011-7918f672742d/go.mod h1:ldy0pHrwJyGW56pPQzzkH36rKxoZW1tw7ZJpeKx+hdo= golang.org/x/exp/typeparams v0.0.0-20220428152302-39d4317da171/go.mod h1:AbB0pIl9nAr9wVwH+Z2ZpaocVmF5I4GyWCDIsVjR0bk= golang.org/x/exp/typeparams v0.0.0-20230203172020-98cc5a0785f9/go.mod h1:AbB0pIl9nAr9wVwH+Z2ZpaocVmF5I4GyWCDIsVjR0bk= golang.org/x/exp/typeparams v0.0.0-20230307190834-24139beb5833 h1:jWGQJV4niP+CCmFW9ekjA9Zx8vYORzOUH2/Nl5WPuLQ= @@ -1438,6 +1446,8 @@ golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE= golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.14.0 h1:Vz7Qs629MkJkGyHxUlRHizWJRG2j8fbQKjELVSNhy7Q= +golang.org/x/sys v0.14.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.1.0/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= From 093a1470c5565cad2d9b0552d68f0912df9bef51 Mon Sep 17 00:00:00 2001 From: coffeebeats <108542400+coffeebeats@users.noreply.github.com> Date: Tue, 7 Nov 2023 17:22:46 -0800 Subject: [PATCH 2/2] fix: install goimports once and cache it --- .github/workflows/check-commit.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/check-commit.yml b/.github/workflows/check-commit.yml index 1b7b3d64..98ce1ff2 100644 --- a/.github/workflows/check-commit.yml +++ b/.github/workflows/check-commit.yml @@ -62,14 +62,16 @@ jobs: id: format continue-on-error: true run: | + go install golang.org/x/tools/cmd/goimports + test -z $(gofmt -l .) - test -z $(go run golang.org/x/tools/cmd/goimports -l .) + test -z $(goimports -l .) - name: Fix formatting of source code if: steps.format.outcome == 'failure' run: | gofmt -w . - go run golang.org/x/tools/cmd/goimports -w . + goimports -w . # See https://github.com/orgs/community/discussions/26560#discussioncomment-3531273 git config user.email "41898282+github-actions[bot]@users.noreply.github.com"