Skip to content

Commit d675e80

Browse files
committed
Replace Makefile with GNUmakefile for hashicorp consistency
Fix format.bash to be consistent with gofmtcheck.sh Introduce errcheck.sh for verifying that all errors are checked. Add additional checks in verify.bash Use `/usr/bin/env bash` rather than /bin/bash to check bash on the PATH rather than hardcoded location Add gogetcookie.sh to use cookies, if you access a remote Git repository through HTTP and if that server uses cookies e.g. for authentication purposes. Get rid of the bootstrap shell file. Added changelog-links.sh to automatically change GH-nnnn style references to clickable links. Use provider package (instead of oci) to make tests compile. Get rid of use of IGNORE_PRE_PUSH_HOOK environment variable in pre-push.bash. Its purpose can be achieved with --no-verify from the command line itself. The test-compile target generates a binary that needs to be ignored from the repo. Fix the passing of debug flag to the acceptance tests Add get release and zip targets as well which were part of the previous Makefile Make the acceptance tests timeout configurable Use pattern from https://mijailovic.net/2017/05/09/error-handling-patterns-in-go/ to make a safeClose on the io.Closer that makes errcheck happy in helpers_objectstorage.go Use proper formatting for logging in helpers_objectstorage.go Add goimports related checking in gofmtcheck.sh as well as in `fmt` target Support run=regex style invocation of tests as well. Add ability to skip goimports checking via a flag. Add update-version target that updates the provider version Fix website-test to create symlinks for oci layouts - this will be removed once the registration is done Increase time required for unit tests
1 parent 76e9f4f commit d675e80

File tree

14 files changed

+251
-165
lines changed

14 files changed

+251
-165
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,4 @@ debug.test
2222
*.ipr
2323
docs/solutions/rhel74_image/ipxe.sh
2424
vendor/github.com/oracle/oci-go-sdk/target
25+
*.test

GNUmakefile

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
TEST?=./...
2+
GOFMT_FILES?=$$(find . -name '*.go' |grep -v vendor)
3+
PKG_NAME=oci
4+
# Collapse with PKG_NAME once we've moved to the hashicorp repo
5+
TEST_PKG_NAME=provider
6+
WEBSITE_REPO=github.com/hashicorp/terraform-website
7+
8+
prefix := $(if $(debug),TF_LOG=DEBUG DEBUG=true OCI_GO_SDK_DEBUG=1, )
9+
timeout := $(if $(timeout), $(timeout), 120m)
10+
run_regex := $(if $(run), -run $(run), )
11+
skip_goimports_check_flag := $(if $(skip_goimports_check), -s, )
12+
13+
default: build
14+
15+
build: fmtcheck
16+
go install
17+
18+
test: fmtcheck
19+
go test -i $(TEST) || exit 1
20+
echo $(TEST) | \
21+
xargs -t -n4 go test $(TESTARGS) -timeout=120s -parallel=4
22+
23+
testacc: fmtcheck
24+
TF_ACC=1 $(prefix) go test $(TEST) -v $(TESTARGS) $(run_regex) -timeout $(timeout)
25+
26+
vet:
27+
@echo "go vet ."
28+
@go vet $$(go list ./... | grep -v vendor/) ; if [ $$? -eq 1 ]; then \
29+
echo ""; \
30+
echo "Vet found suspicious constructs. Please check the reported constructs"; \
31+
echo "and fix them if necessary before submitting the code for review."; \
32+
exit 1; \
33+
fi
34+
35+
fmt:
36+
gofmt -w $(GOFMT_FILES)
37+
goimports -w -local github.com/oracle/terraform-provider-oci $(GOFMT_FILES)
38+
39+
fmtcheck:
40+
@sh -c "'$(CURDIR)/scripts/gofmtcheck.sh' $(skip_goimports_check_flag)"
41+
42+
errcheck:
43+
@sh -c "'$(CURDIR)/scripts/errcheck.sh'"
44+
45+
vendor-status:
46+
@govendor status
47+
48+
test-compile:
49+
@if [ "$(TEST)" = "./..." ]; then \
50+
echo "ERROR: Set TEST to a specific package. For example,"; \
51+
echo " make test-compile TEST=./$(TEST_PKG_NAME)"; \
52+
exit 1; \
53+
fi
54+
go test -c $(TEST) $(TESTARGS)
55+
56+
website:
57+
ifeq (,$(wildcard $(GOPATH)/src/$(WEBSITE_REPO)))
58+
echo "$(WEBSITE_REPO) not found in your GOPATH (necessary for layouts and assets), get-ting..."
59+
git clone https://$(WEBSITE_REPO) $(GOPATH)/src/$(WEBSITE_REPO)
60+
endif
61+
@$(MAKE) -C $(GOPATH)/src/$(WEBSITE_REPO) website-provider PROVIDER_PATH=$(shell pwd) PROVIDER_NAME=$(PKG_NAME)
62+
63+
website-test:
64+
ifeq (,$(wildcard $(GOPATH)/src/$(WEBSITE_REPO)))
65+
echo "$(WEBSITE_REPO) not found in your GOPATH (necessary for layouts and assets), get-ting..."
66+
git clone https://$(WEBSITE_REPO) $(GOPATH)/src/$(WEBSITE_REPO)
67+
# Additional steps before registration is complete
68+
ln -s ../../../../ext/providers/oci/website/docs $(GOPATH)/src/$(WEBSITE_REPO)/content/source/docs/providers/oci
69+
ln -s ../../../ext/providers/oci/website/oci.erb $(GOPATH)/src/$(WEBSITE_REPO)/content/source/layouts/oci.erb
70+
endif
71+
@$(MAKE) -C $(GOPATH)/src/$(WEBSITE_REPO) website-provider-test PROVIDER_PATH=$(shell pwd) PROVIDER_NAME=$(PKG_NAME)
72+
73+
## Additional OCI stuff that will need to be moved eventually
74+
get: ;go get -u github.com/kardianos/govendor; go get golang.org/x/tools/cmd/goimports; go get github.com/mitchellh/gox
75+
76+
### `make update-version version=2.0.1`
77+
update-version:
78+
ifdef version
79+
sed -i -e 's/Version = ".*"/Version = "$(version)"/g' provider/version.go && rm -f provider/version.go-e
80+
else
81+
@echo Err! `make update-version` requires a version argument
82+
endif
83+
84+
### `make release version=2.0.1`
85+
release: clean get
86+
ifdef version
87+
sed -i -e 's/Version = ".*"/Version = "$(version)"/g' provider/version.go && rm -f provider/version.go-e
88+
gox -output ./bin/{{.OS}}_{{.Arch}}/terraform-provider-oci_v$(version)
89+
gox -output ./bin/solaris_amd64/terraform-provider-oci_v$(version) -osarch="solaris/amd64"
90+
else
91+
@echo Err! `make release` requires a version argument
92+
endif
93+
94+
clean: ;@rm -rf terraform-provider-oci rm -rf bin/* rm bin
95+
96+
zip:
97+
@cd bin; \
98+
zip -r windows_386.zip windows_386; \
99+
zip -r windows_amd64.zip windows_amd64; \
100+
tar -czvf darwin_386.tar.gz darwin_386; \
101+
tar -czvf darwin_amd64.tar.gz darwin_amd64; \
102+
tar -czvf freebsd_386.tar.gz freebsd_386; \
103+
tar -czvf freebsd_amd64.tar.gz freebsd_amd64; \
104+
tar -czvf freebsd_arm.tar.gz freebsd_arm; \
105+
tar -czvf linux_386.tar.gz linux_386; \
106+
tar -czvf linux_amd64.tar.gz linux_amd64; \
107+
tar -czvf linux_arm.tar.gz linux_arm; \
108+
tar -czvf openbsd_386.tar.gz openbsd_386; \
109+
tar -czvf openbsd_amd64.tar.gz openbsd_amd64; \
110+
tar -czvf solaris_amd64.tar.gz solaris_amd64
111+
112+
.PHONY: build test testacc vet fmt fmtcheck errcheck vendor-status test-compile website website-test
113+

Makefile

Lines changed: 0 additions & 82 deletions
This file was deleted.

provider/helpers_objectstorage.go

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -117,18 +117,24 @@ func validateSourceValue(i interface{}, k string) (s []string, es []error) {
117117
return
118118
}
119119

120+
// Borrowed from https://mijailovic.net/2017/05/09/error-handling-patterns-in-go/
121+
func safeClose(c io.Closer, err *error) {
122+
if cerr := c.Close(); cerr != nil && *err == nil {
123+
*err = cerr
124+
}
125+
}
126+
120127
func singlePartUpload(multipartUploadData MultipartUploadData) (string, error) {
121128

122129
sourcePath := *multipartUploadData.SourcePath
123130
sourceInfo := *multipartUploadData.SourceInfo
124131

125132
sourceFile, err := os.Open(sourcePath)
126-
127133
if err != nil {
128134
return "", err
129135
}
130136

131-
defer sourceFile.Close()
137+
defer safeClose(sourceFile, &err)
132138

133139
tmpSize := sourceInfo.Size()
134140

@@ -187,7 +193,7 @@ func multiPartUploadImpl(multipartUploadData MultipartUploadData) (string, error
187193
if err != nil {
188194
return "", fmt.Errorf("error opening source file for upload %q: %s", source, err)
189195
}
190-
defer file.Close()
196+
defer safeClose(file, &err)
191197

192198
sourceBlocks, err := objectMultiPartSplit(file)
193199
if err != nil {
@@ -230,10 +236,10 @@ func multiPartUploadImpl(multipartUploadData MultipartUploadData) (string, error
230236
commitMultipartUploadPartDetails := make([]oci_object_storage.CommitMultipartUploadPartDetails, len(sourceBlocks))
231237

232238
osResponseIndex := 0
233-
var error error
239+
var uploadPartRespErr error
234240
for osUploadPartResponse := range osUploadPartResponses {
235241
if osUploadPartResponse.error != nil {
236-
error = osUploadPartResponse.error
242+
uploadPartRespErr = osUploadPartResponse.error
237243
break
238244
}
239245

@@ -244,7 +250,7 @@ func multiPartUploadImpl(multipartUploadData MultipartUploadData) (string, error
244250
osResponseIndex++
245251
}
246252

247-
if error != nil {
253+
if uploadPartRespErr != nil {
248254
// just aborting the multi upload for now; but the service itself will handle the same request again
249255
abortMultipartUploadRequest := oci_object_storage.AbortMultipartUploadRequest{
250256
NamespaceName: multipartUploadResponse.Namespace,
@@ -261,7 +267,7 @@ func multiPartUploadImpl(multipartUploadData MultipartUploadData) (string, error
261267
log.Println("[WARN] Aborting the multi part upload failed")
262268
}
263269

264-
return "", fmt.Errorf("failed to upload object parts of %q to the Oracle cloud: %s", source, error)
270+
return "", fmt.Errorf("failed to upload object parts of %q to the Oracle cloud: %s", source, uploadPartRespErr)
265271
}
266272

267273
commitMultipartUploadRequest := oci_object_storage.CommitMultipartUploadRequest{

provider/version.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"log"
77
)
88

9-
// Version injected during Makefile "release" build step, do not commit change
9+
// Version injected during GNUmakefile "release" build step, do not commit change
1010
const Version = "0.0.0"
1111

1212
func PrintVersion() {

scripts/bootstrap

Lines changed: 0 additions & 4 deletions
This file was deleted.

scripts/changelog-links.sh

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/usr/bin/env bash
2+
3+
# This script rewrites [GH-nnnn]-style references in the CHANGELOG.md file to
4+
# be Markdown links to the given github issues.
5+
#
6+
# This is run during releases so that the issue references in all of the
7+
# released items are presented as clickable links, but we can just use the
8+
# easy [GH-nnnn] shorthand for quickly adding items to the "Unrelease" section
9+
# while merging things between releases.
10+
11+
set -e
12+
13+
if [[ ! -f CHANGELOG.md ]]; then
14+
echo "ERROR: CHANGELOG.md not found in pwd."
15+
echo "Please run this from the root of the terraform provider repository"
16+
exit 1
17+
fi
18+
19+
if [[ `uname` == "Darwin" ]]; then
20+
echo "Using BSD sed"
21+
SED="sed -i.bak -E -e"
22+
else
23+
echo "Using GNU sed"
24+
SED="sed -i.bak -r -e"
25+
fi
26+
27+
PROVIDER_URL="https:\/\/github.com\/terraform-providers\/terraform-provider-oci\/issues"
28+
29+
$SED "s/GH-([0-9]+)/\[#\1\]\($PROVIDER_URL\/\1\)/g" -e 's/\[\[#(.+)([0-9])\)]$/(\[#\1\2))/g' CHANGELOG.md
30+
31+
rm CHANGELOG.md.bak

scripts/errcheck.sh

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/usr/bin/env bash
2+
3+
echo "==> Checking for unchecked errors..."
4+
5+
if ! which errcheck > /dev/null; then
6+
echo "==> Installing errcheck..."
7+
go get -u github.com/kisielk/errcheck
8+
fi
9+
10+
err_files=$(errcheck -ignoretests \
11+
-ignore 'github.com/hashicorp/terraform/helper/schema:Set' \
12+
-ignore 'bytes:.*' \
13+
-ignore 'io:Close|Write' \
14+
$(go list ./...| grep -v /vendor/))
15+
16+
if [[ -n ${err_files} ]]; then
17+
echo 'Unchecked errors found in the following places:'
18+
echo "${err_files}"
19+
echo "Please handle returned errors. You can check directly with \`make errcheck\`"
20+
exit 1
21+
fi
22+
23+
exit 0

scripts/format.bash

Lines changed: 0 additions & 35 deletions
This file was deleted.

0 commit comments

Comments
 (0)