Skip to content

Commit

Permalink
feat: Add goreleaser
Browse files Browse the repository at this point in the history
  • Loading branch information
sylwit authored and sylvain committed Mar 4, 2023
1 parent 93ccc41 commit ba33679
Show file tree
Hide file tree
Showing 12 changed files with 109 additions and 811 deletions.
32 changes: 32 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: release

on:
push:
tags:
- '*'

permissions:
contents: write

jobs:
release:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Set up Go
uses: actions/setup-go@v3
with:
go-version-file: 'go.mod'

- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v4
with:
distribution: goreleaser
version: latest
args: release --clean
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# Binaries for programs and plugins
bin
*.exe
*.exe~
*.dll
Expand All @@ -14,3 +13,5 @@ bin

# Dependency directories (remove the comment below to include it)
# vendor/

dist/
21 changes: 21 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
builds:
- env:
- CGO_ENABLED=0
goos:
- linux
- windows
- darwin
goarch:
- amd64
- arm64

checksum:
name_template: 'checksums.txt'
snapshot:
name_template: "{{ incpatch .Version }}-next"
changelog:
sort: asc
filters:
exclude:
- '^docs:'
- '^test:'
25 changes: 25 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: check-added-large-files
- id: check-case-conflict
- id: check-merge-conflict
- id: check-yaml
args: [ --allow-multiple-documents ]
- id: detect-private-key
- id: end-of-file-fixer
- id: mixed-line-ending
- id: trailing-whitespace

- repo: https://github.com/gruntwork-io/pre-commit
rev: v0.1.18
hooks:
- id: terraform-fmt

- repo: https://github.com/compilerla/conventional-pre-commit
rev: v2.1.1
hooks:
- id: conventional-pre-commit
stages: [ commit-msg ]
args: [ ] # optional: list of Conventional Commits types to allow
6 changes: 4 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
XC_OS="linux darwin"
XC_ARCH="amd64 arm64"
XC_PARALLEL="2"
BIN="bin"
BIN="dist"
SRC=$(shell find . -name "*.go")

ifeq (, $(shell which gox))
Expand All @@ -25,6 +25,8 @@ build: install_deps
fmt:
$(info ******************** checking formatting ********************)
@test -z $(shell gofmt -l $(SRC)) || (gofmt -d $(SRC); exit 1)
terraform fmt -recursive


test: install_deps
$(info ******************** running tests ********************)
Expand All @@ -35,4 +37,4 @@ install_deps:
go get -v ./...

clean:
rm -rf $(BIN)
rm -rf $(BIN)
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
# terraform-cleaner

[![pre-commit](https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit&logoColor=white)](https://github.com/pre-commit/pre-commit)

Tiny utility which detects unused variables in your terraform modules

# Pre-commit

```shell
pre-commit install --hook-type pre-commit --hook-type commit-msg
```
2 changes: 1 addition & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
)

var rootCmd = &cobra.Command{
Use: "terraform-cleaner",
Use: "terraform-cleaner <path>",
Short: "Remove unused variables",
RunE: rootCmdExec,
}
Expand Down
6 changes: 3 additions & 3 deletions cmd/testdata/tf/main.tf
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
terraform {
required_providers {
null = {
source = "hashicorp/null"
source = "hashicorp/null"
version = "3.2.1"
}
}
}

provider "null" {
region = var.region
region = var.region
}

data "null_data_source" "values" {
Expand All @@ -20,4 +20,4 @@ resource "null_resource" "cluster" {
triggers = {
instance_ids = var.instance_ids
}
}
}
2 changes: 1 addition & 1 deletion cmd/testdata/tf/outputs.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
output "out" {
value = data.null_data_source.values.inputs
}
}
8 changes: 4 additions & 4 deletions cmd/testdata/tf/variables.tf
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
variable "name" {
type = string
type = string
default = "terraform-cleaner"
}

variable "region" {
type = string
type = string
default = "ca-central-1"
}

variable "instance_ids" {
type = list(string)
type = list(string)
default = ["i-123", "i-456"]
}

variable "legacy" {}
variable "legacy" {}
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ require (
github.com/hashicorp/hcl/v2 v2.0.0 // indirect
github.com/inconshreveable/mousetrap v1.0.1 // indirect
github.com/mitchellh/go-wordwrap v1.0.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect˚
github.com/pmezard/go-difflib v1.0.0 // indirect; indirect˚
github.com/spf13/pflag v1.0.5 // indirect
github.com/stretchr/testify v1.8.2 // indirect
github.com/stretchr/testify v1.8.2
github.com/zclconf/go-cty v1.1.0 // indirect
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f // indirect
golang.org/x/text v0.3.8 // indirect
Expand Down
Loading

0 comments on commit ba33679

Please # to comment.