Skip to content

Commit

Permalink
Improve (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
yoanm authored Nov 6, 2022
1 parent 256d6ab commit d7e8cc8
Show file tree
Hide file tree
Showing 17 changed files with 146 additions and 27 deletions.
16 changes: 16 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
root = true

[*]
end_of_line = lf
insert_final_newline = true
charset = utf-8
indent_style = space
indent_size = 4

[Makefile]
indent_style = tab
indent_size = 8

[{*.yml,*.yaml}]
indent_style = space
indent_size = 2
3 changes: 3 additions & 0 deletions .github/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[*.yml]
indent_style = space
indent_size = 2
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* @yoanm
6 changes: 6 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
version: 2
updates:
- package-ecosystem: gomod
directory: /
schedule:
interval: monthly
32 changes: 18 additions & 14 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,21 @@ jobs:
cache-dependency-path: ./go.sum

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

- name: Run tests
run: go test -race -covermode=atomic -coverprofile=coverage.out ./...
run: make test-go gotest_o="-race -covermode=atomic -coverprofile=coverage.out"

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3

- name: Upload coverage to Codacy
uses: codacy/codacy-coverage-reporter-action@v1
with:
project-token: ${{ secrets.CODACY_PROJECT_TOKEN }}
coverage-reports: coverage.out
force-coverage-parser: go

static:
name: Static checks
runs-on: ubuntu-latest
Expand All @@ -49,19 +56,16 @@ jobs:
cache-dependency-path: ./go.sum

- name: Verify dependencies
run: go mod verify

- name: Run go vet
run: go vet ./...
run: make verify

- name: Install staticcheck
run: go install honnef.co/go/tools/cmd/staticcheck@latest
- name: Go vet
run: make test-vet

- name: Run staticcheck
run: staticcheck ./...
- name: Install test libs
run: make configure-test-env

- name: Install golint
run: go install golang.org/x/lint/golint@latest
- name: Staticcheck
run: make test-staticcheck

- name: Run golint
run: golint -set_exit_status ./...
- name: Lint
run: make test-lint lint_o="-set_exit_status"
69 changes: 69 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# Based on that awesome makefile https://github.com/dunglas/symfony-docker/blob/main/docs/makefile.md#the-template

.DEFAULT_GOAL = default

.PHONY: default
default: build

##—— 📚 Help ——————————————————————————————————————————————————————————————
.PHONY: help
help: ## ❓ Dislay this help
@grep -E '(^[a-zA-Z0-9_-]+:.*?##.*$$)|(^##)' $(MAKEFILE_LIST) \
| awk 'BEGIN {FS = ":.*?## "}{printf "\033[32m%-30s\033[0m %s\n", $$1, $$2}' \
| sed -e 's/\[32m##——————————/[33m /' \
| sed -e 's/\[32m##——/[33m ——/' \
| sed -e 's/\[32m####/[34m /' \
| sed -e 's/\[32m###/[36m /' \
| sed -e 's/\[32m##\?/[35m /' \
| sed -e 's/\[32m##/[33m/'

##—— ️⚙️ Environments ——————————————————————————————————————————————————————
.PHONY: configure-test-env
configure-test-env: ## 🤖 Install required libraries for test environment (golint, staticcheck, etc)
configure-test-env:
go install golang.org/x/lint/golint@latest
go install honnef.co/go/tools/cmd/staticcheck@latest


##—— 🐹 Golang —————————————————————————————————————————————————
.PHONY: build
build: ## 🗜️ Build package
#### Use build_o="..." to specify build options
$(eval build_o ?=)
build:
go build -v $(build_o)

.PHONY: verify
verify: ## 🗜️ Verify dependencies
verify:
go mod verify


##—— 🧪️ Tests —————————————————————————————————————————————————————————————
.PHONY: test
test: ## 🏃 Launch all tests
test: test-vet test-lint test-staticcheck test-go

test-go: ## 🏃 Launch go test
#### Use gotest_o="..." to specify options
$(eval gotest_o ?=)
test-go:
go test -v $(gotest_o) ./...

test-vet: ## 🏃 Launch go vet
#### Use vet_o="..." to specify options
$(eval vet_o ?=)
test-vet:
go vet $(vet_o) ./...

test-lint: ## 🏃 Launch go lint
#### Use lint_o="..." to specify options (-set_exit_status for instance)
$(eval lint_o ?=)
test-lint:
golint $(lint_o) ./...

test-staticcheck: ## 🏃 Launch staticcheck
#### Use staticcheck_o="..." to specify options
$(eval staticcheck_o ?=)
test-staticcheck:
staticcheck $(staticcheck_o) ./...
14 changes: 11 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
# go-tfsig
# go-tfsig - hclwrite wrapper

[![License](https://img.shields.io/github/license/yoanm/go-tfsig.svg)](https://github.com/yoanm/go-tfsig)
[![Code size](https://img.shields.io/github/languages/code-size/yoanm/go-tfsig.svg)](https://github.com/yoanm/go-tfsig)
[![Dependabot Status](https://api.dependabot.com/badges/status?host=github\&repo=yoanm/go-tfsig)](https://dependabot.com)
[![Go Reference](https://pkg.go.dev/badge/github.com/yoanm/go-tfsig.svg)](https://pkg.go.dev/github.com/yoanm/go-tfsig)

![Dependabot Status](https://flat.badgen.net/github/dependabot/yoanm/go-tfsig)
![Last commit](https://badgen.net/github/last-commit/yoanm/go-tfsig)

[![Scrutinizer Build Status](https://img.shields.io/scrutinizer/build/g/yoanm/go-tfsig.svg?label=Scrutinizer\&logo=scrutinizer)](https://scrutinizer-ci.com/g/yoanm/go-tfsig/build-status/master)
[![Scrutinizer Code Quality](https://img.shields.io/scrutinizer/g/yoanm/go-tfsig/master.svg?logo=scrutinizer)](https://scrutinizer-ci.com/g/yoanm/go-tfsig/?branch=master)
[![Codacy Badge](https://app.codacy.com/project/badge/Grade/e1ceed2c5fa24691b3735a7c4b7a73a0)](https://www.codacy.com/gh/yoanm/go-tfsig/dashboard?utm_source=github.com&utm_medium=referral&utm_content=yoanm/go-tfsig&utm_campaign=Badge_Grade)
[![Go Report Card](https://goreportcard.com/badge/github.com/yoanm/go-tfsig?)](https://goreportcard.com/report/github.com/yoanm/go-tfsig)

[![CI](https://github.com/yoanm/go-tfsig/actions/workflows/CI.yml/badge.svg?branch=master)](https://github.com/yoanm/go-tfsig/actions/workflows/CI.yml)
[![codecov](https://codecov.io/gh/yoanm/go-tfsig/branch/master/graph/badge.svg?token=NHdwEBUFK5)](https://codecov.io/gh/yoanm/go-tfsig)

![GitHub go.mod Go version](https://img.shields.io/github/go-mod/go-version/yoanm/go-tfsig)
![GitHub go.mod Go version](https://img.shields.io/github/go-mod/go-version/yoanm/go-tfsig)

Wrapper for Terraform HCL language (hclwrite)

Generate block **signatures** which are easier to manipulate and alter than hclwrite tokens
2 changes: 1 addition & 1 deletion block_signature.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"github.com/hashicorp/hcl/v2/hclwrite"
"github.com/zclconf/go-cty/cty"

"github.com/yoanm/tfsig/tokens"
"github.com/yoanm/go-tfsig/tokens"
)

/** Public **/
Expand Down
4 changes: 2 additions & 2 deletions block_signature_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
"github.com/zclconf/go-cty/cty"
"github.com/zclconf/go-cty/cty/gocty"

"github.com/yoanm/tfsig/testutils"
"github.com/yoanm/tfsig/tokens"
"github.com/yoanm/go-tfsig/testutils"
"github.com/yoanm/go-tfsig/tokens"
)

func TestNewEmptyResource(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion body_element_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (

"github.com/zclconf/go-cty/cty"

"github.com/yoanm/tfsig/testutils"
"github.com/yoanm/go-tfsig/testutils"
)

func TestBodyBlockBuild_panic(t *testing.T) {
Expand Down
12 changes: 12 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
coverage:
range: "80...100"

flags:
nightly:
joined: false

comment:
show_carryforward_flags: true

github_checks:
annotations: true
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module github.com/yoanm/tfsig
module github.com/yoanm/go-tfsig

go 1.18

Expand Down
2 changes: 1 addition & 1 deletion tokens/generator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"github.com/zclconf/go-cty/cty"
"github.com/zclconf/go-cty/cty/gocty"

"github.com/yoanm/tfsig/testutils"
"github.com/yoanm/go-tfsig/testutils"
)

func TestGenerate(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion tokens/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (

"github.com/zclconf/go-cty/cty"

"github.com/yoanm/tfsig/testutils"
"github.com/yoanm/go-tfsig/testutils"
)

func TestFromValue_panic(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (

"github.com/hashicorp/hcl/v2/hclwrite"

"github.com/yoanm/tfsig/testutils"
"github.com/yoanm/go-tfsig/testutils"
)

func TestAppendNewLineAndBlockIfNotNil(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion value_generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

"github.com/zclconf/go-cty/cty"

"github.com/yoanm/tfsig/tokens"
"github.com/yoanm/go-tfsig/tokens"
)

type ValueGenerator struct {
Expand Down
2 changes: 1 addition & 1 deletion value_generator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

"github.com/zclconf/go-cty/cty"

"github.com/yoanm/tfsig/testutils"
"github.com/yoanm/go-tfsig/testutils"
)

func TestNewValueGenerator(t *testing.T) {
Expand Down

0 comments on commit d7e8cc8

Please sign in to comment.