Skip to content

Commit

Permalink
(CLOUDDEV-354): v2 init
Browse files Browse the repository at this point in the history
  • Loading branch information
anaxaim committed Nov 22, 2023
1 parent ecdafe4 commit 810e156
Show file tree
Hide file tree
Showing 267 changed files with 281 additions and 33,275 deletions.
28 changes: 9 additions & 19 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,34 +1,24 @@
name: build

on:
push:
branches: [ master ]
pull_request:
branches: [ master, main ]
branches: [ master ]

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v3
uses: actions/setup-go@v4
with:
go-version: 1.20.2
go-version: 1.21.3

- name: Linters
run: make linters
run: make lint

- name: Build
run: go build -v ./...

- name: Tests data_source
env:
EC_USERNAME: ${{ secrets.EC_USERNAME }}
EC_PASSWORD: ${{ secrets.EC_PASSWORD }}
run: make test_cloud_data_source

- name: Tests resource
env:
EC_USERNAME: ${{ secrets.EC_USERNAME }}
EC_PASSWORD: ${{ secrets.EC_PASSWORD }}
run: make test_cloud_resource
- name: Tests
run: make test
49 changes: 0 additions & 49 deletions .github/workflows/release.yml

This file was deleted.

60 changes: 23 additions & 37 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,32 +1,19 @@
run:
timeout: 10m
go: "1.20"
go: "1.21.3"

issues:
max-per-linter: 0
max-same-issues: 0
exclude:
# revive, stylecheck: ignore constants in all caps
- don't use ALL_CAPS in Go names; use CamelCase
- ST1003
# gosec
- G401
- G501
exclude-rules:
- path: \.go
- path: (.+)_test.go
linters:
- nolintlint
text: should be written without leading space
- text: lifecyclepolicy.CreateScheduleOpts
linters:
- ireturn
- path: utils|_test
linters:
- wrapcheck
- funlen

linters:
enable-all: true
disable:
# deprecated
- deadcode
- maligned
- varcheck
Expand All @@ -40,37 +27,36 @@ linters:
- rowserrcheck
- sqlclosecheck
- wastedassign
# skip
- gochecknoglobals # check that no global variables exist
- nilnil # Checks that there is no simultaneous return of nil error and an invalid value.
- gomnd # An analyzer to detect magic numbers.
- goerr113 # Golang linter to check the errors handling expressions
- exhaustruct # Checks if all structure fields are initialized
- lll # Reports long lines
# skip: dubious benefit
- gochecknoglobals # Checks that no global variables exist.
- exhaustruct # Checks if all structure fields are initialized.
- lll # Reports long lines.
- godox # Tool for detection of FIXME, TODO and other comment keywords
- wsl # Whitespace Linter - Forces you to use empty lines!
- tagliatelle # Checks the struct tags.
- nonamedreturns # Reports all named returns.
- wrapcheck # Checks that errors returned from external packages are wrapped.
- ireturn # Accept Interfaces, Return Concrete Types.
- tagalign # Checks that struct tags are well aligned
- depguard # Checks if package imports are in a list of acceptable packages
- musttag # Enforce field tags in (un)marshaled structs.
- dupl # Tool for code clone detection.
- cyclop # Checks function and package cyclomatic complexity.
- forcetypeassert # finds forced type assertions
# complexity: need to refactor
- cyclop
- funlen
- gocognit
- gocyclo
- maintidx
- nestif
- dupl
- depguard
- goerr113 # Golang linter to check the errors handling expressions
# tests
- testpackage # Makes you use a separate _test package.
- paralleltest # Detects missing usage of t.Parallel() method in your Go test.

linters-settings:
nlreturn:
block-size: 10
block-size: 5
gci:
sections:
- standard # Standard section: captures all standard packages.
- default # Default section: contains all imports that could not be matched to another section type.
- prefix(github.com/Edge-Center)
errcheck:
ignore: github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema:ForceNew|Set,fmt:.*,io:Close,io:WriteString
nakedret:
max-func-lines: 40
ignore: github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema:ForceNew|Set,fmt
varnamelen:
min-name-length: 1
51 changes: 2 additions & 49 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -1,60 +1,13 @@
# Visit https://goreleaser.com for documentation on how to customize this
# behavior.
before:
hooks:
# this is just an example and not a requirement for provider building/publishing
- go mod tidy
builds:
- env:
# goreleaser does not work with CGO, it could also complicate
# usage by users in CI/CD systems like Terraform Cloud where
# they are unable to install libraries.
- CGO_ENABLED=0
mod_timestamp: '{{ .CommitTimestamp }}'
flags:
- -trimpath
ldflags:
- '-s -w -X main.version={{.Version}} -X main.commit={{.Commit}}'
goos:
- freebsd
- windows
- linux
- darwin
goarch:
- amd64
- '386'
- arm
- arm64
ignore:
- goos: darwin
goarch: '386'
binary: '{{ .ProjectName }}_v{{ .Version }}'
- skip: true
archives:
- format: zip
name_template: '{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}'
checksum:
extra_files:
- glob: 'terraform-registry-manifest.json'
name_template: '{{ .ProjectName }}_{{ .Version }}_manifest.json'
name_template: '{{ .ProjectName }}_{{ .Version }}_SHA256SUMS'
algorithm: sha256
signs:
- artifacts: checksum
args:
# if you are using this in a GitHub action or some other automated pipeline, you
# need to pass the batch flag to indicate its not interactive.
- "--batch"
- "--local-user"
- "{{ .Env.GPG_FINGERPRINT }}" # set this environment variable for your signing key
- "--output"
- "${signature}"
- "--detach-sign"
- "${artifact}"
release:
extra_files:
- glob: 'terraform-registry-manifest.json'
name_template: '{{ .ProjectName }}_{{ .Version }}_manifest.json'
# If you want to manually examine the release before its live, uncomment this line:
# draft: true
changelog:
skip: true
skip: true
110 changes: 20 additions & 90 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,98 +1,28 @@
# ENVS
ifeq ($(OS),Windows_NT)
PROJECT_DIR = $(shell cd)
OS := windows
ifeq ($(PROCESSOR_ARCHITECTURE),AMD64)
ARCH := amd64
endif
ifeq ($(PROCESSOR_ARCHITECTURE),x86)
ARCH := 386
endif
else
PROJECT_DIR = $(shell pwd)
OS := $(shell uname | tr '[:upper:]' '[:lower:]')
ARCH := $(shell uname -m)
endif
BIN_DIR = $(PROJECT_DIR)/bin
TEST_DIR = $(PROJECT_DIR)/edgecenter/test
ENV_TESTS_FILE = $(TEST_DIR)/.env
PROJECT_DIR=$(shell pwd)
BIN_DIR=$(PROJECT_DIR)/bin

# BINARY
BINARY_NAME = terraform-provider-edgecenter
TAG_PREFIX = "v"
TAG = $(shell git describe --tags)
VERSION = $(shell git describe --tags $(LAST_TAG_COMMIT) | sed "s/^$(TAG_PREFIX)//")
PLUGIN_PATH = ~/.terraform.d/plugins/local.edgecenter.ru/repo/edgecenter/$(VERSION)/$(OS)_$(ARCH)

tidy:
go mod tidy

# BUILD
build: tidy
BINARY_NAME=terraform-provider-edgecenter
TAG_PREFIX="v"
TAG=$(shell git describe --tags)
VERSION=$(shell git describe --tags $(LAST_TAG_COMMIT) | sed "s/^$(TAG_PREFIX)//")
PLUGIN_PATH=~/.terraform.d/plugins/local.edgecenter.ru/repo/edgecenter/$(VERSION)/$(OS)_$(ARCH)

.PHONY: build
build: fmtcheck
mkdir -p $(PLUGIN_PATH)
go build -o $(PLUGIN_PATH)/$(BINARY_NAME)_v$(VERSION)
go build -o bin/$(BINARY_NAME)

build_debug: tidy
mkdir -p $(PLUGIN_PATH)
go build -o $(PLUGIN_PATH)/$(BINARY_NAME)_v$(VERSION) -gcflags '-N -l'
go build -o bin/$(BINARY_NAME) -gcflags '-N -l'

# CHECKS
err_check:
@sh -c "'$(PROJECT_DIR)/scripts/errcheck.sh'"

linters:
@test -f $(BIN_DIR)/golangci-lint || curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s v1.54.2
@$(BIN_DIR)/golangci-lint run

linters_docker: # for windows
docker run --rm -v $(PROJECT_DIR):/app -w /app golangci/golangci-lint:v1.54.2 golangci-lint run -v

# TESTS
envs_reader:
go install github.com/joho/godotenv/cmd/godotenv@latest

test_cloud_data_source: envs_reader
godotenv -f $(ENV_TESTS_FILE) go test $(TEST_DIR) -tags cloud_data_source -short -timeout=20m

test_cloud_resource: envs_reader
godotenv -f $(ENV_TESTS_FILE) go test $(TEST_DIR) -tags cloud_resource -short -timeout=20m

test_not_cloud: envs_reader
godotenv -f $(ENV_TESTS_FILE) go test $(TEST_DIR) -tags dns storage cdn -v -timeout=5m

# local test run (need to export VAULT_TOKEN env)
install_jq:
if test "$(OS)" = "linux"; then \
curl -L -o $(BIN_DIR)/jq https://github.com/stedolan/jq/releases/download/jq-1.6/jq-linux64; \
else \
curl -L -o $(BIN_DIR)/jq https://github.com/stedolan/jq/releases/download/jq-1.6/jq-osx-amd64; \
fi
chmod +x $(BIN_DIR)/jq

install_vault:
curl -L -o vault.zip https://releases.hashicorp.com/vault/1.13.3/vault_1.13.3_$(OS)_$(ARCH).zip
unzip vault.zip && rm -f vault.zip && chmod +x vault
mv vault $(BIN_DIR)/

download_env_file: envs_reader
godotenv -f $(ENV_TESTS_FILE) $(BIN_DIR)/vault login -method=token $(VAULT_TOKEN)
godotenv -f $(ENV_TESTS_FILE) $(BIN_DIR)/vault kv get -format=json --field data /CLOUD/terraform | $(BIN_DIR)/jq -r 'to_entries|map("\(.key)=\(.value)")|.[]' >> $(ENV_TESTS_FILE)

test_local_data_source: envs_reader
godotenv -f .local.env go test $(TEST_DIR) -tags cloud_data_source -short -timeout=5m -v

test_local_resource: envs_reader
godotenv -f .local.env go test $(TEST_DIR) -tags cloud_resource -short -timeout=10m -v

# DOCS
docs_fmt:
terraform fmt -recursive ./examples/
.PHONY: lint
lint:
@go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
@golangci-lint run -v ./...

docs: docs_fmt
go get github.com/hashicorp/terraform-plugin-docs/cmd/[email protected]
make tidy
tfplugindocs --tf-version=1.5.0 --provider-name=edgecenter
.PHONY: test
test:
go test -v -timeout=2m

.PHONY: tidy build build_debug err_check linters linters_docker envs_reader test_cloud_data_source test_cloud_resource test_not_cloud install_jq install_vault download_env_file test_local_data_source test_local_resource docs_fmt docs
.PHONY: fmtcheck
fmtcheck:
@sh -c "'$(PROJECT_DIR)/scripts/gofmtcheck.sh'"
Loading

0 comments on commit 810e156

Please sign in to comment.