diff --git a/.github/workflows/publish_release.yml b/.github/workflows/publish_release.yml new file mode 100644 index 00000000..43f4aa2a --- /dev/null +++ b/.github/workflows/publish_release.yml @@ -0,0 +1,26 @@ +name: Publish Release + +on: + push: + tags: + - v* + +jobs: + build: + runs-on: ubuntu-20.04 + steps: + - name: Check out code + uses: actions/checkout@v4 + - name: Setup go env + uses: actions/setup-go@master + with: + go-version: "1.20" + - name: goreleaser with tag + uses: goreleaser/goreleaser-action@v5 + with: + version: latest + args: release --rm-dist + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + diff --git a/.gitignore b/.gitignore index 0d543d05..4f6c7b6e 100644 --- a/.gitignore +++ b/.gitignore @@ -19,6 +19,7 @@ # Go workspace file go.work +/bin -# harbor compiled file -harbor +/harbor +dist/ diff --git a/.goreleaser.yaml b/.goreleaser.yaml new file mode 100644 index 00000000..864ff7a7 --- /dev/null +++ b/.goreleaser.yaml @@ -0,0 +1,37 @@ +project_name: harbor + +builds: +- main: ./cmd/harbor + binary: ./harbor + env: + - CGO_ENABLED=0 + ldflags: + - -w -s -X github.com/goharbor/harbor-cli/cmd/harbor/internal/version.GitCommit={{.FullCommit}} + goos: + - linux + - windows + - darwin + goarch: + - amd64 + - arm64 + - arm + ignore: + - goos: windows + goarch: arm + - goos: windows + goarch: arm64 +archives: +- format: tar.gz + format_overrides: + - goos: windows + format: zip +release: + draft: true + prerelease: auto + +changelog: + sort: asc + filters: + exclude: + - "^docs:" + - "^test:" diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md new file mode 100644 index 00000000..c858b9fb --- /dev/null +++ b/CODE_OF_CONDUCT.md @@ -0,0 +1,3 @@ +# Code of Conduct + +Harbor follows the [CNCF Code of Conduct](https://github.com/cncf/foundation/blob/master/code-of-conduct.md). diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 00000000..e69de29b diff --git a/Makefile b/Makefile new file mode 100644 index 00000000..266d25cb --- /dev/null +++ b/Makefile @@ -0,0 +1,35 @@ +GITCOMMIT := $(shell git rev-parse --short=8 HEAD) +PROJECT_PKG = github.com/goharbor/harbor-cli +RELEASE_CHANNEL="edge" +LDFLAGS = "-w -s -X $(PROJECT_PKG)/version.GitCommit=$(GITCOMMIT) -X $(PROJECT_PKG)/version.ReleaseChannel=$(RELEASE_CHANNEL)" +ARCH := amd64 +GO_EXE = go + +make: + gofmt -l -s -w . + go build -ldflags=${LDFLAGS} -o harbor cmd/harbor/main.go + +windows: + go build -ldflags=${LDFLAGS} -o harbor.exe cmd/harbor/main.go + +.PHONY: build-win-amd64 +build-win-amd64: ## build for windows amd64 + CGO_ENABLED=0 GOARCH=$(ARCH) GOOS=windows $(GO_EXE) build -v --ldflags=$(LDFLAGS) \ + -o bin/harbor-windows-$(ARCH).exe ./cmd/harbor/main.go +.PHONY: build-linux-amd64 +build-linux-amd64: ## build for linux amd64 + CGO_ENABLED=0 GOARCH=$(ARCH) GOOS=linux $(GO_EXE) build -v --ldflags=$(LDFLAGS) \ + -o bin/harbor-linux-$(ARCH) ./cmd/harbor/main.go + +.PHONY: build-darwin-amd64 +build-darwin-amd64: ## build for darwin amd64 + CGO_ENABLED=0 GOARCH=$(ARCH) GOOS=darwin $(GO_EXE) build -v --ldflags=$(LDFLAGS) \ + -o bin/harbor-darwin-$(ARCH) ./cmd/harbor/main.go + +.PHONY: clean +clean: + rm -rf bin + +.PHONY: lint +lint: + golangci-lint run --timeout 5m \ No newline at end of file diff --git a/cmd/harbor/internal/version/version.go b/cmd/harbor/internal/version/version.go new file mode 100644 index 00000000..ea93c6a9 --- /dev/null +++ b/cmd/harbor/internal/version/version.go @@ -0,0 +1,10 @@ +package version + +var ( + Version = "0.1.0" + GitCommit = "" +) + +func GetVersion() string { + return Version +} diff --git a/cmd/harbor/main.go b/cmd/harbor/main.go new file mode 100644 index 00000000..d111ea2c --- /dev/null +++ b/cmd/harbor/main.go @@ -0,0 +1,14 @@ +package main + +import ( + "os" + + "github.com/goharbor/harbor-cli/cmd/harbor/root" +) + +func main() { + err := root.New().Execute() + if err != nil { + os.Exit(1) + } +} diff --git a/cmd/root.go b/cmd/harbor/root/cmd.go similarity index 65% rename from cmd/root.go rename to cmd/harbor/root/cmd.go index a8a2247b..5ffbee71 100644 --- a/cmd/root.go +++ b/cmd/harbor/root/cmd.go @@ -1,10 +1,9 @@ -package cmd +package root import ( - "github.com/akshatdalton/harbor-cli/cmd/constants" - "github.com/akshatdalton/harbor-cli/cmd/login" - "github.com/akshatdalton/harbor-cli/cmd/project" - "github.com/akshatdalton/harbor-cli/cmd/registry" + "github.com/goharbor/harbor-cli/cmd/harbor/root/project" + "github.com/goharbor/harbor-cli/cmd/harbor/root/registry" + "github.com/goharbor/harbor-cli/pkg/constants" "github.com/spf13/cobra" ) @@ -17,8 +16,8 @@ func newGetCommand() *cobra.Command { } cmd.PersistentFlags().String(constants.CredentialNameOption, "", constants.CredentialNameHelp) - cmd.AddCommand(project.NewGetProjectCommand()) - cmd.AddCommand(registry.NewGetRegistryCommand()) + cmd.AddCommand(project.GetProjectCommand()) + cmd.AddCommand(registry.GetRegistryCommand()) return cmd } @@ -31,8 +30,8 @@ func newListCommand() *cobra.Command { } cmd.PersistentFlags().String(constants.CredentialNameOption, "", constants.CredentialNameHelp) - cmd.AddCommand(project.NewListProjectCommand()) - cmd.AddCommand(registry.NewListRegistryCommand()) + cmd.AddCommand(project.ListProjectCommand()) + cmd.AddCommand(registry.ListRegistryCommand()) return cmd } @@ -45,8 +44,8 @@ func newCreateCommand() *cobra.Command { } cmd.PersistentFlags().String(constants.CredentialNameOption, "", constants.CredentialNameHelp) - cmd.AddCommand(project.NewCreateProjectCommand()) - cmd.AddCommand(registry.NewCreateRegistryCommand()) + cmd.AddCommand(project.CreateProjectCommand()) + cmd.AddCommand(registry.CreateRegistryCommand()) return cmd } @@ -59,8 +58,8 @@ func newDeleteCommand() *cobra.Command { } cmd.PersistentFlags().String(constants.CredentialNameOption, "", constants.CredentialNameHelp) - cmd.AddCommand(project.NewDeleteProjectCommand()) - cmd.AddCommand(registry.NewDeleteRegistryCommand()) + cmd.AddCommand(project.DeleteProjectCommand()) + cmd.AddCommand(registry.DeleteRegistryCommand()) return cmd } @@ -73,26 +72,24 @@ func newUpdateCommand() *cobra.Command { } cmd.PersistentFlags().String(constants.CredentialNameOption, "", constants.CredentialNameHelp) - cmd.AddCommand(registry.NewUpdateRegistryCommand()) + cmd.AddCommand(registry.UpdateRegistryCommand()) return cmd } -func addCommands(cmd *cobra.Command) { - cmd.AddCommand(login.NewLoginCommand()) - cmd.AddCommand(newGetCommand()) - cmd.AddCommand(newListCommand()) - cmd.AddCommand(newCreateCommand()) - cmd.AddCommand(newDeleteCommand()) - cmd.AddCommand(newUpdateCommand()) -} - // CreateHarborCLI creates a new Harbor CLI -func CreateHarborCLI() *cobra.Command { +func New() *cobra.Command { cmd := &cobra.Command{ - Use: "harbor", + Use: "harbor [command]", Short: "Official Harbor CLI", } - addCommands(cmd) + cmd.AddCommand( + LoginCommand(), + newGetCommand(), + newListCommand(), + newCreateCommand(), + newDeleteCommand(), + newUpdateCommand(), + ) return cmd } diff --git a/cmd/login/login.go b/cmd/harbor/root/login.go similarity index 91% rename from cmd/login/login.go rename to cmd/harbor/root/login.go index d854da2a..f6fea4fd 100644 --- a/cmd/login/login.go +++ b/cmd/harbor/root/login.go @@ -1,12 +1,12 @@ -package login +package root import ( "context" "fmt" - "github.com/akshatdalton/harbor-cli/cmd/utils" "github.com/goharbor/go-client/pkg/harbor" "github.com/goharbor/go-client/pkg/sdk/v2.0/client/user" + "github.com/goharbor/harbor-cli/pkg/utils" "github.com/spf13/cobra" ) @@ -17,8 +17,8 @@ type loginOptions struct { password string } -// NewLoginCommand creates a new `harbor login` command -func NewLoginCommand() *cobra.Command { +// LoginCommand creates a new `harbor login` command +func LoginCommand() *cobra.Command { var opts loginOptions cmd := &cobra.Command{ diff --git a/cmd/project/create_project.go b/cmd/harbor/root/project/create_project.go similarity index 87% rename from cmd/project/create_project.go rename to cmd/harbor/root/project/create_project.go index 03a4460a..974a53c5 100644 --- a/cmd/project/create_project.go +++ b/cmd/harbor/root/project/create_project.go @@ -3,10 +3,10 @@ package project import ( "context" - "github.com/akshatdalton/harbor-cli/cmd/constants" - "github.com/akshatdalton/harbor-cli/cmd/utils" "github.com/goharbor/go-client/pkg/sdk/v2.0/client/project" "github.com/goharbor/go-client/pkg/sdk/v2.0/models" + "github.com/goharbor/harbor-cli/pkg/constants" + "github.com/goharbor/harbor-cli/pkg/utils" "github.com/spf13/cobra" ) @@ -17,8 +17,8 @@ type createProjectOptions struct { storageLimit int64 } -// NewCreateProjectCommand creates a new `harbor create project` command -func NewCreateProjectCommand() *cobra.Command { +// CreateProjectCommand creates a new `harbor create project` command +func CreateProjectCommand() *cobra.Command { var opts createProjectOptions cmd := &cobra.Command{ diff --git a/cmd/project/delete_project.go b/cmd/harbor/root/project/delete_project.go similarity index 82% rename from cmd/project/delete_project.go rename to cmd/harbor/root/project/delete_project.go index e3d077b9..1529bb99 100644 --- a/cmd/project/delete_project.go +++ b/cmd/harbor/root/project/delete_project.go @@ -3,9 +3,9 @@ package project import ( "context" - "github.com/akshatdalton/harbor-cli/cmd/constants" - "github.com/akshatdalton/harbor-cli/cmd/utils" "github.com/goharbor/go-client/pkg/sdk/v2.0/client/project" + "github.com/goharbor/harbor-cli/pkg/constants" + "github.com/goharbor/harbor-cli/pkg/utils" "github.com/spf13/cobra" ) @@ -13,8 +13,8 @@ type deleteProjectOptions struct { projectNameOrID string } -// NewDeleteProjectCommand creates a new `harbor delete project` command -func NewDeleteProjectCommand() *cobra.Command { +// DeleteProjectCommand creates a new `harbor delete project` command +func DeleteProjectCommand() *cobra.Command { var opts deleteProjectOptions cmd := &cobra.Command{ diff --git a/cmd/project/list_project.go b/cmd/harbor/root/project/ls_project.go similarity index 92% rename from cmd/project/list_project.go rename to cmd/harbor/root/project/ls_project.go index b3cca99a..bbac1096 100644 --- a/cmd/project/list_project.go +++ b/cmd/harbor/root/project/ls_project.go @@ -3,9 +3,9 @@ package project import ( "context" - "github.com/akshatdalton/harbor-cli/cmd/constants" - "github.com/akshatdalton/harbor-cli/cmd/utils" "github.com/goharbor/go-client/pkg/sdk/v2.0/client/project" + "github.com/goharbor/harbor-cli/pkg/constants" + "github.com/goharbor/harbor-cli/pkg/utils" "github.com/spf13/cobra" ) @@ -21,7 +21,7 @@ type listProjectOptions struct { } // NewListProjectCommand creates a new `harbor list project` command -func NewListProjectCommand() *cobra.Command { +func ListProjectCommand() *cobra.Command { var opts listProjectOptions cmd := &cobra.Command{ diff --git a/cmd/project/get_project.go b/cmd/harbor/root/project/view_project.go similarity index 82% rename from cmd/project/get_project.go rename to cmd/harbor/root/project/view_project.go index 0e2d5043..a727caf7 100644 --- a/cmd/project/get_project.go +++ b/cmd/harbor/root/project/view_project.go @@ -3,9 +3,9 @@ package project import ( "context" - "github.com/akshatdalton/harbor-cli/cmd/constants" - "github.com/akshatdalton/harbor-cli/cmd/utils" "github.com/goharbor/go-client/pkg/sdk/v2.0/client/project" + "github.com/goharbor/harbor-cli/pkg/constants" + "github.com/goharbor/harbor-cli/pkg/utils" "github.com/spf13/cobra" ) @@ -13,8 +13,8 @@ type getProjectOptions struct { projectNameOrID string } -// NewGetProjectCommand creates a new `harbor get project` command -func NewGetProjectCommand() *cobra.Command { +// GetProjectCommand creates a new `harbor get project` command +func GetProjectCommand() *cobra.Command { var opts getProjectOptions cmd := &cobra.Command{ diff --git a/cmd/registry/create_registry.go b/cmd/harbor/root/registry/create_registry.go similarity index 94% rename from cmd/registry/create_registry.go rename to cmd/harbor/root/registry/create_registry.go index 52d44224..475c478a 100644 --- a/cmd/registry/create_registry.go +++ b/cmd/harbor/root/registry/create_registry.go @@ -3,10 +3,10 @@ package registry import ( "context" - "github.com/akshatdalton/harbor-cli/cmd/constants" - "github.com/akshatdalton/harbor-cli/cmd/utils" "github.com/goharbor/go-client/pkg/sdk/v2.0/client/registry" "github.com/goharbor/go-client/pkg/sdk/v2.0/models" + "github.com/goharbor/harbor-cli/pkg/constants" + "github.com/goharbor/harbor-cli/pkg/utils" "github.com/spf13/cobra" ) @@ -24,7 +24,7 @@ type createRegistrytOptions struct { } // NewCreateRegistryCommand creates a new `harbor create registry` command -func NewCreateRegistryCommand() *cobra.Command { +func CreateRegistryCommand() *cobra.Command { var opts createRegistrytOptions cmd := &cobra.Command{ diff --git a/cmd/registry/delete_registry.go b/cmd/harbor/root/registry/delete_registry.go similarity index 88% rename from cmd/registry/delete_registry.go rename to cmd/harbor/root/registry/delete_registry.go index 8d230162..a48d8d1f 100644 --- a/cmd/registry/delete_registry.go +++ b/cmd/harbor/root/registry/delete_registry.go @@ -5,9 +5,9 @@ import ( "fmt" "strconv" - "github.com/akshatdalton/harbor-cli/cmd/constants" - "github.com/akshatdalton/harbor-cli/cmd/utils" "github.com/goharbor/go-client/pkg/sdk/v2.0/client/registry" + "github.com/goharbor/harbor-cli/pkg/constants" + "github.com/goharbor/harbor-cli/pkg/utils" "github.com/spf13/cobra" ) @@ -16,7 +16,7 @@ type deleteRegistryOptions struct { } // NewDeleteRegistryCommand creates a new `harbor delete registry` command -func NewDeleteRegistryCommand() *cobra.Command { +func DeleteRegistryCommand() *cobra.Command { var opts deleteRegistryOptions cmd := &cobra.Command{ diff --git a/cmd/registry/list_registry.go b/cmd/harbor/root/registry/ls_registry.go similarity index 90% rename from cmd/registry/list_registry.go rename to cmd/harbor/root/registry/ls_registry.go index 4c3329c6..1a8ca789 100644 --- a/cmd/registry/list_registry.go +++ b/cmd/harbor/root/registry/ls_registry.go @@ -3,9 +3,9 @@ package registry import ( "context" - "github.com/akshatdalton/harbor-cli/cmd/constants" - "github.com/akshatdalton/harbor-cli/cmd/utils" "github.com/goharbor/go-client/pkg/sdk/v2.0/client/registry" + "github.com/goharbor/harbor-cli/pkg/constants" + "github.com/goharbor/harbor-cli/pkg/utils" "github.com/spf13/cobra" ) @@ -17,7 +17,7 @@ type listRegistryOptions struct { } // NewListRegistryCommand creates a new `harbor list registry` command -func NewListRegistryCommand() *cobra.Command { +func ListRegistryCommand() *cobra.Command { var opts listRegistryOptions cmd := &cobra.Command{ diff --git a/cmd/registry/update_registry.go b/cmd/harbor/root/registry/update_registry.go similarity index 95% rename from cmd/registry/update_registry.go rename to cmd/harbor/root/registry/update_registry.go index e31f972b..a7553dda 100644 --- a/cmd/registry/update_registry.go +++ b/cmd/harbor/root/registry/update_registry.go @@ -5,10 +5,10 @@ import ( "fmt" "strconv" - "github.com/akshatdalton/harbor-cli/cmd/constants" - "github.com/akshatdalton/harbor-cli/cmd/utils" "github.com/goharbor/go-client/pkg/sdk/v2.0/client/registry" "github.com/goharbor/go-client/pkg/sdk/v2.0/models" + "github.com/goharbor/harbor-cli/pkg/constants" + "github.com/goharbor/harbor-cli/pkg/utils" "github.com/spf13/cobra" ) @@ -27,7 +27,7 @@ type updateRegistrytOptions struct { } // NewUpdateRegistryCommand creates a new `harbor update registry` command -func NewUpdateRegistryCommand() *cobra.Command { +func UpdateRegistryCommand() *cobra.Command { var opts updateRegistrytOptions cmd := &cobra.Command{ diff --git a/cmd/registry/get_registry.go b/cmd/harbor/root/registry/view_registry.go similarity index 88% rename from cmd/registry/get_registry.go rename to cmd/harbor/root/registry/view_registry.go index b258ec69..51d1d1d2 100644 --- a/cmd/registry/get_registry.go +++ b/cmd/harbor/root/registry/view_registry.go @@ -5,9 +5,9 @@ import ( "fmt" "strconv" - "github.com/akshatdalton/harbor-cli/cmd/constants" - "github.com/akshatdalton/harbor-cli/cmd/utils" "github.com/goharbor/go-client/pkg/sdk/v2.0/client/registry" + "github.com/goharbor/harbor-cli/pkg/constants" + "github.com/goharbor/harbor-cli/pkg/utils" "github.com/spf13/cobra" ) @@ -16,7 +16,7 @@ type getRegistryOptions struct { } // NewGetRegistryCommand creates a new `harbor get registry` command -func NewGetRegistryCommand() *cobra.Command { +func GetRegistryCommand() *cobra.Command { var opts getRegistryOptions cmd := &cobra.Command{ diff --git a/doc/doc.md b/doc/doc.md new file mode 100644 index 00000000..7c37f8a1 --- /dev/null +++ b/doc/doc.md @@ -0,0 +1 @@ +We can create a worker function to automatically generate documents for users whenever a new release is available. This function will streamline the process of document generation and ensure that users have up-to-date information. By automating this task, we can improve efficiency and provide clear and concise documentation in a user-friendly manner. //@amands \ No newline at end of file diff --git a/go.mod b/go.mod index b8e8fda1..942a65fa 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module github.com/akshatdalton/harbor-cli +module github.com/goharbor/harbor-cli go 1.20 diff --git a/main.go b/main.go deleted file mode 100644 index 96959a41..00000000 --- a/main.go +++ /dev/null @@ -1,14 +0,0 @@ -package main - -import ( - "os" - - "github.com/akshatdalton/harbor-cli/cmd" -) - -func main() { - harborCLI := cmd.CreateHarborCLI() - if err := harborCLI.Execute(); err != nil { - os.Exit(1) - } -} diff --git a/cmd/constants/constants.go b/pkg/constants/constants.go similarity index 100% rename from cmd/constants/constants.go rename to pkg/constants/constants.go diff --git a/cmd/utils/credential_store.go b/pkg/utils/credential_store.go similarity index 98% rename from cmd/utils/credential_store.go rename to pkg/utils/credential_store.go index 91ddd1b5..61d10464 100644 --- a/cmd/utils/credential_store.go +++ b/pkg/utils/credential_store.go @@ -9,7 +9,7 @@ import ( "path/filepath" "github.com/adrg/xdg" - "github.com/akshatdalton/harbor-cli/cmd/constants" + "github.com/goharbor/harbor-cli/pkg/constants" "gopkg.in/yaml.v2" ) diff --git a/cmd/utils/utils.go b/pkg/utils/utils.go similarity index 100% rename from cmd/utils/utils.go rename to pkg/utils/utils.go diff --git a/test/e2e/test.md b/test/e2e/test.md new file mode 100644 index 00000000..5a7ec666 --- /dev/null +++ b/test/e2e/test.md @@ -0,0 +1 @@ +e2e tests for cmd can slide in here \ No newline at end of file