From fc667a68d50cb36d23027aab27392eaf1002a99d Mon Sep 17 00:00:00 2001 From: Ben Jackson Date: Thu, 8 Aug 2024 13:14:15 +1000 Subject: [PATCH] chore: update build instructions and mockgen version (#372) --- .github/workflows/goreleaser.yaml | 2 +- .github/workflows/lagoon-cli.yaml | 2 +- .github/workflows/release.yaml | 2 +- Makefile | 19 ++-------------- README.md | 36 ++++++++++++++++++------------ go.mod | 1 + go.sum | 2 ++ internal/lagoon/import_test.go | 2 +- internal/mock/mock_importer.go | 37 ++++++++++++++++++------------- 9 files changed, 52 insertions(+), 51 deletions(-) diff --git a/.github/workflows/goreleaser.yaml b/.github/workflows/goreleaser.yaml index b2c45aaf..ba2b17d4 100644 --- a/.github/workflows/goreleaser.yaml +++ b/.github/workflows/goreleaser.yaml @@ -24,7 +24,7 @@ jobs: go-version: ${{matrix.goversion}} - name: Build run: | - go install github.com/golang/mock/mockgen@v1.4.3 + go install go.uber.org/mock/mockgen@v0.4.0 ARTIFACT_DESTINATION=./builds make build # - name: Check version # run: | diff --git a/.github/workflows/lagoon-cli.yaml b/.github/workflows/lagoon-cli.yaml index 1d9a7a5c..bd5614a7 100644 --- a/.github/workflows/lagoon-cli.yaml +++ b/.github/workflows/lagoon-cli.yaml @@ -28,7 +28,7 @@ jobs: go-version: ${{matrix.goversion}} - name: Build run: | - go install github.com/golang/mock/mockgen@v1.4.3 + go install go.uber.org/mock/mockgen@v0.4.0 ARTIFACT_DESTINATION=./builds make build # - name: Check version # run: | diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 3870687d..21f08e8d 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -19,7 +19,7 @@ jobs: go-version: 1.21 - name: Build CLI run: | - go install github.com/golang/mock/mockgen@v1.4.3 + go install go.uber.org/mock/mockgen@v0.4.0 make deps make test - name: Compile CLI diff --git a/Makefile b/Makefile index cdc78c0a..ee0c42fe 100644 --- a/Makefile +++ b/Makefile @@ -38,6 +38,8 @@ build-linux: test GO111MODULE=on CGO_ENABLED=0 GOOS=linux GOARCH=amd64 $(GOCMD) build -ldflags '${LDFLAGS} -X "${PKG}/cmd.lagoonCLIBuildGoVersion=${GO_VER}"' -o builds/lagoon-cli-${VERSION}-linux-amd64 -v build-darwin: test GO111MODULE=on CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 $(GOCMD) build -ldflags '${LDFLAGS} -X "${PKG}/cmd.lagoonCLIBuildGoVersion=${GO_VER}"' -o builds/lagoon-cli-${VERSION}-darwin-amd64 -v +build-darwin-arm64: test + GO111MODULE=on CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 $(GOCMD) build -ldflags '${LDFLAGS} -X "${PKG}/cmd.lagoonCLIBuildGoVersion=${GO_VER}"' -o builds/lagoon-cli-${VERSION}-darwin-arm64 -v docs: test LAGOON_GEN_DOCS=true GO111MODULE=on $(GOCMD) run main.go --docs @@ -96,20 +98,3 @@ install-linux: install-darwin: cp builds/lagoon-cli-${VERSION}-darwin-amd64 ${ARTIFACT_DESTINATION}/lagoon -release-patch: - $(eval VERSION=$(shell ${PWD}/increment_ver.sh -p $(shell git describe --abbrev=0 --tags))) - git tag $(VERSION) - mkdocs gh-deploy - git push $(GIT_ORIGIN) main --tags - -release-minor: - $(eval VERSION=$(shell ${PWD}/increment_ver.sh -m $(shell git describe --abbrev=0 --tags))) - git tag $(VERSION) - mkdocs gh-deploy - git push $(GIT_ORIGIN) main --tags - -release-major: - $(eval VERSION=$(shell ${PWD}/increment_ver.sh -M $(shell git describe --abbrev=0 --tags))) - git tag $(VERSION) - mkdocs gh-deploy - git push $(GIT_ORIGIN) main --tags diff --git a/README.md b/README.md index ee57bb1c..35eaa81f 100644 --- a/README.md +++ b/README.md @@ -27,20 +27,38 @@ lagoon ### Commands For the full list of commands see the docs for [Lagoon CLI](https://uselagoon.github.io/lagoon-cli/commands/lagoon/) -## Build +## Building -Note: You should make sure you have your `GOPATH` configured and in your path if you are going to build the lagoon CLI. If you haven't got `go` installed and are using the docker method, you can export `GOPATH` to be somewhere else in your `PATH` for binaries. +### Requirements + +Install `Go` - https://go.dev/doc/install + +You also need `mockgen`, it can be installed using the following command once `Go` is installed. + +``` +go install go.uber.org/mock/mockgen@v0.4.0 +``` + +Note: You should make sure you have your `GOPATH` configured and in your path, see https://pkg.go.dev/cmd/go#hdr-GOPATH_environment_variable ### Run tests ``` make test -make test-docker ``` ### Build locally + +You can compile the binary and load it into your `GOPATH` bin directory using the following. +``` +make build +``` + +Alternatively, these will compile a binary inside a `builds` directory in this repository, you can place them wherever you wish. ``` make build-linux -make build-darwin #macos +#macos +make build-darwin +make build-darwin-arm64 ``` ### Build using Docker @@ -57,14 +75,6 @@ make all-docker-linux make all-docker-darwin ``` -### Releasing -New releases can be created by running one of the following, this will create the version bump and update the `gh-pages` branch -``` -make release-patch -make release-minor -make release-major -``` - ### Install ``` make ARTIFACT_DESTINATION=/usr/local/bin install-linux @@ -77,8 +87,6 @@ Versions can also be defined, and the binaries will be version tagged make VERSION=v0.0.1 ... ``` - - ### Acknowledgements [Matt Glaman](https://github.com/mglaman) - Initial conception and development - Thanks Matt! diff --git a/go.mod b/go.mod index 37f103f8..39ccf638 100644 --- a/go.mod +++ b/go.mod @@ -37,6 +37,7 @@ require ( github.com/pmezard/go-difflib v1.0.0 // indirect github.com/rivo/uniseg v0.2.0 // indirect github.com/russross/blackfriday/v2 v2.1.0 // indirect + go.uber.org/mock v0.4.0 // indirect golang.org/x/sys v0.18.0 // indirect ) diff --git a/go.sum b/go.sum index 6b01b7af..c323d489 100644 --- a/go.sum +++ b/go.sum @@ -69,6 +69,8 @@ github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o github.com/uselagoon/machinery v0.0.27 h1:luIrdAiVhCPgxAwh2gtPm5iepMnXyTR6sNbuLuBhk80= github.com/uselagoon/machinery v0.0.27/go.mod h1:NbgtEofjK2XY0iUpk9aMYazIo+W/NI56+UF72jv8zVY= github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= +go.uber.org/mock v0.4.0 h1:VcM4ZOtdbR4f6VXfiOpwpVJDL6lCReaZ6mw31wqh7KU= +go.uber.org/mock v0.4.0/go.mod h1:a6FSlNadKUHUa9IP5Vyt1zh4fC7uAwxMutEAscFbkZc= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.21.0 h1:X31++rzVUdKhX5sWmSOFZxx8UW/ldWx55cbf08iNAMA= diff --git a/internal/lagoon/import_test.go b/internal/lagoon/import_test.go index 1f65f1fd..d446a98b 100644 --- a/internal/lagoon/import_test.go +++ b/internal/lagoon/import_test.go @@ -7,11 +7,11 @@ import ( "os" "testing" - "github.com/golang/mock/gomock" "github.com/uselagoon/lagoon-cli/internal/lagoon" "github.com/uselagoon/lagoon-cli/internal/mock" "github.com/uselagoon/lagoon-cli/internal/schema" api "github.com/uselagoon/machinery/api/schema" + "go.uber.org/mock/gomock" ) // importCalls stores arrays of expected import calls associated with a given diff --git a/internal/mock/mock_importer.go b/internal/mock/mock_importer.go index 603e530c..843dd53f 100644 --- a/internal/mock/mock_importer.go +++ b/internal/mock/mock_importer.go @@ -1,5 +1,10 @@ // Code generated by MockGen. DO NOT EDIT. // Source: import.go +// +// Generated by this command: +// +// mockgen -source=import.go -destination=../mock/mock_importer.go -package=mock +// // Package mock is a generated GoMock package. package mock @@ -8,8 +13,8 @@ import ( context "context" reflect "reflect" - gomock "github.com/golang/mock/gomock" schema "github.com/uselagoon/lagoon-cli/internal/schema" + gomock "go.uber.org/mock/gomock" ) // MockImporter is a mock of Importer interface. @@ -44,7 +49,7 @@ func (m *MockImporter) AddEnvVariable(arg0 context.Context, arg1 *schema.EnvVari } // AddEnvVariable indicates an expected call of AddEnvVariable. -func (mr *MockImporterMockRecorder) AddEnvVariable(arg0, arg1, arg2 interface{}) *gomock.Call { +func (mr *MockImporterMockRecorder) AddEnvVariable(arg0, arg1, arg2 any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AddEnvVariable", reflect.TypeOf((*MockImporter)(nil).AddEnvVariable), arg0, arg1, arg2) } @@ -58,7 +63,7 @@ func (m *MockImporter) AddGroup(arg0 context.Context, arg1 *schema.AddGroupInput } // AddGroup indicates an expected call of AddGroup. -func (mr *MockImporterMockRecorder) AddGroup(arg0, arg1, arg2 interface{}) *gomock.Call { +func (mr *MockImporterMockRecorder) AddGroup(arg0, arg1, arg2 any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AddGroup", reflect.TypeOf((*MockImporter)(nil).AddGroup), arg0, arg1, arg2) } @@ -72,7 +77,7 @@ func (m *MockImporter) AddGroupsToProject(arg0 context.Context, arg1 *schema.Pro } // AddGroupsToProject indicates an expected call of AddGroupsToProject. -func (mr *MockImporterMockRecorder) AddGroupsToProject(arg0, arg1, arg2 interface{}) *gomock.Call { +func (mr *MockImporterMockRecorder) AddGroupsToProject(arg0, arg1, arg2 any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AddGroupsToProject", reflect.TypeOf((*MockImporter)(nil).AddGroupsToProject), arg0, arg1, arg2) } @@ -86,7 +91,7 @@ func (m *MockImporter) AddNotificationEmail(arg0 context.Context, arg1 *schema.A } // AddNotificationEmail indicates an expected call of AddNotificationEmail. -func (mr *MockImporterMockRecorder) AddNotificationEmail(arg0, arg1, arg2 interface{}) *gomock.Call { +func (mr *MockImporterMockRecorder) AddNotificationEmail(arg0, arg1, arg2 any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AddNotificationEmail", reflect.TypeOf((*MockImporter)(nil).AddNotificationEmail), arg0, arg1, arg2) } @@ -100,7 +105,7 @@ func (m *MockImporter) AddNotificationMicrosoftTeams(arg0 context.Context, arg1 } // AddNotificationMicrosoftTeams indicates an expected call of AddNotificationMicrosoftTeams. -func (mr *MockImporterMockRecorder) AddNotificationMicrosoftTeams(arg0, arg1, arg2 interface{}) *gomock.Call { +func (mr *MockImporterMockRecorder) AddNotificationMicrosoftTeams(arg0, arg1, arg2 any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AddNotificationMicrosoftTeams", reflect.TypeOf((*MockImporter)(nil).AddNotificationMicrosoftTeams), arg0, arg1, arg2) } @@ -114,7 +119,7 @@ func (m *MockImporter) AddNotificationRocketChat(arg0 context.Context, arg1 *sch } // AddNotificationRocketChat indicates an expected call of AddNotificationRocketChat. -func (mr *MockImporterMockRecorder) AddNotificationRocketChat(arg0, arg1, arg2 interface{}) *gomock.Call { +func (mr *MockImporterMockRecorder) AddNotificationRocketChat(arg0, arg1, arg2 any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AddNotificationRocketChat", reflect.TypeOf((*MockImporter)(nil).AddNotificationRocketChat), arg0, arg1, arg2) } @@ -128,7 +133,7 @@ func (m *MockImporter) AddNotificationSlack(arg0 context.Context, arg1 *schema.A } // AddNotificationSlack indicates an expected call of AddNotificationSlack. -func (mr *MockImporterMockRecorder) AddNotificationSlack(arg0, arg1, arg2 interface{}) *gomock.Call { +func (mr *MockImporterMockRecorder) AddNotificationSlack(arg0, arg1, arg2 any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AddNotificationSlack", reflect.TypeOf((*MockImporter)(nil).AddNotificationSlack), arg0, arg1, arg2) } @@ -142,7 +147,7 @@ func (m *MockImporter) AddNotificationToProject(arg0 context.Context, arg1 *sche } // AddNotificationToProject indicates an expected call of AddNotificationToProject. -func (mr *MockImporterMockRecorder) AddNotificationToProject(arg0, arg1, arg2 interface{}) *gomock.Call { +func (mr *MockImporterMockRecorder) AddNotificationToProject(arg0, arg1, arg2 any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AddNotificationToProject", reflect.TypeOf((*MockImporter)(nil).AddNotificationToProject), arg0, arg1, arg2) } @@ -156,7 +161,7 @@ func (m *MockImporter) AddOrUpdateEnvironment(arg0 context.Context, arg1 *schema } // AddOrUpdateEnvironment indicates an expected call of AddOrUpdateEnvironment. -func (mr *MockImporterMockRecorder) AddOrUpdateEnvironment(arg0, arg1, arg2 interface{}) *gomock.Call { +func (mr *MockImporterMockRecorder) AddOrUpdateEnvironment(arg0, arg1, arg2 any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AddOrUpdateEnvironment", reflect.TypeOf((*MockImporter)(nil).AddOrUpdateEnvironment), arg0, arg1, arg2) } @@ -170,7 +175,7 @@ func (m *MockImporter) AddProject(arg0 context.Context, arg1 *schema.AddProjectI } // AddProject indicates an expected call of AddProject. -func (mr *MockImporterMockRecorder) AddProject(arg0, arg1, arg2 interface{}) *gomock.Call { +func (mr *MockImporterMockRecorder) AddProject(arg0, arg1, arg2 any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AddProject", reflect.TypeOf((*MockImporter)(nil).AddProject), arg0, arg1, arg2) } @@ -184,7 +189,7 @@ func (m *MockImporter) AddSSHKey(arg0 context.Context, arg1 *schema.AddSSHKeyInp } // AddSSHKey indicates an expected call of AddSSHKey. -func (mr *MockImporterMockRecorder) AddSSHKey(arg0, arg1, arg2 interface{}) *gomock.Call { +func (mr *MockImporterMockRecorder) AddSSHKey(arg0, arg1, arg2 any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AddSSHKey", reflect.TypeOf((*MockImporter)(nil).AddSSHKey), arg0, arg1, arg2) } @@ -198,7 +203,7 @@ func (m *MockImporter) AddUser(arg0 context.Context, arg1 *schema.AddUserInput, } // AddUser indicates an expected call of AddUser. -func (mr *MockImporterMockRecorder) AddUser(arg0, arg1, arg2 interface{}) *gomock.Call { +func (mr *MockImporterMockRecorder) AddUser(arg0, arg1, arg2 any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AddUser", reflect.TypeOf((*MockImporter)(nil).AddUser), arg0, arg1, arg2) } @@ -212,7 +217,7 @@ func (m *MockImporter) AddUserToGroup(arg0 context.Context, arg1 *schema.UserGro } // AddUserToGroup indicates an expected call of AddUserToGroup. -func (mr *MockImporterMockRecorder) AddUserToGroup(arg0, arg1, arg2 interface{}) *gomock.Call { +func (mr *MockImporterMockRecorder) AddUserToGroup(arg0, arg1, arg2 any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AddUserToGroup", reflect.TypeOf((*MockImporter)(nil).AddUserToGroup), arg0, arg1, arg2) } @@ -226,7 +231,7 @@ func (m *MockImporter) EnvironmentByName(arg0 context.Context, arg1 string, arg2 } // EnvironmentByName indicates an expected call of EnvironmentByName. -func (mr *MockImporterMockRecorder) EnvironmentByName(arg0, arg1, arg2, arg3 interface{}) *gomock.Call { +func (mr *MockImporterMockRecorder) EnvironmentByName(arg0, arg1, arg2, arg3 any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "EnvironmentByName", reflect.TypeOf((*MockImporter)(nil).EnvironmentByName), arg0, arg1, arg2, arg3) } @@ -240,7 +245,7 @@ func (m *MockImporter) ProjectByName(arg0 context.Context, arg1 string, arg2 *sc } // ProjectByName indicates an expected call of ProjectByName. -func (mr *MockImporterMockRecorder) ProjectByName(arg0, arg1, arg2 interface{}) *gomock.Call { +func (mr *MockImporterMockRecorder) ProjectByName(arg0, arg1, arg2 any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ProjectByName", reflect.TypeOf((*MockImporter)(nil).ProjectByName), arg0, arg1, arg2) }