From e442550a2181f18a3336fecbe2164237e00cef44 Mon Sep 17 00:00:00 2001 From: Mateusz Urbanek Date: Wed, 2 Aug 2023 08:47:32 +0200 Subject: [PATCH] chore: repo setup (#4) --- .editorconfig | 33 +++++++++++++ .github/ISSUE_TEMPLATES/bug_report.yaml | 20 ++++++++ .github/ISSUE_TEMPLATES/feature_request.yaml | 39 +++++++++++++++ README.md | 6 +-- cmd/{generate => bootstrap}/main.go | 51 ++++++++++++-------- cmd/bootstrap/main_test.go | 41 ++++++++++++++++ cmd/{generate => bootstrap}/templates.go | 4 +- doc.go | 27 ++++------- endpoint.go | 2 +- endpoint_test.go | 2 +- env.go | 2 +- env_test.go | 2 +- gocosi.go | 2 +- gocosi_test.go | 2 +- grpc/handlers/handlers.go | 2 +- grpc/log/log.go | 2 +- metrics.go | 2 +- mocking.go | 2 +- options.go | 2 +- options_test.go | 2 +- testutils/mkdir.go | 2 +- 21 files changed, 193 insertions(+), 54 deletions(-) create mode 100644 .editorconfig create mode 100644 .github/ISSUE_TEMPLATES/bug_report.yaml create mode 100644 .github/ISSUE_TEMPLATES/feature_request.yaml rename cmd/{generate => bootstrap}/main.go (63%) create mode 100644 cmd/bootstrap/main_test.go rename cmd/{generate => bootstrap}/templates.go (98%) diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..09bd544 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,33 @@ +; https://editorconfig.org/ + +root = true + +[*] +insert_final_newline = true +charset = utf-8 +trim_trailing_whitespace = true +indent_style = space +indent_size = 2 + +[{Makefile,go.mod,go.sum,*.go,.gitmodules}] +indent_style = tab +indent_size = 4 + +[*.{py}] +indent_style = space +indent_size = 4 + +# 2 space indentation +[*.{js,json,y{a,}ml}] +indent_style = space +indent_size = 2 +trim_trailing_whitespace = true + +[*.md] +indent_size = 2 +indent_style = space +trim_trailing_whitespace = true +eclint_indent_style = unset + +[Dockerfile] +indent_size = 4 diff --git a/.github/ISSUE_TEMPLATES/bug_report.yaml b/.github/ISSUE_TEMPLATES/bug_report.yaml new file mode 100644 index 0000000..29b48ce --- /dev/null +++ b/.github/ISSUE_TEMPLATES/bug_report.yaml @@ -0,0 +1,20 @@ +name: Bug Report +description: You encountered bug? Unexpected behavior? Open this one. +title: "[BUG]: " +labels: + - kind/bug +body: + - type: textarea + id: what-happened + attributes: + label: What happened? + description: Also, what did you expect to happen? + placeholder: Put your description here. + validations: + required: true + - type: textarea + id: logs + attributes: + label: Relevant log output + description: Please copy and paste any relevant log output. This will be automatically formatted into code, so no need for backticks. + render: Text diff --git a/.github/ISSUE_TEMPLATES/feature_request.yaml b/.github/ISSUE_TEMPLATES/feature_request.yaml new file mode 100644 index 0000000..14d286a --- /dev/null +++ b/.github/ISSUE_TEMPLATES/feature_request.yaml @@ -0,0 +1,39 @@ +name: Feature Request +description: You encountered bug? Unexpected behavior? Open this one. +title: "[FEATURE]: <title>" +labels: + - kind/feature +body: + - type: dropdown + id: contributor + attributes: + label: Are you interested in contributing to the development of this feature? + description: This will help us categorize the issue. + options: + - Yes + - No + validations: + required: true + - type: markdown + attributes: + label: Is your feature request related to a problem? Please describe. + description: A clear and concise description of what the problem is. + validations: + required: true + - type: markdown + attributes: + label: Describe the solution you'd like. + description: A clear and concise description of what you want to happen. + validations: + required: true + - type: markdown + attributes: + label: Describe alternatives you've considered. + description: A clear and concise description of any alternative solutions or features you've considered. + validations: + required: true + - type: input + id: additional_info + attributes: + label: Additional Information + description: Any other relevant information about the feature request. diff --git a/README.md b/README.md index 5e7ff3a..1463858 100644 --- a/README.md +++ b/README.md @@ -22,10 +22,10 @@ A Container Object Storage Interface (COSI) library and other helpful utilities The following example illustrates using `gocosi` Object Storage Plugin bootstrapper to create a new COSI Object Storage Plugin from scratch: ```bash -mkdir -p cosi-osp && cd cosi-osp go run \ - github.com/doomshrine/gocosi/cmd/generate@main \ - example.com/your/cosi-osp + github.com/doomshrine/gocosi/cmd/bootstrap@main \ + -module example.com/your/cosi-osp \ + -dir cosi-osp ``` You will obtain the following file structure in the `cosi-osp` folder: diff --git a/cmd/generate/main.go b/cmd/bootstrap/main.go similarity index 63% rename from cmd/generate/main.go rename to cmd/bootstrap/main.go index c48eea1..859f223 100644 --- a/cmd/generate/main.go +++ b/cmd/bootstrap/main.go @@ -1,4 +1,4 @@ -// Copyright © 2023 doomshrine and gocosi authors. All Rights Reserved. +// Copyright © 2023 gocosi authors. All Rights Reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -16,10 +16,12 @@ package main import ( "errors" + "flag" "fmt" "log" "os" "os/exec" + "path" "text/template" ) @@ -28,30 +30,40 @@ type Config struct { GoVersion string } +var ( + modPath string + directory string +) + func main() { - if err := realMain(); err != nil { + flag.StringVar(&modPath, "module", "example.com/cosi-osp", "Provide name for your new module.") + flag.StringVar(&directory, "dir", "cosi-osp", "Location, where the module will be created.") + flag.Parse() + + if err := realMain(modPath, directory); err != nil { log.Fatal(err) } } -func realMain() error { - if len(os.Args) < 2 { - return errors.New("no name specified") +func realMain(modPath, location string) error { + if modPath == "" || location == "" { + return errors.New("invalid argument") } cfg := Config{ - ModPath: os.Args[1], + ModPath: modPath, GoVersion: "1.20", } - err := os.MkdirAll("./servers/provisioner", 0o755) - if err != nil { - return fmt.Errorf("unable to create './servers/provisioner' directory: %w", err) - } - - err = os.MkdirAll("./servers/identity", 0o755) - if err != nil { - return fmt.Errorf("unable to create './servers/identity' directory: %w", err) + for _, dir := range []string{ + location, + path.Join(location, "servers/provisioner"), + path.Join(location, "servers/identity"), + } { + err := os.MkdirAll(dir, 0o755) + if err != nil { + return fmt.Errorf("unable to create '%s' directory: %w", dir, err) + } } for _, tpl := range []struct { @@ -59,19 +71,19 @@ func realMain() error { template string }{ { - filepath: "go.mod", + filepath: path.Join(location, "go.mod"), template: goMod, }, { - filepath: "main.go", + filepath: path.Join(location, "main.go"), template: mainGo, }, { - filepath: "./servers/provisioner/provisioner.go", + filepath: path.Join(location, "./servers/provisioner/provisioner.go"), template: provisionerGo, }, { - filepath: "./servers/identity/identity.go", + filepath: path.Join(location, "./servers/identity/identity.go"), template: identityGo, }, } { @@ -82,10 +94,11 @@ func realMain() error { } cmd := exec.Command("go", "mod", "tidy") + cmd.Dir = location cmd.Stderr = os.Stderr cmd.Stdout = os.Stdout - err = cmd.Run() + err := cmd.Run() if err != nil { return fmt.Errorf("failed running 'go mod tidy': %w", err) } diff --git a/cmd/bootstrap/main_test.go b/cmd/bootstrap/main_test.go new file mode 100644 index 0000000..7f013fe --- /dev/null +++ b/cmd/bootstrap/main_test.go @@ -0,0 +1,41 @@ +package main + +import ( + "bytes" + "context" + "os" + "os/exec" + "testing" + + "github.com/doomshrine/testcontext" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" +) + +const TestModPath = "main.test/module" + +func TestRealMain(t *testing.T) { + t.Parallel() + + ctx, cancel := testcontext.FromT(context.Background(), t) + defer cancel() + + dir, err := os.MkdirTemp("", "*") + require.NoError(t, err) + + defer os.RemoveAll(dir) + + err = realMain(TestModPath, dir) + require.NoError(t, err) + + bufOut := new(bytes.Buffer) + bufErr := new(bytes.Buffer) + + cmd := exec.CommandContext(ctx, "go", "build") + cmd.Dir = dir + cmd.Stderr = bufErr + cmd.Stdout = bufOut + + err = cmd.Run() + assert.NoError(t, err, "stdout: >>>%s<<<, stderr: >>>%s<<<", bufOut.String(), bufErr.String()) +} diff --git a/cmd/generate/templates.go b/cmd/bootstrap/templates.go similarity index 98% rename from cmd/generate/templates.go rename to cmd/bootstrap/templates.go index 48b3c18..29b7078 100644 --- a/cmd/generate/templates.go +++ b/cmd/bootstrap/templates.go @@ -1,4 +1,4 @@ -// Copyright © 2023 doomshrine and gocosi authors. All Rights Reserved. +// Copyright © 2023 gocosi authors. All Rights Reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -97,7 +97,7 @@ func (s *Server) DriverGetInfo(_ context.Context, _ *cosi.DriverGetInfoRequest) return &cosi.DriverGetInfoResponse{ Name: s.name, }, nil -} +} ` const provisionerGo = `package provisioner diff --git a/doc.go b/doc.go index 42117a5..3124f2a 100644 --- a/doc.go +++ b/doc.go @@ -1,4 +1,4 @@ -// Copyright © 2023 doomshrine and gocosi authors. All Rights Reserved. +// Copyright © 2023 gocosi authors. All Rights Reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -18,29 +18,22 @@ // // The following example illustrates using `gocosi` Object Storage Plugin bootstrapper to create a new COSI Object Storage Plugin from scratch: // -// ```bash -// mkdir -p cosi-osp && cd cosi-osp -// // go run \ -// github.com/doomshrine/gocosi/cmd/generate@main \ -// example.com/your/cosi-osp -// -// ``` +// github.com/doomshrine/gocosi/cmd/bootstrap@main \ +// -module example.com/your/cosi-osp \ +// -dir cosi-osp // // You will obtain the following file structure in the `cosi-osp` folder: // -// ``` -// cosi-osp -// ├── go.mod -// ├── go.sum -// ├── main.go -// └── servers -// +// cosi-osp +// ├── go.mod +// ├── go.sum +// ├── main.go +// └── servers // ├── identity // │ └── identity.go // └── provisioner // └── provisioner.go // -// 4 directories, 5 files -// ``` +// 4 directories, 5 files package gocosi diff --git a/endpoint.go b/endpoint.go index 4a374bb..3599404 100644 --- a/endpoint.go +++ b/endpoint.go @@ -1,4 +1,4 @@ -// Copyright © 2023 doomshrine and gocosi authors. All Rights Reserved. +// Copyright © 2023 gocosi authors. All Rights Reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/endpoint_test.go b/endpoint_test.go index 6c74b12..5876db5 100644 --- a/endpoint_test.go +++ b/endpoint_test.go @@ -1,4 +1,4 @@ -// Copyright © 2023 doomshrine and gocosi authors. All Rights Reserved. +// Copyright © 2023 gocosi authors. All Rights Reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/env.go b/env.go index 333b624..fab7f39 100644 --- a/env.go +++ b/env.go @@ -1,4 +1,4 @@ -// Copyright © 2023 doomshrine and gocosi authors. All Rights Reserved. +// Copyright © 2023 gocosi authors. All Rights Reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/env_test.go b/env_test.go index f906f4b..aee253b 100644 --- a/env_test.go +++ b/env_test.go @@ -1,4 +1,4 @@ -// Copyright © 2023 doomshrine and gocosi authors. All Rights Reserved. +// Copyright © 2023 gocosi authors. All Rights Reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/gocosi.go b/gocosi.go index f6610d9..76538f3 100644 --- a/gocosi.go +++ b/gocosi.go @@ -1,4 +1,4 @@ -// Copyright © 2023 doomshrine and gocosi authors. All Rights Reserved. +// Copyright © 2023 gocosi authors. All Rights Reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/gocosi_test.go b/gocosi_test.go index 6db280a..f77642f 100644 --- a/gocosi_test.go +++ b/gocosi_test.go @@ -1,4 +1,4 @@ -// Copyright © 2023 doomshrine and gocosi authors. All Rights Reserved. +// Copyright © 2023 gocosi authors. All Rights Reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/grpc/handlers/handlers.go b/grpc/handlers/handlers.go index 51d7a9b..7dc9a4f 100644 --- a/grpc/handlers/handlers.go +++ b/grpc/handlers/handlers.go @@ -1,4 +1,4 @@ -// Copyright © 2023 doomshrine and gocosi authors. All Rights Reserved. +// Copyright © 2023 gocosi authors. All Rights Reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/grpc/log/log.go b/grpc/log/log.go index cc4d22a..8397bca 100644 --- a/grpc/log/log.go +++ b/grpc/log/log.go @@ -1,4 +1,4 @@ -// Copyright © 2023 doomshrine and gocosi authors. All Rights Reserved. +// Copyright © 2023 gocosi authors. All Rights Reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/metrics.go b/metrics.go index 4ac7188..81019b9 100644 --- a/metrics.go +++ b/metrics.go @@ -1,4 +1,4 @@ -// Copyright © 2023 doomshrine and gocosi authors. All Rights Reserved. +// Copyright © 2023 gocosi authors. All Rights Reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/mocking.go b/mocking.go index 217dd6b..db7a7e6 100644 --- a/mocking.go +++ b/mocking.go @@ -1,4 +1,4 @@ -// Copyright © 2023 doomshrine and gocosi authors. All Rights Reserved. +// Copyright © 2023 gocosi authors. All Rights Reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/options.go b/options.go index 88abc35..30d4472 100644 --- a/options.go +++ b/options.go @@ -1,4 +1,4 @@ -// Copyright © 2023 doomshrine and gocosi authors. All Rights Reserved. +// Copyright © 2023 gocosi authors. All Rights Reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/options_test.go b/options_test.go index f906f4b..aee253b 100644 --- a/options_test.go +++ b/options_test.go @@ -1,4 +1,4 @@ -// Copyright © 2023 doomshrine and gocosi authors. All Rights Reserved. +// Copyright © 2023 gocosi authors. All Rights Reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/testutils/mkdir.go b/testutils/mkdir.go index f780294..7bf0ee7 100644 --- a/testutils/mkdir.go +++ b/testutils/mkdir.go @@ -1,4 +1,4 @@ -// Copyright © 2023 doomshrine and gocosi authors. All Rights Reserved. +// Copyright © 2023 gocosi authors. All Rights Reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License.