Skip to content

Commit 0c1be39

Browse files
author
Cristian Vidmar
committed
feat: goreleaser
1 parent 83f5511 commit 0c1be39

File tree

11 files changed

+273
-43
lines changed

11 files changed

+273
-43
lines changed

.github/workflows/checks.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: checks
2+
3+
on:
4+
# Triggers the workflow on push or pull request events but only for the main branch
5+
push:
6+
branches: [ main ]
7+
pull_request:
8+
branches: [ main ]
9+
# Allows you to run this workflow manually from the Actions tab
10+
workflow_dispatch:
11+
12+
jobs:
13+
goreleaser:
14+
runs-on: ubuntu-latest
15+
env:
16+
GOFLAGS: -mod=readonly
17+
GOPROXY: https://proxy.golang.org
18+
steps:
19+
- name: Checkout
20+
uses: actions/checkout@v3
21+
22+
- name: Set up Go
23+
uses: actions/setup-go@v3
24+
with:
25+
go-version-file: go.mod
26+
27+
- name: golangci-lint
28+
uses: golangci/golangci-lint-action@v3

.github/workflows/release.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: goreleaser
2+
3+
on:
4+
push:
5+
tags:
6+
- v*.*.*
7+
8+
jobs:
9+
goreleaser:
10+
runs-on: ubuntu-latest
11+
env:
12+
GOFLAGS: -mod=readonly
13+
GOPROXY: https://proxy.golang.org
14+
steps:
15+
- name: Checkout
16+
uses: actions/checkout@v3
17+
18+
- name: Set up Go
19+
uses: actions/setup-go@v3
20+
with:
21+
go-version-file: go.mod
22+
23+
- name: Run GoReleaser
24+
uses: goreleaser/goreleaser-action@v3
25+
with:
26+
distribution: goreleaser
27+
version: latest
28+
args: release --rm-dist
29+
env:
30+
GITHUB_TOKEN: ${{ secrets.PERSONAL_GITHUB_TOKEN }}

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,9 @@
1313

1414
# Dependency directories (remove the comment below to include it)
1515
# vendor/
16+
bin/
17+
.history*
18+
.idea/
19+
.vscode/
20+
*untracked_*.go
21+

.golangci.yml

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
run:
2+
timeout: 5m
3+
tests: false
4+
5+
linters-settings:
6+
golint:
7+
min-confidence: 0
8+
goimports:
9+
local-prefixes: github.com/foomo/contentfulcommander
10+
gocritic:
11+
enabled-tags:
12+
- diagnostic
13+
- style
14+
disabled-tags:
15+
- performance
16+
- experimental
17+
- opinionated
18+
lll:
19+
line-length: 150
20+
21+
linters:
22+
disable-all: true
23+
enable:
24+
- bodyclose
25+
- dogsled
26+
- dupl
27+
- exhaustive
28+
- exportloopref
29+
- goconst
30+
- gofmt
31+
- gofumpt
32+
- goimports
33+
- revive
34+
- goprintffuncname
35+
- govet
36+
- ineffassign
37+
- misspell
38+
- nakedret
39+
- noctx
40+
- nolintlint
41+
- prealloc
42+
- rowserrcheck
43+
- sqlclosecheck
44+
- staticcheck
45+
- stylecheck
46+
- typecheck
47+
- unconvert
48+
- unparam
49+
- unused
50+
- whitespace
51+
- errcheck
52+
- gocritic
53+
- gosimple
54+
55+
- gocyclo
56+
- gosec
57+
- lll
58+
- exportloopref
59+
60+
# unused
61+
# - godot
62+
# - gocognit
63+
# - nlreturn
64+
# - gochecknoglobals
65+
# - gochecknoinits
66+
# - depguard
67+
# - goheader
68+
# - gomodguard
69+
70+
# don't enable:
71+
# - asciicheck
72+
# - funlen
73+
# - godox
74+
# - goerr113
75+
# - gomnd
76+
# - interfacer
77+
# - maligned
78+
# - nestif
79+
# - testpackage
80+
# - wsl

.goreleaser.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# .goreleaser.yml
2+
# Build customization
3+
builds:
4+
- binary: contentfulcommander
5+
main: ./main.go
6+
env:
7+
- CGO_ENABLED=0
8+
ldflags:
9+
- -s -w -X main.VERSION={{.Version}}
10+
goos:
11+
- windows
12+
- darwin
13+
- linux
14+
goarch:
15+
- amd64
16+
- arm64
17+
ignore:
18+
- goos: windows
19+
goarch: arm64
20+
21+
# .goreleaser.yml
22+
archives:
23+
- format: tar.gz
24+
format_overrides:
25+
- goos: windows
26+
format: zip
27+
28+
brews:
29+
# Reporitory to push the tap to.
30+
- tap:
31+
owner: foomo
32+
name: homebrew
33+
caveats: "contentfulcommander help"
34+
homepage: "https://github.com/foomo/contentfulcommander"
35+
description: "A toolbox of non-trivial Contentful interactions"

Makefile

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
.DEFAULT_GOAL:=help
2+
3+
## === Tasks ===
4+
5+
.PHONY: install
6+
## Install binary
7+
install:
8+
go build -o ${GOPATH}/bin/contenfulcommander main.go
9+
10+
.PHONY: build
11+
## Build binary
12+
build:
13+
mkdir -p bin
14+
go build -o bin/contenfulcommander main.go
15+
16+
.PHONY: lint
17+
## Run linter
18+
lint:
19+
golangci-lint run
20+
21+
.PHONY: lint.fix
22+
## Fix lint violations
23+
lint.fix:
24+
golangci-lint run --fix
25+
26+
27+
## === Utils ===
28+
29+
## Show help text
30+
help:
31+
@awk '{ \
32+
if ($$0 ~ /^.PHONY: [a-zA-Z\-\_0-9]+$$/) { \
33+
helpCommand = substr($$0, index($$0, ":") + 2); \
34+
if (helpMessage) { \
35+
printf "\033[36m%-23s\033[0m %s\n", \
36+
helpCommand, helpMessage; \
37+
helpMessage = ""; \
38+
} \
39+
} else if ($$0 ~ /^[a-zA-Z\-\_0-9.]+:/) { \
40+
helpCommand = substr($$0, 0, index($$0, ":")); \
41+
if (helpMessage) { \
42+
printf "\033[36m%-23s\033[0m %s\n", \
43+
helpCommand, helpMessage"\n"; \
44+
helpMessage = ""; \
45+
} \
46+
} else if ($$0 ~ /^##/) { \
47+
if (helpMessage) { \
48+
helpMessage = helpMessage"\n "substr($$0, 3); \
49+
} else { \
50+
helpMessage = substr($$0, 3); \
51+
} \
52+
} else { \
53+
if (helpMessage) { \
54+
print "\n "helpMessage"\n" \
55+
} \
56+
helpMessage = ""; \
57+
} \
58+
}' \
59+
$(MAKEFILE_LIST)

cmd/chid/chid.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@ package chid
22

33
import (
44
"encoding/json"
5-
"github.com/foomo/contentfulcommander/model"
65
"log"
76

87
"github.com/foomo/contentful"
8+
99
"github.com/foomo/contentfulcommander/cmd/common"
1010
"github.com/foomo/contentfulcommander/contentfulclient"
11+
"github.com/foomo/contentfulcommander/model"
1112
)
1213

1314
func Run(cma *contentful.Contentful, params []string) error {

cmd/modeldiff/modeldiff.go

Lines changed: 25 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,16 @@ import (
55
"encoding/json"
66
"errors"
77
"fmt"
8+
"sort"
9+
"strings"
10+
811
"github.com/foomo/contentful"
12+
913
"github.com/foomo/contentfulcommander/contentfulclient"
1014
"github.com/foomo/contentfulcommander/model"
11-
"sort"
12-
"strings"
1315
)
1416

1517
func Run(cma *contentful.Contentful, params []string) error {
16-
1718
firstSpace, firstEnvironment := contentfulclient.GetSpaceAndEnvironment(params[0])
1819
if firstSpace == "" {
1920
return errors.New("firstspace ID is empty")
@@ -77,35 +78,32 @@ func getContentTypes(cma *contentful.Contentful, spaceID, environment string) (c
7778
}
7879

7980
func diffContentTypes(firstSpaceName, secondSpaceName string, firstSpaceContentTypes, secondSpaceContentTypes []model.ContentType) {
80-
8181
firstContentTypeMap,
8282
secondContentTypeMap,
8383
firstOnlyTypes,
8484
secondOnlyTypes,
8585
_,
86-
sortedTypes :=
87-
sliceElementsCompare(firstSpaceContentTypes, secondSpaceContentTypes,
88-
func(contentType model.ContentType) string {
89-
return contentType.Sys.ID
90-
})
86+
sortedTypes := sliceElementsCompare(firstSpaceContentTypes, secondSpaceContentTypes,
87+
func(contentType model.ContentType) string {
88+
return contentType.Sys.ID
89+
})
9190

92-
const contentTypeHeader = "Content Type: '%s' %s\n"
9391
for _, contentTypeID := range sortedTypes {
9492
if _, ok := firstOnlyTypes[contentTypeID]; ok {
95-
_ = printContentTypeHeader(contentTypeHeader, contentTypeID, false)
93+
_ = printContentTypeHeader(contentTypeID, false)
9694
fmt.Printf("AAA ___ content type only available in %s\n", firstSpaceName)
9795
continue
9896
}
9997
if _, ok := secondOnlyTypes[contentTypeID]; ok {
100-
_ = printContentTypeHeader(contentTypeHeader, contentTypeID, false)
98+
_ = printContentTypeHeader(contentTypeID, false)
10199
fmt.Printf("___ BBB content type only available in %s\n", secondSpaceName)
102100
continue
103101
}
104102
firstContentType := firstContentTypeMap[contentTypeID]
105103
secondContentType := secondContentTypeMap[contentTypeID]
106104
contentTypeHeaderAlreadyPrinted := false
107105
if firstContentType.Name != secondContentType.Name {
108-
contentTypeHeaderAlreadyPrinted = printContentTypeHeader(contentTypeHeader, contentTypeID, contentTypeHeaderAlreadyPrinted)
106+
contentTypeHeaderAlreadyPrinted = printContentTypeHeader(contentTypeID, contentTypeHeaderAlreadyPrinted)
109107
fmt.Printf("AAA BBB Name is different\n")
110108
fmt.Printf(" ^ ^----B: %s\n", firstContentType.Name)
111109
fmt.Printf(" ^--------A: %s\n", secondContentType.Name)
@@ -123,27 +121,26 @@ func diffContentTypes(firstSpaceName, secondSpaceName string, firstSpaceContentT
123121
firstOnlyFields,
124122
secondOnlyFields,
125123
_,
126-
sortedFields :=
127-
sliceElementsCompare(firstFields, secondFields,
128-
func(field model.ContentTypeField) string {
129-
return field.ID
130-
})
124+
sortedFields := sliceElementsCompare(firstFields, secondFields,
125+
func(field model.ContentTypeField) string {
126+
return field.ID
127+
})
131128
for _, fieldID := range sortedFields {
132129
if _, ok := firstOnlyFields[fieldID]; ok {
133-
contentTypeHeaderAlreadyPrinted = printContentTypeHeader(contentTypeHeader, contentTypeID, contentTypeHeaderAlreadyPrinted)
130+
contentTypeHeaderAlreadyPrinted = printContentTypeHeader(contentTypeID, contentTypeHeaderAlreadyPrinted)
134131
fmt.Printf(" AAA ___ field '%s' only available in %s\n", fieldID, firstSpaceName)
135132
continue
136133
}
137134
if _, ok := secondOnlyFields[fieldID]; ok {
138-
contentTypeHeaderAlreadyPrinted = printContentTypeHeader(contentTypeHeader, contentTypeID, contentTypeHeaderAlreadyPrinted)
135+
contentTypeHeaderAlreadyPrinted = printContentTypeHeader(contentTypeID, contentTypeHeaderAlreadyPrinted)
139136
fmt.Printf(" ___ BBB field '%s' only available in %s\n", fieldID, firstSpaceName)
140137
continue
141138
}
142139
firstField := firstContentTypeFieldMap[fieldID]
143140
secondField := secondContentTypeFieldMap[fieldID]
144141
fieldHeaderAlreadyPrinted := false
145142
printHeaders := func() {
146-
contentTypeHeaderAlreadyPrinted = printContentTypeHeader(contentTypeHeader, contentTypeID, contentTypeHeaderAlreadyPrinted)
143+
contentTypeHeaderAlreadyPrinted = printContentTypeHeader(contentTypeID, contentTypeHeaderAlreadyPrinted)
147144
fieldHeaderAlreadyPrinted = printFieldHeader(fieldID, fieldHeaderAlreadyPrinted)
148145
}
149146
if firstField.Name != secondField.Name {
@@ -174,14 +171,14 @@ func diffContentTypes(firstSpaceName, secondSpaceName string, firstSpaceContentT
174171
printHeaders()
175172
printFieldValuesAB("Required", secondField.Required, firstField.Required)
176173
}
177-
firstFieldValidations := getJsonString(firstField.Validations)
178-
secondFieldValidations := getJsonString(secondField.Validations)
174+
firstFieldValidations := getJSONString(firstField.Validations)
175+
secondFieldValidations := getJSONString(secondField.Validations)
179176
if firstFieldValidations != secondFieldValidations {
180177
printHeaders()
181178
printFieldValuesAB("Validations", firstFieldValidations, secondFieldValidations)
182179
}
183-
firstFieldItems := getJsonString(firstField.Items)
184-
secondFieldItems := getJsonString(secondField.Items)
180+
firstFieldItems := getJSONString(firstField.Items)
181+
secondFieldItems := getJSONString(secondField.Items)
185182
if firstFieldItems != secondFieldItems {
186183
printHeaders()
187184
printFieldValuesAB("Items", firstFieldItems, secondFieldItems)
@@ -190,7 +187,7 @@ func diffContentTypes(firstSpaceName, secondSpaceName string, firstSpaceContentT
190187
}
191188
}
192189

193-
func getJsonString(value any) (stringValue string) {
190+
func getJSONString(value any) (stringValue string) {
194191
byt, _ := json.Marshal(value)
195192
stringValue = string(byt)
196193
return
@@ -240,9 +237,9 @@ func sliceElementsCompare[A any](firstSlice, secondSlice []A, getID func(element
240237
return firstObjectMap, secondObjectMap, firstOnly, secondOnly, common, sortedIDs
241238
}
242239

243-
func printContentTypeHeader(contentTypeHeader, contentTypeID string, contentTypeHeaderAlreadyPrinted bool) bool {
240+
func printContentTypeHeader(contentTypeID string, contentTypeHeaderAlreadyPrinted bool) bool {
244241
if !contentTypeHeaderAlreadyPrinted {
245-
fmt.Printf(contentTypeHeader, contentTypeID, strings.Repeat("-", 80-len(contentTypeID)))
242+
fmt.Printf("Content Type: '%s' %s\n", contentTypeID, strings.Repeat("-", 80-len(contentTypeID)))
246243
}
247244
return true
248245
}

0 commit comments

Comments
 (0)