From 2b343ec87814247da8deb22518ec46438a6c3bf0 Mon Sep 17 00:00:00 2001 From: Matthew F Leader Date: Tue, 30 Jan 2024 15:56:31 -0500 Subject: [PATCH 1/6] upgrade module --- go.mod | 10 +++++----- go.sum | 19 +++++++++---------- 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/go.mod b/go.mod index a034f3d..11ea1b9 100644 --- a/go.mod +++ b/go.mod @@ -1,10 +1,10 @@ module go.flow.arcalot.io/deployer -go 1.18 +go 1.21 require ( - go.arcalot.io/assert v1.6.0 - go.arcalot.io/lang v1.0.0 - go.arcalot.io/log/v2 v2.0.0 - go.flow.arcalot.io/pluginsdk v0.5.1 + go.arcalot.io/assert v1.7.0 + go.arcalot.io/lang v1.1.0 + go.arcalot.io/log/v2 v2.1.0 + go.flow.arcalot.io/pluginsdk v0.8.0 ) diff --git a/go.sum b/go.sum index 66d9810..62d1016 100644 --- a/go.sum +++ b/go.sum @@ -1,11 +1,10 @@ -go.arcalot.io/assert v1.6.0 h1:iKA8SZZ1MRblMX5QAwwY5RbpR+VNyp//4IU7vo08Xu0= -go.arcalot.io/assert v1.6.0/go.mod h1:Xy3ScX0p9IMY89gdsgexOKxnmDr0nGHG9dV7p8Uxg7w= -go.arcalot.io/lang v1.0.0 h1:mgDaieT4wWdZTnR4V7+/pgYRmzfU7VZZgIzHccuxAbY= -go.arcalot.io/lang v1.0.0/go.mod h1:ALqfYEhAzC2WoGLaycmJoNJd5NmkR7V1PSKp/c5D278= -go.arcalot.io/log/v2 v2.0.0 h1:mbmsWDVBXZNWrDzUh5JLzeGCQ59kTuMFs+pyfJGc1hk= -go.arcalot.io/log/v2 v2.0.0/go.mod h1:1V8jnFIIGwh2CtcGkHNOmy1nCo7LbazQNkUcnKYNMn4= -go.flow.arcalot.io/pluginsdk v0.5.0 h1:TRS/waCTcdoMZ9neDAcfy3zpzyDnPHRbhV+Y1kpcw3Y= -go.flow.arcalot.io/pluginsdk v0.5.0/go.mod h1:2s2f//7uOkBjr1QaiWJD/bqDIeLlINJtD1BhiY4aGPM= -go.flow.arcalot.io/pluginsdk v0.5.1 h1:ebb2ThAqmjmwGpDyKpd1wEDUisPqPabgARjFohy47Io= -go.flow.arcalot.io/pluginsdk v0.5.1/go.mod h1:2s2f//7uOkBjr1QaiWJD/bqDIeLlINJtD1BhiY4aGPM= +go.arcalot.io/assert v1.7.0 h1:PTLyeisNMUKpM9wXRDxResanBhuGOYO1xFK3v5b3FSw= +go.arcalot.io/assert v1.7.0/go.mod h1:nNmWPoNUHFyrPkNrD2aASm5yPuAfiWdB/4X7Lw3ykHk= +go.arcalot.io/lang v1.1.0 h1:ugglRKpd3qIMkdghAjKJxsziIgHm8QpxrzZPSXoa08I= +go.arcalot.io/lang v1.1.0/go.mod h1:2BZJO4csY7NnN/Nf1+eTdIQH4A2vxtOMneaO+PJl+Co= +go.arcalot.io/log/v2 v2.1.0 h1:lNO931hJ82LgS6WcCFCxpLWXQXPFhOkz6PyAJ/augq4= +go.arcalot.io/log/v2 v2.1.0/go.mod h1:PNWOSkkPmgS2OMlWTIlB/WqOw0yaBvDYd8ENAP80H4k= +go.flow.arcalot.io/pluginsdk v0.8.0 h1:cShsshrR17ZFLcbgi3aZvqexLttcp3JISFNqPUPuDvA= +go.flow.arcalot.io/pluginsdk v0.8.0/go.mod h1:sk7ssInR/T+Gy+RSRr+QhKqZcECFFxMyn1hPQCTZSyU= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= From f040dcf86ab60ce220f12d504e16f569f39f47c9 Mon Sep 17 00:00:00 2001 From: Matthew F Leader Date: Tue, 30 Jan 2024 15:57:37 -0500 Subject: [PATCH 2/6] fix golangci config --- .golangci.yml | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index ff3c5f5..1570663 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -75,18 +75,20 @@ linters: # endregion linters-settings: depguard: - list-type: whitelist - include-go-root: false - packages: - - go.flow.arcalot.io/ - - go.arcalot.io/ - - github.com/docker/ - - github.com/opencontainers/ - - gopkg.in/yaml.v3 - - github.com/fxamacker/cbor - - k8s.io/ - - sigs.k8s.io/ - - golang.org/ + rules: + main: + list-mode: strict + allow: + - $gostd + - go.flow.arcalot.io/ + - go.arcalot.io/ + - github.com/docker/ + - github.com/opencontainers/ + - gopkg.in/yaml.v3 + - github.com/fxamacker/cbor + - k8s.io/ + - sigs.k8s.io/ + - golang.org/ govet: enable-all: true check-shadowing: false From 3579ebeb64fcfa99c4d24ad96c08ba0c38713bfe Mon Sep 17 00:00:00 2001 From: Matthew F Leader Date: Tue, 30 Jan 2024 16:04:28 -0500 Subject: [PATCH 3/6] fix linting --- interface.go | 2 ++ registry/helper_test.go | 36 +++++++++++++++--------------------- registry/new.go | 2 ++ registry/registry.go | 2 ++ 4 files changed, 21 insertions(+), 21 deletions(-) diff --git a/interface.go b/interface.go index 2e68607..21e5694 100644 --- a/interface.go +++ b/interface.go @@ -9,6 +9,8 @@ import ( "go.flow.arcalot.io/pluginsdk/schema" ) +// DeploymentType is the mechanism of deployment, such as +// image or python. type DeploymentType string // ConnectorFactory is an abstraction that hides away the complexity of instantiating a Connector. Its main purpose is diff --git a/registry/helper_test.go b/registry/helper_test.go index ed19d63..d94faec 100644 --- a/registry/helper_test.go +++ b/registry/helper_test.go @@ -1,52 +1,46 @@ package registry_test import ( - "context" - "fmt" + "context" + "fmt" - log "go.arcalot.io/log/v2" - "go.flow.arcalot.io/deployer" - "go.flow.arcalot.io/pluginsdk/schema" + log "go.arcalot.io/log/v2" + "go.flow.arcalot.io/deployer" + "go.flow.arcalot.io/pluginsdk/schema" ) type testConfig struct { } -var testConfigInput = map[string]any{ - "test-type": map[string]any{ - "deployer_name": "test", - }, -} - type testNewFactory struct { } var testDeploymentType = deployer.DeploymentType("test-type") func (t testNewFactory) Name() string { - return "test" + return "test" } func (t testNewFactory) DeploymentType() deployer.DeploymentType { - return "test-type" + return "test-type" } func (t testNewFactory) ConfigurationSchema() schema.Object { - return schema.NewTypedScopeSchema[testConfig]( - schema.NewStructMappedObjectSchema[testConfig]( - "test", - map[string]*schema.PropertySchema{}, - ), - ) + return schema.NewTypedScopeSchema[testConfig]( + schema.NewStructMappedObjectSchema[testConfig]( + "test", + map[string]*schema.PropertySchema{}, + ), + ) } func (t testNewFactory) Create(_ any, _ log.Logger) (deployer.Connector, error) { - return &testConnector{}, nil + return &testConnector{}, nil } type testConnector struct { } func (t testConnector) Deploy(_ context.Context, _ string) (deployer.Plugin, error) { - return nil, fmt.Errorf("not implemented") + return nil, fmt.Errorf("not implemented") } diff --git a/registry/new.go b/registry/new.go index 5043507..be9d6ad 100644 --- a/registry/new.go +++ b/registry/new.go @@ -1,3 +1,5 @@ +// Package registry provides an interface to an aggregate of deployers, +// and a factory for that aggregate. package registry import ( diff --git a/registry/registry.go b/registry/registry.go index ccfe0b8..a96ec61 100644 --- a/registry/registry.go +++ b/registry/registry.go @@ -1,3 +1,5 @@ +// Package registry provides an interface to an aggregate of deployers, +// and a factory for that aggregate. package registry import ( From 5083393e80958c269c01665947a03f822c55dcaf Mon Sep 17 00:00:00 2001 From: Matthew F Leader Date: Tue, 30 Jan 2024 16:04:57 -0500 Subject: [PATCH 4/6] gofmt helper test --- registry/helper_test.go | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/registry/helper_test.go b/registry/helper_test.go index d94faec..afb73c3 100644 --- a/registry/helper_test.go +++ b/registry/helper_test.go @@ -1,12 +1,12 @@ package registry_test import ( - "context" - "fmt" + "context" + "fmt" - log "go.arcalot.io/log/v2" - "go.flow.arcalot.io/deployer" - "go.flow.arcalot.io/pluginsdk/schema" + log "go.arcalot.io/log/v2" + "go.flow.arcalot.io/deployer" + "go.flow.arcalot.io/pluginsdk/schema" ) type testConfig struct { @@ -18,29 +18,29 @@ type testNewFactory struct { var testDeploymentType = deployer.DeploymentType("test-type") func (t testNewFactory) Name() string { - return "test" + return "test" } func (t testNewFactory) DeploymentType() deployer.DeploymentType { - return "test-type" + return "test-type" } func (t testNewFactory) ConfigurationSchema() schema.Object { - return schema.NewTypedScopeSchema[testConfig]( - schema.NewStructMappedObjectSchema[testConfig]( - "test", - map[string]*schema.PropertySchema{}, - ), - ) + return schema.NewTypedScopeSchema[testConfig]( + schema.NewStructMappedObjectSchema[testConfig]( + "test", + map[string]*schema.PropertySchema{}, + ), + ) } func (t testNewFactory) Create(_ any, _ log.Logger) (deployer.Connector, error) { - return &testConnector{}, nil + return &testConnector{}, nil } type testConnector struct { } func (t testConnector) Deploy(_ context.Context, _ string) (deployer.Plugin, error) { - return nil, fmt.Errorf("not implemented") + return nil, fmt.Errorf("not implemented") } From 0860e9fcf59b2aa4685af49c6019cf1938a148ea Mon Sep 17 00:00:00 2001 From: Matthew F Leader Date: Tue, 30 Jan 2024 16:08:47 -0500 Subject: [PATCH 5/6] add workflow --- .github/scripts/gogenerate.sh | 27 ++++++++++++ .github/workflows/build.yaml | 79 +++++++++++++++++++++++++++++++++++ 2 files changed, 106 insertions(+) create mode 100755 .github/scripts/gogenerate.sh create mode 100644 .github/workflows/build.yaml diff --git a/.github/scripts/gogenerate.sh b/.github/scripts/gogenerate.sh new file mode 100755 index 0000000..3bd55c6 --- /dev/null +++ b/.github/scripts/gogenerate.sh @@ -0,0 +1,27 @@ +#!/bin/bash + +export NOLINT=1 +go generate >/tmp/gogenerate.output 2>/tmp/gogenerate.output +if [ $? -ne 0 ]; then + echo -e "::group::\e[0;31m❌ Go generate failed.\e[0m" + cat /tmp/gogenerate.output + echo "::endgroup::" + exit 1 +fi + +echo -e "::group::\e[0;32m✅ Go generate succeeded.\e[0m" +cat /tmp/gogenerate.output +echo "::endgroup::" + +git diff >/tmp/gogenerate.diff +if [ "$(cat /tmp/gogenerate.diff | wc -l)" -ne 0 ]; then + echo -e "::group::\e[0;31m❌ Git changes after go generate.\e[0m" + echo "The following is the diff of files:" + cat /tmp/gogenerate.diff + echo "::endgroup::" + echo -e "\e[0;31m⚙ Please run go generate before pushing your changes.\e[0m" + exit 1 +fi + +echo -e "::group::\e[0;32m✅ No changes after go generate.\e[0m" +echo "::endgroup::" diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml new file mode 100644 index 0000000..2450a81 --- /dev/null +++ b/.github/workflows/build.yaml @@ -0,0 +1,79 @@ +name: Build +on: + push: + branches: + - main + pull_request: +jobs: + golangci-lint: + name: golangci-lint + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Run golangci-lint + uses: golangci/golangci-lint-action@v3 + with: + version: v1.55.2 + test: + name: go test + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: 1.21.6 + - name: Set up gotestfmt + uses: GoTestTools/gotestfmt-action@v2 + - uses: actions/cache@v4 + with: + path: | + ~/go/pkg/mod + ~/.cache/go-build + key: go-test-${{ hashFiles('**/go.sum') }} + restore-keys: go-test- + - name: Run go test + run: | + set -euo pipefail + go generate + go test -coverprofile /tmp/coverage.out -json -v ./... 2>&1 | tee /tmp/gotest.log | gotestfmt + echo "# Code coverage summary" > /tmp/coverage.md + echo "|File|Type|Coverage|" >> /tmp/coverage.md + echo "|----|----|--------|" >> /tmp/coverage.md + go tool cover -func /tmp/coverage.out | sed -e 's/\s\s*/|/g' -e 's/^/|/g' -e 's/$/|/g' >> /tmp/coverage.md + + cat /tmp/coverage.md >> $GITHUB_STEP_SUMMARY + echo "::group::Code coverage summary" + go tool cover -func /tmp/coverage.out + echo "::endgroup::" + - name: Upload test log + uses: actions/upload-artifact@v3 + if: always() + with: + name: test-results + path: | + /tmp/gotest.log + /tmp/coverage.out + /tmp/coverage.md + if-no-files-found: error + generate: + name: go generate + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: 1.21.6 + - uses: actions/cache@v4 + with: + path: | + ~/go/pkg/mod + ~/.cache/go-build + key: go-test-${{ hashFiles('**/go.sum') }} + restore-keys: go-generate- + - name: Run go generate + run: ./.github/scripts/gogenerate.sh From 60ff36a33d142d92031c00d385790ef0255dda7c Mon Sep 17 00:00:00 2001 From: Matthew F Leader Date: Tue, 30 Jan 2024 16:22:55 -0500 Subject: [PATCH 6/6] remove generator --- .github/scripts/gogenerate.sh | 27 --------------------------- .github/workflows/build.yaml | 19 ------------------- 2 files changed, 46 deletions(-) delete mode 100755 .github/scripts/gogenerate.sh diff --git a/.github/scripts/gogenerate.sh b/.github/scripts/gogenerate.sh deleted file mode 100755 index 3bd55c6..0000000 --- a/.github/scripts/gogenerate.sh +++ /dev/null @@ -1,27 +0,0 @@ -#!/bin/bash - -export NOLINT=1 -go generate >/tmp/gogenerate.output 2>/tmp/gogenerate.output -if [ $? -ne 0 ]; then - echo -e "::group::\e[0;31m❌ Go generate failed.\e[0m" - cat /tmp/gogenerate.output - echo "::endgroup::" - exit 1 -fi - -echo -e "::group::\e[0;32m✅ Go generate succeeded.\e[0m" -cat /tmp/gogenerate.output -echo "::endgroup::" - -git diff >/tmp/gogenerate.diff -if [ "$(cat /tmp/gogenerate.diff | wc -l)" -ne 0 ]; then - echo -e "::group::\e[0;31m❌ Git changes after go generate.\e[0m" - echo "The following is the diff of files:" - cat /tmp/gogenerate.diff - echo "::endgroup::" - echo -e "\e[0;31m⚙ Please run go generate before pushing your changes.\e[0m" - exit 1 -fi - -echo -e "::group::\e[0;32m✅ No changes after go generate.\e[0m" -echo "::endgroup::" diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 2450a81..aa52128 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -58,22 +58,3 @@ jobs: /tmp/coverage.out /tmp/coverage.md if-no-files-found: error - generate: - name: go generate - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v4 - - name: Set up Go - uses: actions/setup-go@v5 - with: - go-version: 1.21.6 - - uses: actions/cache@v4 - with: - path: | - ~/go/pkg/mod - ~/.cache/go-build - key: go-test-${{ hashFiles('**/go.sum') }} - restore-keys: go-generate- - - name: Run go generate - run: ./.github/scripts/gogenerate.sh