Skip to content

Commit

Permalink
Dev and release workflow improvements (#38)
Browse files Browse the repository at this point in the history
* Update Makefile; remove cruft

 Fixes #25

* Add CircleCI integration

 Fixes #24

* Clean up linter errors

 #24

* Add releasing with GoReleaser

 Fixes #36

* Fix typo
  • Loading branch information
Trevor Rosen authored Jan 14, 2020
1 parent 7c6224c commit 5659863
Show file tree
Hide file tree
Showing 20 changed files with 115 additions and 555 deletions.
26 changes: 26 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
version: 2.1
jobs:
build:
docker:
- image: circleci/golang:1.13.0
working_directory: /go/src/github.com/{{ORG_NAME}}/{{REPO_NAME}}
steps:
- checkout
- run:
name: Install golangci-lint
command: curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -d -b $(go env GOPATH)/bin v1.18.0

- run:
name: Run lint
when: always
command: make lint

- run:
name: Run vet
when: always
command: make vet

- run:
name: Run tests
when: always
command: make test
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,4 @@ website/vendor
!command/test-fixtures/**/*.tfstate
!command/test-fixtures/**/.terraform/
terraform-provider-appoptics
dist/
29 changes: 29 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
before:
hooks:
- go mod tidy
builds:
-
goos:
- darwin
- linux
goarch:
- amd64
env:
- CGO_ENABLED=0
archives:
-
replacements:
darwin: Darwin
linux: Linux
386: i386
amd64: x86_64
checksum:
name_template: 'checksums.txt'
snapshot:
name_template: "{{ .Tag }}"
changelog:
sort: asc
filters:
exclude:
- '^docs:'
- '^test:'
55 changes: 16 additions & 39 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,52 +1,29 @@
TEST?=$$(go list ./... |grep -v 'vendor')
WEBSITE_REPO=github.com/hashicorp/terraform-website
PKG_NAME=librato
plugin_name=terraform-provider-appoptics
plugin_path=~/.terraform.d/plugins
.PHONY: build test testacc vet lint release

plugin_name=terraform-provider-appoptics

default: build

build:
go build -o $(plugin_name)

user-install:
mkdir -p $(plugin_path) && go build -o $(plugin_path)/$(plugin_name)
test:
go test ./...

test: fmtcheck
go test -i $(TEST) || exit 1
echo $(TEST) | \
xargs -t -n4 go test $(TESTARGS) -timeout=30s -parallel=4

testacc: fmtcheck
TF_ACC=1 go test $(TEST) -v $(TESTARGS) -timeout 120m
testacc:
TF_ACC=1 go test -v -timeout 120m

vet:
@echo "go vet ."
@go vet $$(go list ./... | grep -v vendor/) ; if [ $$? -eq 1 ]; then \
echo ""; \
echo "Vet found suspicious constructs. Please check the reported constructs"; \
echo "and fix them if necessary before submitting the code for review."; \
exit 1; \
fi

fmtcheck:
@sh -c "'$(CURDIR)/scripts/gofmtcheck.sh'"

errcheck:
@sh -c "'$(CURDIR)/scripts/errcheck.sh'"

vendor-status:
@govendor status

test-compile:
@if [ "$(TEST)" = "./..." ]; then \
echo "ERROR: Set TEST to a specific package. For example,"; \
echo " make test-compile TEST=./$(PKG_NAME)"; \
exit 1; \
fi
go test -c $(TEST) $(TESTARGS)
go vet ./...

lint:
"$$(go env GOPATH)/bin/golangci-lint" run

.PHONY: build test testacc vet fmt fmtcheck errcheck vendor-status test-compile website website-test
# Produces artifacts in the dist directory
# DOES NOT push release artifacts
test-release:
goreleaser --snapshot --skip-publish --rm-dist

# Requires a GITHUB_TOKEN to be set in the environment
release:
goreleaser --rm-dist
2 changes: 1 addition & 1 deletion appoptics/resource_appoptics_alert.go
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ func resourceAppOpticsAlertRead(d *schema.ResourceData, meta interface{}) error
}
log.Printf("[INFO] Received AppOptics Alert: %s", alert.Name)

d.Set("name", alert.Name)
d.Set("name", alert.Name) //nolint

if err := d.Set("description", alert.Description); err != nil {
return err
Expand Down
12 changes: 6 additions & 6 deletions appoptics/resource_appoptics_metric.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,23 +193,23 @@ func resourceAppOpticsMetricRead(d *schema.ResourceData, meta interface{}) error
return fmt.Errorf("Error reading AppOptics Metric %s: %s", id, err)
}

d.Set("name", metric.Name)
d.Set("type", metric.Type)
d.Set("name", metric.Name) //nolint
d.Set("type", metric.Type) //nolint

if metric.Description != "" {
d.Set("description", metric.Description)
d.Set("description", metric.Description) //nolint
}

if metric.DisplayName != "" {
d.Set("display_name", metric.DisplayName)
d.Set("display_name", metric.DisplayName) //nolint
}

if metric.Period != 0 {
d.Set("period", metric.Period)
d.Set("period", metric.Period) //nolint
}

if metric.Composite != "" {
d.Set("composite", metric.Composite)
d.Set("composite", metric.Composite) //nolint
}

attributes := metricAttributesGather(d, &metric.Attributes)
Expand Down
22 changes: 14 additions & 8 deletions appoptics/resource_appoptics_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,7 @@ func resourceAppOpticsService() *schema.Resource {
// Takes JSON in a string. Decodes JSON into
// settings hash
func resourceAppOpticsServicesExpandSettings(rawSettings string) (map[string]string, error) {
var settings map[string]string

settings = make(map[string]string)
settings := make(map[string]string)
err := json.Unmarshal([]byte(rawSettings), &settings)
if err != nil {
return nil, fmt.Errorf("Error decoding JSON: %s", err)
Expand Down Expand Up @@ -103,7 +101,7 @@ func resourceAppOpticsServiceCreate(d *schema.ResourceData, meta interface{}) er
return fmt.Errorf("Error creating AppOptics service: %s", err)
}

resource.Retry(1*time.Minute, func() *resource.RetryError {
retryErr := resource.Retry(1*time.Minute, func() *resource.RetryError {
_, err := client.ServicesService().Retrieve(serviceResult.ID)
if err != nil {
if errResp, ok := err.(*appoptics.ErrorResponse); ok && errResp.Response.StatusCode == 404 {
Expand All @@ -114,6 +112,10 @@ func resourceAppOpticsServiceCreate(d *schema.ResourceData, meta interface{}) er
return nil
})

if retryErr != nil {
return retryErr
}

d.SetId(strconv.Itoa(serviceResult.ID))
return resourceAppOpticsServiceReadResult(d, *serviceResult)
}
Expand Down Expand Up @@ -141,10 +143,10 @@ func resourceAppOpticsServiceRead(d *schema.ResourceData, meta interface{}) erro

func resourceAppOpticsServiceReadResult(d *schema.ResourceData, service appoptics.Service) error {
d.SetId(strconv.FormatUint(uint64(service.ID), 10))
d.Set("type", service.Type)
d.Set("title", service.Title)
d.Set("type", service.Type) //nolint
d.Set("title", service.Title) //nolint
settings, _ := resourceAppOpticsServicesFlatten(service.Settings)
d.Set("settings", settings)
d.Set("settings", settings) //nolint

return nil
}
Expand Down Expand Up @@ -223,7 +225,7 @@ func resourceAppOpticsServiceDelete(d *schema.ResourceData, meta interface{}) er
return fmt.Errorf("Error deleting Service: %s", err)
}

resource.Retry(1*time.Minute, func() *resource.RetryError {
retryErr := resource.Retry(1*time.Minute, func() *resource.RetryError {
_, err := client.ServicesService().Retrieve(int(id))
if err != nil {
if errResp, ok := err.(*appoptics.ErrorResponse); ok && errResp.Response.StatusCode == 404 {
Expand All @@ -234,6 +236,10 @@ func resourceAppOpticsServiceDelete(d *schema.ResourceData, meta interface{}) er
return resource.RetryableError(fmt.Errorf("service still exists"))
})

if retryErr != nil {
return retryErr
}

d.SetId("")
return nil
}
12 changes: 10 additions & 2 deletions appoptics/resource_appoptics_space.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func resourceAppOpticsSpaceCreate(d *schema.ResourceData, meta interface{}) erro
return fmt.Errorf("Error creating AppOptics space %s: %s", name, err)
}

resource.Retry(1*time.Minute, func() *resource.RetryError {
retryErr := resource.Retry(1*time.Minute, func() *resource.RetryError {
_, err := client.SpacesService().Retrieve(space.ID)
if err != nil {
if errResp, ok := err.(*appoptics.ErrorResponse); ok && errResp.Response.StatusCode == 404 {
Expand All @@ -49,6 +49,10 @@ func resourceAppOpticsSpaceCreate(d *schema.ResourceData, meta interface{}) erro
return nil
})

if retryErr != nil {
return retryErr
}

d.SetId(strconv.Itoa(space.ID))
return resourceAppOpticsSpaceReadResult(d, space)
}
Expand Down Expand Up @@ -116,7 +120,7 @@ func resourceAppOpticsSpaceDelete(d *schema.ResourceData, meta interface{}) erro
return fmt.Errorf("Error deleting space: %s", err)
}

resource.Retry(1*time.Minute, func() *resource.RetryError {
retryErr := resource.Retry(1*time.Minute, func() *resource.RetryError {
_, err := client.SpacesService().Retrieve(int(id))
if err != nil {
if errResp, ok := err.(*appoptics.ErrorResponse); ok && errResp.Response.StatusCode == 404 {
Expand All @@ -127,6 +131,10 @@ func resourceAppOpticsSpaceDelete(d *schema.ResourceData, meta interface{}) erro
return resource.RetryableError(fmt.Errorf("space still exists"))
})

if retryErr != nil {
return retryErr
}

d.SetId("")
return nil
}
16 changes: 12 additions & 4 deletions appoptics/resource_librato_space_chart.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ func resourceAppOpticsSpaceChartCreate(d *schema.ResourceData, meta interface{})
return fmt.Errorf("Error creating AppOptics space chart %s: %s", spaceChart.Name, err)
}

resource.Retry(1*time.Minute, func() *resource.RetryError {
retryErr := resource.Retry(1*time.Minute, func() *resource.RetryError {
_, err := client.ChartsService().Retrieve(spaceChartResult.ID, spaceID)
if err != nil {
if errResp, ok := err.(*appoptics.ErrorResponse); ok && errResp.Response.StatusCode == 404 {
Expand All @@ -269,6 +269,10 @@ func resourceAppOpticsSpaceChartCreate(d *schema.ResourceData, meta interface{})
return nil
})

if retryErr != nil {
return retryErr
}

return resourceAppOpticsSpaceChartReadResult(d, spaceChartResult)
}

Expand Down Expand Up @@ -443,10 +447,10 @@ func resourceAppOpticsSpaceChartUpdate(d *schema.ResourceData, meta interface{})
if v, ok := streamData["units_longs"].(string); ok && v != "" {
stream.UnitsLong = v
}
if v, ok := streamData["min"].(int); ok && !math.IsNaN(float64(v)) {
if v, ok := streamData["min"].(int); ok {
stream.Min = v
}
if v, ok := streamData["max"].(int); ok && !math.IsNaN(float64(v)) {
if v, ok := streamData["max"].(int); ok {
stream.Max = v
}
streams[i] = stream
Expand Down Expand Up @@ -503,7 +507,7 @@ func resourceAppOpticsSpaceChartDelete(d *schema.ResourceData, meta interface{})
return fmt.Errorf("Error deleting space: %s", err)
}

resource.Retry(1*time.Minute, func() *resource.RetryError {
retryErr := resource.Retry(1*time.Minute, func() *resource.RetryError {
_, err := client.ChartsService().Retrieve(id, spaceID)
if err != nil {
if errResp, ok := err.(*appoptics.ErrorResponse); ok && errResp.Response.StatusCode == 404 {
Expand All @@ -514,6 +518,10 @@ func resourceAppOpticsSpaceChartDelete(d *schema.ResourceData, meta interface{})
return resource.RetryableError(fmt.Errorf("space chart still exists"))
})

if retryErr != nil {
return retryErr
}

d.SetId("")
return nil
}
31 changes: 0 additions & 31 deletions scripts/changelog-links.sh

This file was deleted.

24 changes: 0 additions & 24 deletions scripts/errcheck.sh

This file was deleted.

13 changes: 0 additions & 13 deletions scripts/gofmtcheck.sh

This file was deleted.

Loading

0 comments on commit 5659863

Please sign in to comment.