Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert CLOUDDEV-354 from main #37

Merged
merged 1 commit into from
Dec 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
28 changes: 19 additions & 9 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,24 +1,34 @@
name: build

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

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

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

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

- name: Tests
run: make test
- 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
49 changes: 49 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# This GitHub action can publish assets for release when a tag is created.
# Currently its setup to run on any tag that matches the pattern "v*" (ie. v0.1.0).
#
# This uses an action (hashicorp/ghaction-import-gpg) that assumes you set your
# private key in the `GPG_PRIVATE_KEY` secret and passphrase in the `PASSPHRASE`
# secret. If you would rather own your own GPG handling, please fork this action
# or use an alternative one for key handling.
#
# You will need to pass the `--batch` flag to `gpg` in your signing step
# in `goreleaser` to indicate this is being used in a non-interactive mode.
#
name: release
on:
push:
tags:
- 'v*'
jobs:
goreleaser:
runs-on: ubuntu-latest
steps:
-
name: Checkout
uses: actions/checkout@v3
-
name: Unshallow
run: git fetch --prune --unshallow
-
name: Set up Go
uses: actions/setup-go@v3
with:
go-version: 1.20.2
-
name: Import GPG key
id: import_gpg
uses: crazy-max/ghaction-import-gpg@v5
with:
# These secrets will need to be configured for the repository:
gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }}
passphrase: ${{ secrets.PASSPHRASE }}
-
name: Run GoReleaser
uses: goreleaser/goreleaser-action@v4
with:
version: latest
args: release --rm-dist
env:
GPG_FINGERPRINT: ${{ steps.import_gpg.outputs.fingerprint }}
# # GitHub sets this automatically
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
58 changes: 35 additions & 23 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,32 @@
run:
timeout: 10m
go: "1.21.3"
go: "1.20"

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: (.+)_test.go
- path: \.go
linters:
- funlen
- nolintlint
text: should be written without leading space
- text: lifecyclepolicy.CreateScheduleOpts
linters:
- ireturn
- path: utils|_test
linters:
- wrapcheck

linters:
enable-all: true
disable:
# deprecated
- deadcode
- maligned
- varcheck
Expand All @@ -27,38 +40,37 @@ linters:
- rowserrcheck
- sqlclosecheck
- wastedassign
# skip: dubious benefit
- gochecknoglobals # Checks that no global variables exist.
- exhaustruct # Checks if all structure fields are initialized.
- lll # Reports long lines.
# 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
- 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
- goerr113 # Golang linter to check the errors handling expressions
# complexity: need to refactor
- cyclop
- funlen
- gocognit
- gocyclo
- maintidx
- nestif
# tests
- testpackage # Makes you use a separate _test package.
- paralleltest # Detects missing usage of t.Parallel() method in your Go test.
- dupl
- depguard

linters-settings:
nlreturn:
block-size: 5
block-size: 10
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
ignore: github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema:ForceNew|Set,fmt:.*,io:Close,io:WriteString
nakedret:
max-func-lines: 40
varnamelen:
min-name-length: 1
51 changes: 49 additions & 2 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,60 @@
# 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:
- skip: true
- 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 }}'
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
103 changes: 77 additions & 26 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,47 +1,98 @@
PROJECT_DIR=$(shell pwd)
GOFMT_FILES?=$$(find . -name '*.go' |grep -v vendor)
BIN_DIR=$(PROJECT_DIR)/bin
# 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

# 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)
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: tidy
tidy:
go mod tidy

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

.PHONY: lint
lint:
@go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
@golangci-lint run -v ./...
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

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

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

.PHONY: fmtcheck
fmtcheck:
@sh -c "'$(PROJECT_DIR)/scripts/gofmtcheck.sh'"
# 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
.PHONY: docs_fmt
docs_fmt:
terraform fmt -recursive ./examples/

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

.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
Loading