From 6f5d14093989a26ac2b28513610b7e5408e43856 Mon Sep 17 00:00:00 2001 From: Darko Djalevski Date: Tue, 13 Apr 2021 17:26:33 +0200 Subject: [PATCH] fix: Remove circle CI, add github actions (#175) --- .circleci/config.yml | 17 ---- .github/workflows/go.yml | 163 ++++++++++++++++++++++++++++++++++ .github/workflows/pr.yml | 23 +++++ .github/workflows/release.yml | 60 +++++++++++-- .pre-commit-config.yaml | 7 ++ README.md | 3 + go.sum | 7 -- helpers/helpers.go | 10 ++- 8 files changed, 255 insertions(+), 35 deletions(-) delete mode 100644 .circleci/config.yml create mode 100644 .github/workflows/go.yml create mode 100644 .github/workflows/pr.yml create mode 100644 .pre-commit-config.yaml diff --git a/.circleci/config.yml b/.circleci/config.yml deleted file mode 100644 index e227fcc6..00000000 --- a/.circleci/config.yml +++ /dev/null @@ -1,17 +0,0 @@ -version: 2.1 - -orbs: - moul: moul/build@1.14.0 # https://github.com/moul/build - -workflows: - main: - jobs: - - moul/golang-build: - gopkg: moul.io/protoc-gen-gotemplate - - moul/golang-build: - gopkg: moul.io/protoc-gen-gotemplate - tag: '1.12' - - moul/golang-build: - gopkg: moul.io/protoc-gen-gotemplate - tag: '1.11' - - moul/docker-build diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml new file mode 100644 index 00000000..d7ca24ce --- /dev/null +++ b/.github/workflows/go.yml @@ -0,0 +1,163 @@ +name: Go +on: + push: + tags: + - v* + branches: + - master + - main + paths: + - '**.go' + - ".goreleaser.yml" + - ".golangci.yml" + - ".dockerignore" + - "Makefile" + - "rules.mk" + - "go.*" + - ".github/workflows/go.yml" + pull_request: + paths: + - '**.go' + - ".goreleaser.yml" + - ".golangci.yml" + - ".dockerignore" + - "Makefile" + - "rules.mk" + - "go.*" + - ".github/workflows/go.yml" + +jobs: + goreleaser-dryrun: + strategy: + matrix: + golang: [1.16.x] + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@master + - name: Set up Go + uses: actions/setup-go@v2 + with: + go-version: ${{ matrix.golang }} + - name: Cache Go modules + uses: actions/cache@v2.1.4 + with: + path: ~/go/pkg/mod + key: ${{ runner.os }}-go-${{ matrix.golang }}-v1-${{ hashFiles('**/go.sum') }} + restore-keys: ${{ runner.os }}-go-${{ matrix.golang }}-v1- + - name: Run GoReleaser (Dry Run) + uses: goreleaser/goreleaser-action@v2 + with: + version: latest + args: release --rm-dist --snapshot --skip-publish + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + golangci-lint: + runs-on: ubuntu-latest + strategy: + matrix: + golangci_lint: [v1.38] + steps: + - uses: actions/checkout@v2 + - name: golangci-lint + uses: golangci/golangci-lint-action@v2.5.2 + with: + version: ${{ matrix.golangci_lint }} + #github-token: ${{ secrets.GITHUB_TOKEN }} + args: --timeout=2m + only-new-issues: false + working-directory: . + tests-on-windows: + needs: golangci-lint # run after golangci-lint action to not produce duplicated errors + runs-on: windows-latest + strategy: + matrix: + golang: [1.16.x] + steps: + - uses: actions/checkout@v2 + - name: Install Go + uses: actions/setup-go@v2 + with: + go-version: ${{ matrix.golang }} + - name: Run tests on Windows + run: make.exe unittest + continue-on-error: true + tests-on-mac: + needs: golangci-lint # run after golangci-lint action to not produce duplicated errors + runs-on: macos-latest + strategy: + matrix: + golang: [1.16.x] + env: + OS: macos-latest + GOLANG: ${{ matrix.golang }} + steps: + - uses: actions/checkout@v2 + - name: Install Go + uses: actions/setup-go@v2 + with: + go-version: ${{ matrix.golang }} + - uses: actions/cache@v2.1.4 + with: + path: ~/go/pkg/mod + key: ${{ runner.os }}-go-${{ matrix.golang }}-v1-${{ hashFiles('**/go.sum') }} + restore-keys: ${{ runner.os }}-go-${{ matrix.golang }}-v1- + - name: Compile the project + run: make go.install + - name: Run tests on Unix-like operating systems + run: make unittest + - name: Check go.mod and go.sum + run: | + go mod tidy -v + git --no-pager diff go.mod go.sum + git --no-pager diff --quiet go.mod go.sum + - name: Upload coverage to Codecov + uses: codecov/codecov-action@v1 + with: + #token: ${{ secrets.CODECOV_TOKEN }} + file: ./coverage.txt + flags: unittests + env_vars: OS,GOLANG + name: codecov-umbrella + fail_ci_if_error: false + tests-on-linux: + needs: golangci-lint # run after golangci-lint action to not produce duplicated errors + runs-on: ubuntu-latest + strategy: + matrix: + golang: + - 1.14.x + - 1.15.x + - 1.16.x + env: + OS: ubuntu-latest + GOLANG: ${{ matrix.golang }} + steps: + - uses: actions/checkout@v2 + - name: Install Go + uses: actions/setup-go@v2 + with: + go-version: ${{ matrix.golang }} + - uses: actions/cache@v2.1.4 + with: + path: ~/go/pkg/mod + key: ${{ runner.os }}-go-${{ matrix.golang }}-v1-${{ hashFiles('**/go.sum') }} + restore-keys: ${{ runner.os }}-go-${{ matrix.golang }}-v1- + - name: Compile the project + run: make go.install + - name: Check go.mod and go.sum + run: | + go mod tidy -v + git --no-pager diff go.mod go.sum + git --no-pager diff --quiet go.mod go.sum + - name: Run tests on Unix-like operating systems + run: make unittest + - name: Upload coverage to Codecov + uses: codecov/codecov-action@v1 + with: + #token: ${{ secrets.CODECOV_TOKEN }} + file: ./coverage.txt + flags: unittests + env_vars: OS,GOLANG + name: codecov-umbrella + fail_ci_if_error: false \ No newline at end of file diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml new file mode 100644 index 00000000..ab11d105 --- /dev/null +++ b/.github/workflows/pr.yml @@ -0,0 +1,23 @@ +name: PR + +on: + #pull_request_target: + pull_request: + branches: [ master, main ] + issue_comment: + types: [ edited ] + +jobs: + preview: + name: Release-Notes Preview + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - run: | + git fetch --prune --unshallow --tags + - uses: snyk/release-notes-preview@v1.6.2 + with: + releaseBranch: master + env: + GITHUB_PR_USERNAME: ${{ github.actor }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 60b56fb0..59f9a535 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,13 +1,59 @@ -name: Semantic Release - -on: push +name: Release +on: + push: + branches: + - master + - main jobs: - semantic-release: + release: + name: releaser runs-on: ubuntu-latest + strategy: + matrix: + golang: [1.16.x] steps: - - uses: actions/checkout@master - - uses: codfish/semantic-release-action@v1 - if: github.ref == 'refs/heads/master' + - + name: Checkout + uses: actions/checkout@master + - + name: Unshallow + run: git fetch --prune --unshallow + - + name: Run Semantic Release + id: semantic + uses: docker://ghcr.io/codfish/semantic-release-action:v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - + name: Set up Go + if: steps.semantic.outputs.new-release-published == 'true' + uses: actions/setup-go@v2 + with: + go-version: ${{ matrix.golang }} + - + name: Cache Go modules + if: steps.semantic.outputs.new-release-published == 'true' + uses: actions/cache@v2.1.4 + with: + path: ~/go/pkg/mod + key: ${{ runner.os }}-go-${{ matrix.golang }}-v1-${{ hashFiles('**/go.sum') }} + restore-keys: ${{ runner.os }}-go-${{ matrix.golang }}-v1- + - + name: Run GoReleaser + if: steps.semantic.outputs.new-release-published == 'true' + uses: goreleaser/goreleaser-action@v2 + with: + version: latest + args: release --rm-dist env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - + name: Register version on pkg.go.dev + if: steps.semantic.outputs.new-release-published == 'true' + run: | + package=$(cat go.mod | grep ^module | awk '{print $2}') + version=v${{ steps.semantic.outputs.release-version }} + url=https://proxy.golang.org/${package}/@v/${version}.info + set -x +e + curl -i $url \ No newline at end of file diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 00000000..f83c03c9 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,7 @@ +- repo: git://github.com/dnephin/pre-commit-golang + rev: master + hooks: + - id: go-fmt + - id: go-vet + - id: go-lint + - id: go-imports diff --git a/README.md b/README.md index e5877497..201259b9 100644 --- a/README.md +++ b/README.md @@ -22,6 +22,9 @@ The plugin parses **protobuf** files, generates an **ast**, and walks a local ** 3. the `ast` is given to [Golang's `text/template` engine](https://golang.org/pkg/text/template/) for each *user* template files 4. the *funcmap* enriching the template engine is based on [Masterminds/sprig](https://github.com/Masterminds/sprig), and contains type-manipulation, iteration and language-specific helpers +## Dev helpers +1. Pre-commit script for install: https://pre-commit.com + ## Web editor ![Web editor screenshot](https://github.com/moul/protoc-gen-gotemplate/raw/master/assets/web-editor.jpg) diff --git a/go.sum b/go.sum index 5e086f40..06ff7aa7 100644 --- a/go.sum +++ b/go.sum @@ -21,7 +21,6 @@ github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3Ee github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4= github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA= github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= -github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= @@ -97,7 +96,6 @@ github.com/mitchellh/copystructure v1.0.0 h1:Laisrj+bAB6b/yJwB5Bt3ITZhGJdqmxquMK github.com/mitchellh/copystructure v1.0.0/go.mod h1:SNtv71yrdKgLRyLFxmLdkAbkKEFWgYaq1OVrnRcwhnw= github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= -github.com/mitchellh/reflectwalk v1.0.0 h1:9D+8oIskB4VJBN5SFlmc27fSlIBZaov1Wpk/IfikLNY= github.com/mitchellh/reflectwalk v1.0.0/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw= github.com/mitchellh/reflectwalk v1.0.1 h1:FVzMWA5RllMAKIdUSC8mdWo3XtwoecrH79BY70sEEpE= github.com/mitchellh/reflectwalk v1.0.1/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw= @@ -136,7 +134,6 @@ github.com/spf13/viper v1.4.0/go.mod h1:PTJ7Z/lr49W6bUbkmS1V3by4uWynFiR9p7+dSq/y github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= -github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/stretchr/testify v1.5.1 h1:nOGnQDM7FYENwehXlg/kFVnos3rEvtKTjRvOWSzb6H4= @@ -170,7 +167,6 @@ golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn golang.org/x/net v0.0.0-20190522155817-f3200d17e092/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20191002035440-2ec189313ef0/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20200226121028-0de0cce0169b h1:0mm1VjtFUOIlE1SbDlwjYaDxZVDP2S5ou6y0gSgXHu8= golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= @@ -187,7 +183,6 @@ golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5h golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190422165155-953cdadca894 h1:Cz4ceDQGXuKRnVBDTS23GTn/pU5OE2C0WrNTOYK1Uuc= golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= @@ -210,7 +205,6 @@ google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZi google.golang.org/grpc v1.21.0/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM= google.golang.org/grpc v1.24.0/go.mod h1:XDChyiUovWa60DnaeDeZmSW86xtLtjtZbwvSiRnRtcA= gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= @@ -219,7 +213,6 @@ gopkg.in/resty.v1 v1.12.0/go.mod h1:mDo4pnntr5jdWRML875a/NmxYqAlA73dVijT2AXvQQo= gopkg.in/yaml.v2 v2.0.0-20170812160011-eb3733d160e7/go.mod h1:JAlM8MvJe8wmxCU4Bli9HhUf9+ttbYbLASfIpnQbh74= gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v2 v2.2.3 h1:fvjTMHxHEw/mxHbtzPi3JCcKXQRAnQTBRo6YCJSVHKI= gopkg.in/yaml.v2 v2.2.3/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.7 h1:VUgggvou5XRW9mHwD/yXxIYSMtY0zoKQf/v226p2nyo= gopkg.in/yaml.v2 v2.2.7/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= diff --git a/helpers/helpers.go b/helpers/helpers.go index 6863e7e9..470e6fd5 100644 --- a/helpers/helpers.go +++ b/helpers/helpers.go @@ -23,6 +23,8 @@ var ( registry *ggdescriptor.Registry // some helpers need access to registry ) +const timestamp = "timestamp" + var ProtoHelpersFuncMap = template.FuncMap{ "string": func(i interface { String() string @@ -830,7 +832,7 @@ func goTypeWithGoPackage(p *descriptor.FileDescriptorProto, f *descriptor.FieldD pkg := "" if *f.Type == descriptor.FieldDescriptorProto_TYPE_MESSAGE || *f.Type == descriptor.FieldDescriptorProto_TYPE_ENUM { if isTimestampPackage(*f.TypeName) { - pkg = "timestamp" + pkg = timestamp } else { pkg = *p.GetOptions().GoPackage if strings.Contains(*p.GetOptions().GoPackage, ";") { @@ -846,7 +848,7 @@ func goTypeWithPackage(f *descriptor.FieldDescriptorProto) string { pkg := "" if *f.Type == descriptor.FieldDescriptorProto_TYPE_MESSAGE || *f.Type == descriptor.FieldDescriptorProto_TYPE_ENUM { if isTimestampPackage(*f.TypeName) { - pkg = "timestamp" + pkg = timestamp } else { pkg = getPackageTypeName(*f.TypeName) } @@ -921,7 +923,7 @@ func rustTypeWithPackage(f *descriptor.FieldDescriptorProto) string { pkg := "" if *f.Type == descriptor.FieldDescriptorProto_TYPE_MESSAGE || *f.Type == descriptor.FieldDescriptorProto_TYPE_ENUM { if isTimestampPackage(*f.TypeName) { - pkg = "timestamp" + pkg = timestamp } else { pkg = getPackageTypeName(*f.TypeName) } @@ -972,7 +974,7 @@ func cppTypeWithPackage(f *descriptor.FieldDescriptorProto) string { pkg := "" if *f.Type == descriptor.FieldDescriptorProto_TYPE_MESSAGE || *f.Type == descriptor.FieldDescriptorProto_TYPE_ENUM { if isTimestampPackage(*f.TypeName) { - pkg = "timestamp" + pkg = timestamp } else { pkg = getPackageTypeName(*f.TypeName) }