From 6f659f80b9d6aa7bced8a7a0d54b6396c1e9de7d Mon Sep 17 00:00:00 2001 From: franklin Date: Fri, 30 Jul 2021 18:17:30 +0200 Subject: [PATCH] chore: add release workflow --- .github/workflows/release.yml | 37 +++++++++++++++ .gitignore | 2 + .golangci.yml | 85 +++++++++++++++++++++++++++++++++++ .goreleaser.yml | 31 +++++++++++++ Makefile | 62 +++++++++++++++++++++++++ README.md | 24 ++++++++-- main.go | 2 +- 7 files changed, 238 insertions(+), 5 deletions(-) create mode 100644 .github/workflows/release.yml create mode 100644 .golangci.yml create mode 100644 .goreleaser.yml create mode 100644 Makefile diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..8ec9c6f --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,37 @@ +name: goreleaser + +on: + push: + tags: + - v*.*.* + +jobs: + goreleaser: + runs-on: ubuntu-latest + env: + GOFLAGS: -mod=readonly + GOPROXY: https://proxy.golang.org + steps: + - name: Checkout + uses: actions/checkout@v2 + + - name: Unshallow + run: git fetch --prune --unshallow + + - name: Set up Go + uses: actions/setup-go@v2 + with: + go-version: 1.16 + + # TODO enable + #- name: golangci-lint + # uses: golangci/golangci-lint-action@v2 + + - name: Run GoReleaser + uses: goreleaser/goreleaser-action@v2 + with: + distribution: goreleaser + version: latest + args: release --rm-dist + env: + GITHUB_TOKEN: ${{ secrets.PERSONAL_GITHUB_TOKEN }} diff --git a/.gitignore b/.gitignore index f2dd955..0ad1ec1 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,5 @@ # Output of the go coverage tool, specifically when used with LiteIDE *.out + +bin \ No newline at end of file diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 0000000..84c2500 --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,85 @@ +run: + timeout: 5m + +linters-settings: + gci: + local-prefixes: github.com/foomo/gocontentful + golint: + min-confidence: 0 + goimports: + local-prefixes: github.com/foomo/gocontentful + gocritic: + enabled-tags: + - diagnostic + - style + disabled-tags: + - performance + - experimental + - opinionated + lll: + line-length: 150 + +linters: + disable-all: true + enable: + - bodyclose + - deadcode + - dogsled + - dupl + - exhaustive + - exportloopref + - gci + - goconst + - gofmt + - gofumpt + - goimports + - revive + - goprintffuncname + - govet + - ineffassign + - misspell + - nakedret + - noctx + - nolintlint + - prealloc + - rowserrcheck + - sqlclosecheck + - staticcheck + - structcheck + - stylecheck + - typecheck + - unconvert + - unparam + - unused + - varcheck + - whitespace + - errcheck + - gocritic + - gosimple + + - gocyclo + - gosec + - lll + - exportloopref + + # unused + # - godot + # - gocognit + # - nlreturn + # - gochecknoglobals + # - gochecknoinits + # - depguard + # - goheader + # - gomodguard + + # don't enable: + # - asciicheck + # - funlen + # - godox + # - goerr113 + # - gomnd + # - interfacer + # - maligned + # - nestif + # - testpackage + # - wsl diff --git a/.goreleaser.yml b/.goreleaser.yml new file mode 100644 index 0000000..4e13ca5 --- /dev/null +++ b/.goreleaser.yml @@ -0,0 +1,31 @@ +# .goreleaser.yml +# Build customization +builds: + - binary: gocontentful + main: ./cmd/main.go + env: + - CGO_ENABLED=0 + ldflags: + - -s -w -X github.com/foomo/gocontentful/VERSION={{.Version}} + goos: + - windows + - darwin + - linux + goarch: + - amd64 + +# .goreleaser.yml +archives: + - format: tar.gz + format_overrides: + - goos: windows + format: zip + +brews: + # Reporitory to push the tap to. + - tap: + owner: foomo + name: homebrew-gocontentful + caveats: "gocontentful -h" + homepage: "https://github.com/foomo/gocontentful" + description: "An Contentful Entry-Reference Mapper for Go" diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..a9b3f5b --- /dev/null +++ b/Makefile @@ -0,0 +1,62 @@ +.DEFAULT_GOAL:=help + +## === Tasks === + +## Install binary +install: + go build -o ${GOPATH}/bin/gocontenful main.go + +## Build binary +build: + mkdir -p bin + go build -o bin/gocontenful main.go + +.PHONY: test +## Run tests +test: + go test ./... + +.PHONY: lint +## Run linter +lint: + golangci-lint run + +.PHONY: lint.fix +## Fix lint violations +lint.fix: + golangci-lint run --fix + + +## === Utils === + +## Show help text +help: + @awk '{ \ + if ($$0 ~ /^.PHONY: [a-zA-Z\-\_0-9]+$$/) { \ + helpCommand = substr($$0, index($$0, ":") + 2); \ + if (helpMessage) { \ + printf "\033[36m%-23s\033[0m %s\n", \ + helpCommand, helpMessage; \ + helpMessage = ""; \ + } \ + } else if ($$0 ~ /^[a-zA-Z\-\_0-9.]+:/) { \ + helpCommand = substr($$0, 0, index($$0, ":")); \ + if (helpMessage) { \ + printf "\033[36m%-23s\033[0m %s\n", \ + helpCommand, helpMessage"\n"; \ + helpMessage = ""; \ + } \ + } else if ($$0 ~ /^##/) { \ + if (helpMessage) { \ + helpMessage = helpMessage"\n "substr($$0, 3); \ + } else { \ + helpMessage = substr($$0, 3); \ + } \ + } else { \ + if (helpMessage) { \ + print "\n "helpMessage"\n" \ + } \ + helpMessage = ""; \ + } \ + }' \ + $(MAKEFILE_LIST) diff --git a/README.md b/README.md index d655b12..65bda1f 100644 --- a/README.md +++ b/README.md @@ -27,11 +27,25 @@ Quickstart Prerequisite: you need Go 1.16+. Upgrade if you still haven't, then run: -> go get github.com/foomo/gocontentful +```bash +go get github.com/foomo/gocontentful +``` + +If you trust us there are precompiled versions: + +[releases](https://github.com/foomo/gocontentful/releases) + +On the mac: + +```bash +brew install foomo/gocontentful/gocontentful +``` Test the installation (make sure $GOPATH/bin is in your $PATH): ->gocontentful +```bash +gocontentful +```
Contentful API Generator starting...
 
@@ -51,13 +65,15 @@ Usage of gocontentful:
 Note: The last segment of the path/to/target/package will be used as package name
 
-###Use case +### Use case - You want to generate a package named "people" and manipulate entries of content types with ID "person" and "pet". Run the following: ->gocontentful -spaceid YOUR_SPACE_ID -cmakey YOUR_CMA_API_TOKEN -contenttypes person,pet path/to/your/go/project/folder/people +```bash +gocontentful -spaceid YOUR_SPACE_ID -cmakey YOUR_CMA_API_TOKEN -contenttypes person,pet path/to/your/go/project/folder/people +``` The -contenttypes parameter is optional. If not specified, an API for all content types of the space will be generated. diff --git a/main.go b/main.go index 7d7e58a..8b0d636 100644 --- a/main.go +++ b/main.go @@ -11,7 +11,7 @@ import ( "github.com/foomo/gocontentful/erm" ) -const VERSION = "v0.9.5" +var VERSION = "latest" var Usage = func() { fmt.Printf("\nSYNOPSIS\n")