From 05d5a3f4bc93673ca1980dfc7d3736c4e1d9419b Mon Sep 17 00:00:00 2001 From: BrunoQuaresma Date: Fri, 3 May 2024 14:00:57 +0000 Subject: [PATCH 01/11] chore: format go code using gofumpt --- Makefile | 3 +++ devcontainer/devcontainer.go | 6 +++--- devcontainer/devcontainer_test.go | 4 ++-- devcontainer/features/features.go | 4 ++-- envbuilder.go | 8 ++++---- envbuilder_internal_test.go | 12 ++++++------ git.go | 2 +- git_test.go | 2 +- go.mod | 1 + go.sum | 4 ++++ integration/integration_test.go | 4 ++-- options_test.go | 3 +-- scripts/docsgen/main.go | 2 +- testutil/gittest/gittest.go | 2 +- testutil/registrytest/registrytest.go | 2 +- tools.go | 7 +++++++ 16 files changed, 40 insertions(+), 26 deletions(-) create mode 100644 tools.go diff --git a/Makefile b/Makefile index d607f956..5421df0c 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,9 @@ GOARCH := $(shell go env GOARCH) PWD=$(shell pwd) +format: *.go + go run mvdan.cc/gofumpt -w . + develop: ./scripts/develop.sh diff --git a/devcontainer/devcontainer.go b/devcontainer/devcontainer.go index 19642e38..8f2780c0 100644 --- a/devcontainer/devcontainer.go +++ b/devcontainer/devcontainer.go @@ -141,7 +141,7 @@ func (s *Spec) Compile(fs billy.Filesystem, devcontainerDir, scratchDir string, if s.Image != "" { // We just write the image to a file and return it. dockerfilePath := filepath.Join(scratchDir, "Dockerfile") - file, err := fs.OpenFile(dockerfilePath, os.O_CREATE|os.O_WRONLY, 0644) + file, err := fs.OpenFile(dockerfilePath, os.O_CREATE|os.O_WRONLY, 0o644) if err != nil { return nil, fmt.Errorf("open dockerfile: %w", err) } @@ -228,7 +228,7 @@ func (s *Spec) compileFeatures(fs billy.Filesystem, devcontainerDir, scratchDir } featuresDir := filepath.Join(scratchDir, "features") - err := fs.MkdirAll(featuresDir, 0644) + err := fs.MkdirAll(featuresDir, 0o644) if err != nil { return "", nil, fmt.Errorf("create features directory: %w", err) } @@ -278,7 +278,7 @@ func (s *Spec) compileFeatures(fs billy.Filesystem, devcontainerDir, scratchDir featureSha := md5.Sum([]byte(featureRefRaw)) featureName := filepath.Base(featureRef) featureDir := filepath.Join(featuresDir, fmt.Sprintf("%s-%x", featureName, featureSha[:4])) - if err := fs.MkdirAll(featureDir, 0644); err != nil { + if err := fs.MkdirAll(featureDir, 0o644); err != nil { return "", nil, err } spec, err := features.Extract(fs, devcontainerDir, featureDir, featureRefRaw) diff --git a/devcontainer/devcontainer_test.go b/devcontainer/devcontainer_test.go index fe573433..da003223 100644 --- a/devcontainer/devcontainer_test.go +++ b/devcontainer/devcontainer_test.go @@ -137,9 +137,9 @@ func TestCompileDevContainer(t *testing.T) { }, } dcDir := "/workspaces/coder/.devcontainer" - err := fs.MkdirAll(dcDir, 0755) + err := fs.MkdirAll(dcDir, 0o755) require.NoError(t, err) - file, err := fs.OpenFile(filepath.Join(dcDir, "Dockerfile"), os.O_CREATE|os.O_WRONLY, 0644) + file, err := fs.OpenFile(filepath.Join(dcDir, "Dockerfile"), os.O_CREATE|os.O_WRONLY, 0o644) require.NoError(t, err) _, err = io.WriteString(file, "FROM localhost:5000/envbuilder-test-ubuntu:latest") require.NoError(t, err) diff --git a/devcontainer/features/features.go b/devcontainer/features/features.go index 739211e8..07f346ed 100644 --- a/devcontainer/features/features.go +++ b/devcontainer/features/features.go @@ -65,7 +65,7 @@ func extractFromImage(fs billy.Filesystem, directory, reference string) error { path := filepath.Join(directory, header.Name) switch header.Typeflag { case tar.TypeDir: - err = fs.MkdirAll(path, 0755) + err = fs.MkdirAll(path, 0o755) if err != nil { return fmt.Errorf("mkdir %s: %w", path, err) } @@ -126,7 +126,7 @@ func Extract(fs billy.Filesystem, devcontainerDir, directory, reference string) if ok { // For some reason the filesystem abstraction doesn't support chmod. // https://github.com/src-d/go-billy/issues/56 - err = chmodder.Chmod(installScriptPath, 0755) + err = chmodder.Chmod(installScriptPath, 0o755) } if err != nil { return nil, fmt.Errorf("chmod install.sh: %w", err) diff --git a/envbuilder.go b/envbuilder.go index 83ca67d9..fdfe2c7e 100644 --- a/envbuilder.go +++ b/envbuilder.go @@ -151,7 +151,7 @@ func Run(ctx context.Context, options Options) error { if err != nil { return fmt.Errorf("parse docker config: %w", err) } - err = os.WriteFile(filepath.Join(MagicDir, "config.json"), decoded, 0644) + err = os.WriteFile(filepath.Join(MagicDir, "config.json"), decoded, 0o644) if err != nil { return fmt.Errorf("write docker config: %w", err) } @@ -225,7 +225,7 @@ func Run(ctx context.Context, options Options) error { defaultBuildParams := func() (*devcontainer.Compiled, error) { dockerfile := filepath.Join(MagicDir, "Dockerfile") - file, err := options.Filesystem.OpenFile(dockerfile, os.O_CREATE|os.O_WRONLY, 0644) + file, err := options.Filesystem.OpenFile(dockerfile, os.O_CREATE|os.O_WRONLY, 0o644) if err != nil { return nil, err } @@ -705,7 +705,7 @@ func Run(ctx context.Context, options Options) error { endStage("👤 Updated the ownership of the workspace!") } - err = os.MkdirAll(options.WorkspaceFolder, 0755) + err = os.MkdirAll(options.WorkspaceFolder, 0o755) if err != nil { return fmt.Errorf("create workspace folder: %w", err) } @@ -962,7 +962,7 @@ func createPostStartScript(path string, postStartCommand devcontainer.LifecycleS } defer postStartScript.Close() - if err := postStartScript.Chmod(0755); err != nil { + if err := postStartScript.Chmod(0o755); err != nil { return err } diff --git a/envbuilder_internal_test.go b/envbuilder_internal_test.go index d9fd3cb9..967e15d0 100644 --- a/envbuilder_internal_test.go +++ b/envbuilder_internal_test.go @@ -32,7 +32,7 @@ func TestFindDevcontainerJSON(t *testing.T) { // given fs := memfs.New() - err := fs.MkdirAll("/workspace/.devcontainer", 0600) + err := fs.MkdirAll("/workspace/.devcontainer", 0o600) require.NoError(t, err) // when @@ -50,7 +50,7 @@ func TestFindDevcontainerJSON(t *testing.T) { // given fs := memfs.New() - err := fs.MkdirAll("/workspace/.devcontainer", 0600) + err := fs.MkdirAll("/workspace/.devcontainer", 0o600) require.NoError(t, err) fs.Create("/workspace/.devcontainer/devcontainer.json") @@ -71,7 +71,7 @@ func TestFindDevcontainerJSON(t *testing.T) { // given fs := memfs.New() - err := fs.MkdirAll("/workspace/experimental-devcontainer", 0600) + err := fs.MkdirAll("/workspace/experimental-devcontainer", 0o600) require.NoError(t, err) fs.Create("/workspace/experimental-devcontainer/devcontainer.json") @@ -93,7 +93,7 @@ func TestFindDevcontainerJSON(t *testing.T) { // given fs := memfs.New() - err := fs.MkdirAll("/workspace/.devcontainer", 0600) + err := fs.MkdirAll("/workspace/.devcontainer", 0o600) require.NoError(t, err) fs.Create("/workspace/.devcontainer/experimental.json") @@ -115,7 +115,7 @@ func TestFindDevcontainerJSON(t *testing.T) { // given fs := memfs.New() - err := fs.MkdirAll("/workspace", 0600) + err := fs.MkdirAll("/workspace", 0o600) require.NoError(t, err) fs.Create("/workspace/devcontainer.json") @@ -136,7 +136,7 @@ func TestFindDevcontainerJSON(t *testing.T) { // given fs := memfs.New() - err := fs.MkdirAll("/workspace/.devcontainer/sample", 0600) + err := fs.MkdirAll("/workspace/.devcontainer/sample", 0o600) require.NoError(t, err) fs.Create("/workspace/.devcontainer/sample/devcontainer.json") diff --git a/git.go b/git.go index 9f542add..94b96523 100644 --- a/git.go +++ b/git.go @@ -63,7 +63,7 @@ func CloneRepo(ctx context.Context, opts CloneRepoOptions) (bool, error) { } } - err = opts.Storage.MkdirAll(opts.Path, 0755) + err = opts.Storage.MkdirAll(opts.Path, 0o755) if err != nil { return false, fmt.Errorf("mkdir %q: %w", opts.Path, err) } diff --git a/git_test.go b/git_test.go index 0d034728..67d25cdd 100644 --- a/git_test.go +++ b/git_test.go @@ -161,7 +161,7 @@ func TestCloneRepo(t *testing.T) { func mustRead(t *testing.T, fs billy.Filesystem, path string) string { t.Helper() - f, err := fs.OpenFile(path, os.O_RDONLY, 0644) + f, err := fs.OpenFile(path, os.O_RDONLY, 0o644) require.NoError(t, err) content, err := io.ReadAll(f) require.NoError(t, err) diff --git a/go.mod b/go.mod index 00b3dfc2..623526b0 100644 --- a/go.mod +++ b/go.mod @@ -285,6 +285,7 @@ require ( gvisor.dev/gvisor v0.0.0-20240301031223-3172bc04679b // indirect inet.af/netaddr v0.0.0-20230525184311-b8eac61e914a // indirect inet.af/peercred v0.0.0-20210906144145-0893ea02156a // indirect + mvdan.cc/gofumpt v0.6.0 // indirect nhooyr.io/websocket v1.8.7 // indirect storj.io/drpc v0.0.33-0.20230420154621-9716137f6037 // indirect tailscale.com v1.46.1 // indirect diff --git a/go.sum b/go.sum index 455df787..bcb4908c 100644 --- a/go.sum +++ b/go.sum @@ -292,6 +292,7 @@ github.com/felixge/httpsnoop v1.0.3 h1:s/nj+GCswXYzN5v2DpNMuMQYe+0DDwt5WVCU6CWBd github.com/felixge/httpsnoop v1.0.3/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U= github.com/frankban/quicktest v1.14.5 h1:dfYrrRyLtiqT9GyKXgdh+k4inNeTvmGbuSgZ3lx3GhA= github.com/frankban/quicktest v1.14.5/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0= +github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8= github.com/fullsailor/pkcs7 v0.0.0-20190404230743-d7302db945fa h1:RDBNVkRviHZtvDvId8XSGPu3rmpmSe+wKRcEWNgsfWU= github.com/fullsailor/pkcs7 v0.0.0-20190404230743-d7302db945fa/go.mod h1:KnogPXtdwXqoenmZCw6S+25EAm2MkxbG0deNDu4cbSA= github.com/fxamacker/cbor/v2 v2.4.0 h1:ri0ArlOR+5XunOP8CRUowT0pSJOwhW098ZCUyskZD88= @@ -735,6 +736,7 @@ github.com/robfig/cron/v3 v3.0.1 h1:WdRxkvbJztn8LMz/QEvLN5sBU+xKpSqwwUO1Pjr4qDs= github.com/robfig/cron/v3 v3.0.1/go.mod h1:eQICP3HwyT7UooqI/z+Ov+PtYAWygg1TEWWzGIFLtro= github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M= github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUzkipdSkR5nkCZA= +github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU5NdKM8= github.com/rootless-containers/rootlesskit v1.1.0 h1:cRaRIYxY8oce4eE/zeAUZhgKu/4tU1p9YHN4+suwV7M= github.com/rootless-containers/rootlesskit v1.1.0/go.mod h1:H+o9ndNe7tS91WqU0/+vpvc+VaCd7TCIWaJjnV0ujUo= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= @@ -1123,6 +1125,8 @@ inet.af/netaddr v0.0.0-20230525184311-b8eac61e914a h1:1XCVEdxrvL6c0TGOhecLuB7U9z inet.af/netaddr v0.0.0-20230525184311-b8eac61e914a/go.mod h1:e83i32mAQOW1LAqEIweALsuK2Uw4mhQadA5r7b0Wobo= inet.af/peercred v0.0.0-20210906144145-0893ea02156a h1:qdkS8Q5/i10xU2ArJMKYhVa1DORzBfYS/qA2UK2jheg= inet.af/peercred v0.0.0-20210906144145-0893ea02156a/go.mod h1:FjawnflS/udxX+SvpsMgZfdqx2aykOlkISeAsADi5IU= +mvdan.cc/gofumpt v0.6.0 h1:G3QvahNDmpD+Aek/bNOLrFR2XC6ZAdo62dZu65gmwGo= +mvdan.cc/gofumpt v0.6.0/go.mod h1:4L0wf+kgIPZtcCWXynNS2e6bhmj73umwnuXSZarixzA= nhooyr.io/websocket v1.8.7 h1:usjR2uOr/zjjkVMy0lW+PPohFok7PCow5sDjLgX4P4g= nhooyr.io/websocket v1.8.7/go.mod h1:B70DZP8IakI65RVQ51MsWP/8jndNma26DVA/nFSCgW0= sigs.k8s.io/yaml v1.4.0 h1:Mk1wCc2gy/F0THH0TAp1QYyJNzRm2KCLy3o5ASXVI5E= diff --git a/integration/integration_test.go b/integration/integration_test.go index ca0ec0b6..a8c12640 100644 --- a/integration/integration_test.go +++ b/integration/integration_test.go @@ -279,7 +279,7 @@ func TestBuildIgnoreVarRunSecrets(t *testing.T) { }, }) dir := t.TempDir() - err := os.WriteFile(filepath.Join(dir, "secret"), []byte("test"), 0644) + err := os.WriteFile(filepath.Join(dir, "secret"), []byte("test"), 0o644) require.NoError(t, err) ctr, err := runEnvbuilder(t, options{ env: []string{ @@ -360,6 +360,7 @@ func TestBuildFromDevcontainerInSubfolder(t *testing.T) { output := execContainer(t, ctr, "echo hello") require.Equal(t, "hello", strings.TrimSpace(output)) } + func TestBuildFromDevcontainerInRoot(t *testing.T) { t.Parallel() @@ -772,7 +773,6 @@ func setupPassthroughRegistry(t *testing.T, image string, auth *registryAuth) st } proxy.ServeHTTP(w, r) - })) return fmt.Sprintf("%s/%s", strings.TrimPrefix(srv.URL, "http://"), image) } diff --git a/options_test.go b/options_test.go index ee5b0fbb..af510619 100644 --- a/options_test.go +++ b/options_test.go @@ -89,7 +89,7 @@ func TestCLIOutput(t *testing.T) { require.NoError(t, err) if *updateCLIOutputGoldenFiles { - err = os.WriteFile("testdata/options.golden", b.Stdout.Bytes(), 0644) + err = os.WriteFile("testdata/options.golden", b.Stdout.Bytes(), 0o644) require.NoError(t, err) t.Logf("updated golden file: testdata/options.golden") } else { @@ -111,7 +111,6 @@ func runCLI() envbuilder.Options { i := cmd.Invoke().WithOS() fakeIO(i) err := i.Run() - if err != nil { panic("failed to run CLI: " + err.Error()) } diff --git a/scripts/docsgen/main.go b/scripts/docsgen/main.go index fa51c242..c79995cf 100644 --- a/scripts/docsgen/main.go +++ b/scripts/docsgen/main.go @@ -30,7 +30,7 @@ func main() { mkd := "\n## Environment Variables\n\n" + options.Markdown() modifiedContent := readmeContent[:startIndex+len(startSection)] + mkd + readmeContent[endIndex:] - err = os.WriteFile(readmePath, []byte(modifiedContent), 0644) + err = os.WriteFile(readmePath, []byte(modifiedContent), 0o644) if err != nil { panic(err) } diff --git a/testutil/gittest/gittest.go b/testutil/gittest/gittest.go index 28629fee..bb34b3f9 100644 --- a/testutil/gittest/gittest.go +++ b/testutil/gittest/gittest.go @@ -143,7 +143,7 @@ func NewRepo(t *testing.T, fs billy.Filesystem, commits ...CommitFunc) *git.Repo // WriteFile writes a file to the filesystem. func WriteFile(t *testing.T, fs billy.Filesystem, path, content string) { t.Helper() - file, err := fs.OpenFile(path, os.O_CREATE|os.O_RDWR, 0644) + file, err := fs.OpenFile(path, os.O_CREATE|os.O_RDWR, 0o644) require.NoError(t, err) _, err = file.Write([]byte(content)) require.NoError(t, err) diff --git a/testutil/registrytest/registrytest.go b/testutil/registrytest/registrytest.go index 4c7e1e13..0bc3d312 100644 --- a/testutil/registrytest/registrytest.go +++ b/testutil/registrytest/registrytest.go @@ -74,7 +74,7 @@ func WriteContainer(t *testing.T, serverURL, containerRef, mediaType string, fil require.NoError(t, err) } err := wtr.WriteHeader(&tar.Header{ - Mode: 0777, + Mode: 0o777, Name: name, Typeflag: tar.TypeReg, Size: int64(len(data)), diff --git a/tools.go b/tools.go new file mode 100644 index 00000000..5d50659e --- /dev/null +++ b/tools.go @@ -0,0 +1,7 @@ +//go:build tools + +package envbuilder + +import ( + _ "mvdan.cc/gofumpt" +) From 3cff2f64224f408ca3c47eb782187e598b91c685 Mon Sep 17 00:00:00 2001 From: BrunoQuaresma Date: Fri, 3 May 2024 14:18:41 +0000 Subject: [PATCH 02/11] Use fmt instead of format --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 5421df0c..77881c7e 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ GOARCH := $(shell go env GOARCH) PWD=$(shell pwd) -format: *.go +fmt: *.go go run mvdan.cc/gofumpt -w . develop: From c2c04e534025d31bb65ebd35a290ab91f0db69a3 Mon Sep 17 00:00:00 2001 From: BrunoQuaresma Date: Fri, 3 May 2024 14:28:57 +0000 Subject: [PATCH 03/11] Add fmt to CI --- .github/workflows/ci.yaml | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index a9055aa1..bada3c31 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -77,3 +77,29 @@ jobs: - name: Check for unstaged files run: git diff --exit-code + fmt: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + ref: ${{ github.event.pull_request.head.sha }} + + - name: Echo Go Cache Paths + id: go-cache-paths + run: | + echo "GOCACHE=$(go env GOCACHE)" >> ${{ runner.os == 'Windows' && '$env:' || '$' }}GITHUB_OUTPUT + echo "GOMODCACHE=$(go env GOMODCACHE)" >> ${{ runner.os == 'Windows' && '$env:' || '$' }}GITHUB_OUTPUT + + - name: Go Build Cache + uses: actions/cache@v3 + with: + path: ${{ steps.go-cache-paths.outputs.GOCACHE }} + key: ${{ runner.os }}-go-build-${{ hashFiles('**/go.**', '**.go') }} + + - uses: actions/setup-go@v3 + with: + go-version: "~1.21" + + - name: Check format + run: test -z $(go run mvdan.cc/gofumpt -l .) From 639031dff12182510661bb90e964f418fbdce4f1 Mon Sep 17 00:00:00 2001 From: BrunoQuaresma Date: Fri, 3 May 2024 18:10:23 +0000 Subject: [PATCH 04/11] Use gofumpt directly --- Makefile | 2 +- go.mod | 3 ++- go.sum | 11 +++++------ tools.go | 7 ------- 4 files changed, 8 insertions(+), 15 deletions(-) delete mode 100644 tools.go diff --git a/Makefile b/Makefile index 77881c7e..63fec176 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,7 @@ GOARCH := $(shell go env GOARCH) PWD=$(shell pwd) fmt: *.go - go run mvdan.cc/gofumpt -w . + go run mvdan.cc/gofumpt@v0.6.0 -l -w . develop: ./scripts/develop.sh diff --git a/go.mod b/go.mod index 623526b0..dfdddb59 100644 --- a/go.mod +++ b/go.mod @@ -124,6 +124,7 @@ require ( github.com/ebitengine/purego v0.5.0-alpha.1 // indirect github.com/emirpasic/gods v1.18.1 // indirect github.com/felixge/httpsnoop v1.0.3 // indirect + github.com/frankban/quicktest v1.14.6 // indirect github.com/fxamacker/cbor/v2 v2.4.0 // indirect github.com/go-chi/chi/v5 v5.0.10 // indirect github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 // indirect @@ -220,6 +221,7 @@ require ( github.com/richardartoul/molecule v1.0.1-0.20221107223329-32cfee06a052 // indirect github.com/rivo/uniseg v0.4.4 // indirect github.com/robfig/cron/v3 v3.0.1 // indirect + github.com/rogpeppe/go-internal v1.12.0 // indirect github.com/rootless-containers/rootlesskit v1.1.0 // indirect github.com/secure-systems-lab/go-securesystemslib v0.7.0 // indirect github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3 // indirect @@ -285,7 +287,6 @@ require ( gvisor.dev/gvisor v0.0.0-20240301031223-3172bc04679b // indirect inet.af/netaddr v0.0.0-20230525184311-b8eac61e914a // indirect inet.af/peercred v0.0.0-20210906144145-0893ea02156a // indirect - mvdan.cc/gofumpt v0.6.0 // indirect nhooyr.io/websocket v1.8.7 // indirect storj.io/drpc v0.0.33-0.20230420154621-9716137f6037 // indirect tailscale.com v1.46.1 // indirect diff --git a/go.sum b/go.sum index bcb4908c..09fc1a01 100644 --- a/go.sum +++ b/go.sum @@ -230,6 +230,7 @@ github.com/coreos/go-systemd/v22 v22.3.2/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSV github.com/coreos/go-systemd/v22 v22.5.0 h1:RrqgGjYQKalulkV8NGVIfkXQf6YYmOyiJKk8iXXhfZs= github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc= github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= +github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= github.com/creack/pty v1.1.18 h1:n56/Zwd5o6whRC5PMGretI4IdRLlmBXYNjScPaBgsbY= github.com/creack/pty v1.1.18/go.mod h1:MOBLtS5ELjhRRrroQr9kyvTxUAFNvYEK993ew/Vr4O4= github.com/cyphar/filepath-securejoin v0.2.4 h1:Ugdm7cg7i6ZK6x3xDF1oEu1nfkyfH53EtKeQYTC3kyg= @@ -290,9 +291,8 @@ github.com/fatih/color v1.16.0/go.mod h1:fL2Sau1YI5c0pdGEVCbKQbLXB6edEj1ZgiY4Nij github.com/felixge/httpsnoop v1.0.1/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U= github.com/felixge/httpsnoop v1.0.3 h1:s/nj+GCswXYzN5v2DpNMuMQYe+0DDwt5WVCU6CWBdXk= github.com/felixge/httpsnoop v1.0.3/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U= -github.com/frankban/quicktest v1.14.5 h1:dfYrrRyLtiqT9GyKXgdh+k4inNeTvmGbuSgZ3lx3GhA= -github.com/frankban/quicktest v1.14.5/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0= github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8= +github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0= github.com/fullsailor/pkcs7 v0.0.0-20190404230743-d7302db945fa h1:RDBNVkRviHZtvDvId8XSGPu3rmpmSe+wKRcEWNgsfWU= github.com/fullsailor/pkcs7 v0.0.0-20190404230743-d7302db945fa/go.mod h1:KnogPXtdwXqoenmZCw6S+25EAm2MkxbG0deNDu4cbSA= github.com/fxamacker/cbor/v2 v2.4.0 h1:ri0ArlOR+5XunOP8CRUowT0pSJOwhW098ZCUyskZD88= @@ -698,6 +698,7 @@ github.com/pion/udp v0.1.4 h1:OowsTmu1Od3sD6i3fQUJxJn2fEvJO6L1TidgadtbTI8= github.com/pion/udp v0.1.4/go.mod h1:G8LDo56HsFwC24LIcnT4YIDU5qcB6NepqqjP0keL2us= github.com/pjbgf/sha1cd v0.3.0 h1:4D5XXmUUBUl/xQ6IjCkEAbqXskkq/4O7LmGn0AqMDs4= github.com/pjbgf/sha1cd v0.3.0/go.mod h1:nZ1rrWOcGJ5uZgEEVL1VUM9iRQiZvWdbZjkKyFzPPsI= +github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA= github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= @@ -734,9 +735,9 @@ github.com/rivo/uniseg v0.4.4 h1:8TfxU8dW6PdqD27gjM8MVNuicgxIjxpm4K7x4jp8sis= github.com/rivo/uniseg v0.4.4/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88= github.com/robfig/cron/v3 v3.0.1 h1:WdRxkvbJztn8LMz/QEvLN5sBU+xKpSqwwUO1Pjr4qDs= github.com/robfig/cron/v3 v3.0.1/go.mod h1:eQICP3HwyT7UooqI/z+Ov+PtYAWygg1TEWWzGIFLtro= -github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M= -github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUzkipdSkR5nkCZA= +github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs= github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU5NdKM8= +github.com/rogpeppe/go-internal v1.12.0/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99yedzYV+kq4uf4= github.com/rootless-containers/rootlesskit v1.1.0 h1:cRaRIYxY8oce4eE/zeAUZhgKu/4tU1p9YHN4+suwV7M= github.com/rootless-containers/rootlesskit v1.1.0/go.mod h1:H+o9ndNe7tS91WqU0/+vpvc+VaCd7TCIWaJjnV0ujUo= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= @@ -1125,8 +1126,6 @@ inet.af/netaddr v0.0.0-20230525184311-b8eac61e914a h1:1XCVEdxrvL6c0TGOhecLuB7U9z inet.af/netaddr v0.0.0-20230525184311-b8eac61e914a/go.mod h1:e83i32mAQOW1LAqEIweALsuK2Uw4mhQadA5r7b0Wobo= inet.af/peercred v0.0.0-20210906144145-0893ea02156a h1:qdkS8Q5/i10xU2ArJMKYhVa1DORzBfYS/qA2UK2jheg= inet.af/peercred v0.0.0-20210906144145-0893ea02156a/go.mod h1:FjawnflS/udxX+SvpsMgZfdqx2aykOlkISeAsADi5IU= -mvdan.cc/gofumpt v0.6.0 h1:G3QvahNDmpD+Aek/bNOLrFR2XC6ZAdo62dZu65gmwGo= -mvdan.cc/gofumpt v0.6.0/go.mod h1:4L0wf+kgIPZtcCWXynNS2e6bhmj73umwnuXSZarixzA= nhooyr.io/websocket v1.8.7 h1:usjR2uOr/zjjkVMy0lW+PPohFok7PCow5sDjLgX4P4g= nhooyr.io/websocket v1.8.7/go.mod h1:B70DZP8IakI65RVQ51MsWP/8jndNma26DVA/nFSCgW0= sigs.k8s.io/yaml v1.4.0 h1:Mk1wCc2gy/F0THH0TAp1QYyJNzRm2KCLy3o5ASXVI5E= diff --git a/tools.go b/tools.go deleted file mode 100644 index 5d50659e..00000000 --- a/tools.go +++ /dev/null @@ -1,7 +0,0 @@ -//go:build tools - -package envbuilder - -import ( - _ "mvdan.cc/gofumpt" -) From 30c05380ab861102978507c40a2a379240b4607e Mon Sep 17 00:00:00 2001 From: BrunoQuaresma Date: Fri, 3 May 2024 18:12:48 +0000 Subject: [PATCH 05/11] Fix make target --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 63fec176..4b52e7b8 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ GOARCH := $(shell go env GOARCH) PWD=$(shell pwd) -fmt: *.go +fmt: **/*.go go run mvdan.cc/gofumpt@v0.6.0 -l -w . develop: From c1a360450e9aa94be3f63215d93845f05d9b7cdd Mon Sep 17 00:00:00 2001 From: BrunoQuaresma Date: Fri, 3 May 2024 18:17:55 +0000 Subject: [PATCH 06/11] Add script to check fmt --- .github/workflows/ci.yaml | 2 +- envbuilder.go | 2 +- scripts/check_fmt.sh | 8 ++++++++ 3 files changed, 10 insertions(+), 2 deletions(-) create mode 100755 scripts/check_fmt.sh diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index bada3c31..636f7e77 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -102,4 +102,4 @@ jobs: go-version: "~1.21" - name: Check format - run: test -z $(go run mvdan.cc/gofumpt -l .) + run: bash ./scripts/check_fmt.sh diff --git a/envbuilder.go b/envbuilder.go index fdfe2c7e..4ddb0b86 100644 --- a/envbuilder.go +++ b/envbuilder.go @@ -151,7 +151,7 @@ func Run(ctx context.Context, options Options) error { if err != nil { return fmt.Errorf("parse docker config: %w", err) } - err = os.WriteFile(filepath.Join(MagicDir, "config.json"), decoded, 0o644) + err = os.WriteFile(filepath.Join(MagicDir, "config.json"), decoded, 0644) if err != nil { return fmt.Errorf("write docker config: %w", err) } diff --git a/scripts/check_fmt.sh b/scripts/check_fmt.sh new file mode 100755 index 00000000..be30ba41 --- /dev/null +++ b/scripts/check_fmt.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +list="$(go run mvdan.cc/gofumpt@v0.6.0 -l .)" +if [[ -n $list ]]; then + echo -e "error: The following files have changes:\n\n${list}\n\nDiff:\n\n" + go run mvdan.cc/gofumpt@v0.6.0 -d . + exit 1 +fi From 54e2edf2b04db1199ae8126e0055087236f65211 Mon Sep 17 00:00:00 2001 From: BrunoQuaresma Date: Fri, 3 May 2024 18:20:39 +0000 Subject: [PATCH 07/11] Simplify CI --- .github/workflows/ci.yaml | 28 ++-------------------------- 1 file changed, 2 insertions(+), 26 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 636f7e77..413e4546 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -56,19 +56,7 @@ jobs: with: ref: ${{ github.event.pull_request.head.sha }} - - name: Echo Go Cache Paths - id: go-cache-paths - run: | - echo "GOCACHE=$(go env GOCACHE)" >> ${{ runner.os == 'Windows' && '$env:' || '$' }}GITHUB_OUTPUT - echo "GOMODCACHE=$(go env GOMODCACHE)" >> ${{ runner.os == 'Windows' && '$env:' || '$' }}GITHUB_OUTPUT - - - name: Go Build Cache - uses: actions/cache@v3 - with: - path: ${{ steps.go-cache-paths.outputs.GOCACHE }} - key: ${{ runner.os }}-go-build-${{ hashFiles('**/go.**', '**.go') }} - - - uses: actions/setup-go@v3 + - uses: actions/setup-go@v5 with: go-version: "~1.21" @@ -85,19 +73,7 @@ jobs: with: ref: ${{ github.event.pull_request.head.sha }} - - name: Echo Go Cache Paths - id: go-cache-paths - run: | - echo "GOCACHE=$(go env GOCACHE)" >> ${{ runner.os == 'Windows' && '$env:' || '$' }}GITHUB_OUTPUT - echo "GOMODCACHE=$(go env GOMODCACHE)" >> ${{ runner.os == 'Windows' && '$env:' || '$' }}GITHUB_OUTPUT - - - name: Go Build Cache - uses: actions/cache@v3 - with: - path: ${{ steps.go-cache-paths.outputs.GOCACHE }} - key: ${{ runner.os }}-go-build-${{ hashFiles('**/go.**', '**.go') }} - - - uses: actions/setup-go@v3 + - uses: actions/setup-go@v5 with: go-version: "~1.21" From f948538ac0969470a53952047ae3750fa5699ba0 Mon Sep 17 00:00:00 2001 From: BrunoQuaresma Date: Fri, 3 May 2024 18:21:54 +0000 Subject: [PATCH 08/11] Only trigger push and pull request to master --- .github/workflows/ci.yaml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 413e4546..cb5a4985 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -2,7 +2,11 @@ name: ci on: push: + branches: + - master pull_request: + branches: + - master workflow_dispatch: permissions: From b1d839e47bc11d63c0dcf0837a49f72225e19a18 Mon Sep 17 00:00:00 2001 From: BrunoQuaresma Date: Fri, 3 May 2024 18:22:42 +0000 Subject: [PATCH 09/11] Remove checkout ref --- .github/workflows/ci.yaml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index cb5a4985..9a984d43 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -57,8 +57,6 @@ jobs: steps: - name: Checkout uses: actions/checkout@v4 - with: - ref: ${{ github.event.pull_request.head.sha }} - uses: actions/setup-go@v5 with: @@ -74,8 +72,6 @@ jobs: steps: - name: Checkout uses: actions/checkout@v4 - with: - ref: ${{ github.event.pull_request.head.sha }} - uses: actions/setup-go@v5 with: From 0e9a75614519269a72fd3f1c3bb8a49f56e9c64a Mon Sep 17 00:00:00 2001 From: BrunoQuaresma Date: Fri, 3 May 2024 18:23:51 +0000 Subject: [PATCH 10/11] Fix branches to be main instead of master --- .github/workflows/ci.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 9a984d43..f7f7872f 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -3,10 +3,10 @@ name: ci on: push: branches: - - master + - main pull_request: branches: - - master + - main workflow_dispatch: permissions: From 6aedc9ffce9ec2d11beda2a3a1969a922190ecf2 Mon Sep 17 00:00:00 2001 From: BrunoQuaresma Date: Fri, 3 May 2024 18:24:52 +0000 Subject: [PATCH 11/11] Fix fmt --- envbuilder.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/envbuilder.go b/envbuilder.go index 4ddb0b86..fdfe2c7e 100644 --- a/envbuilder.go +++ b/envbuilder.go @@ -151,7 +151,7 @@ func Run(ctx context.Context, options Options) error { if err != nil { return fmt.Errorf("parse docker config: %w", err) } - err = os.WriteFile(filepath.Join(MagicDir, "config.json"), decoded, 0644) + err = os.WriteFile(filepath.Join(MagicDir, "config.json"), decoded, 0o644) if err != nil { return fmt.Errorf("write docker config: %w", err) }