-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: initial commit, includes init commands and module command
- Loading branch information
0 parents
commit c45f07b
Showing
19 changed files
with
3,143 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
name: CI | ||
on: | ||
push: | ||
branches: | ||
- '**' | ||
pull_request: | ||
branches: | ||
- '**' | ||
|
||
jobs: | ||
lint: | ||
name: Lint | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: go-with-cache | ||
uses: magnetikonline/action-golang-cache@v4 | ||
with: | ||
go-version-file: go.mod | ||
- run: make install-tools | ||
- run: make lint | ||
|
||
test: | ||
name: Test | ||
runs-on: ubuntu-latest | ||
needs: lint | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: go-with-cache | ||
uses: magnetikonline/action-golang-cache@v4 | ||
with: | ||
go-version-file: go.mod | ||
- run: make install-tools | ||
- run: make test | ||
|
||
release: | ||
name: Release | ||
runs-on: ubuntu-latest | ||
needs: test | ||
permissions: | ||
contents: write | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: go-with-cache | ||
uses: magnetikonline/action-golang-cache@v4 | ||
with: | ||
go-version-file: go.mod | ||
- run: make install-tools | ||
- uses: go-semantic-release/action@v1 | ||
with: | ||
bin: ./bin/semantic-release | ||
hooks: goreleaser | ||
allow-initial-development-versions: true | ||
args: --allow-initial-development-versions --allow-no-changes | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# If you prefer the allow list template instead of the deny list, see community template: | ||
# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore | ||
# | ||
# Binaries for programs and plugins | ||
*.exe | ||
*.exe~ | ||
*.dll | ||
*.so | ||
*.dylib | ||
|
||
# Test binary, built with `go test -c` | ||
*.test | ||
|
||
# Output of the go coverage tool, specifically when used with LiteIDE | ||
*.out | ||
|
||
# Dependency directories (remove the comment below to include it) | ||
# vendor/ | ||
|
||
# Go workspace file | ||
go.work | ||
|
||
# local binaries | ||
bin/* | ||
|
||
# idea things | ||
.idea/ | ||
|
||
# ci tools | ||
.semrel/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
linters: | ||
enable: | ||
- errorlint | ||
- forbidigo | ||
- gocritic | ||
- goconst | ||
- gocyclo | ||
- gofumpt | ||
- goimports | ||
- misspell | ||
- revive | ||
- unconvert | ||
- unparam | ||
- wastedassign | ||
|
||
linters-settings: | ||
gocyclo: | ||
min-complexity: 12 | ||
gofumpt: | ||
extra-rules: true | ||
govet: | ||
enable-all: true | ||
disable: | ||
- fieldalignment |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
builds: | ||
- env: | ||
- CGO_ENABLED=0 | ||
targets: | ||
- linux_amd64 | ||
- linux_arm64 | ||
- darwin_amd64 | ||
- darwin_arm64 | ||
- linux_arm | ||
- windows_amd64 | ||
main: ./ | ||
ldflags: | ||
- -extldflags '-static' | ||
- -s -w -X 'github.com/fitz7/tfnew/cmd.Version={{.Version}}' | ||
|
||
archives: | ||
- format: binary | ||
name_template: '{{ .Binary }}_v{{ .Version }}_{{ .Os }}_{{ .Arch }}' | ||
|
||
checksum: | ||
name_template: '{{ .ProjectName }}_v{{ .Version }}_checksums.txt' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ | ||
"plugins": { | ||
"commit-analyzer": { | ||
"name": "github:faceit/commit-analyzer-regex", | ||
"options": { | ||
"minor": "feat", | ||
"patch": "build|ci|fix|perf|refactor|test|chore" | ||
} | ||
}, | ||
"changelog-generator": { | ||
"name": "default", | ||
"options": { | ||
"emojis": "true" | ||
} | ||
}, | ||
"provider": { | ||
"name": "github", | ||
"options": { | ||
"slug": "fitz7/tfnew" | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2023 Andrew Fitzpatrick | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
export GOBIN := $(PWD)/bin | ||
export PATH := $(GOBIN):$(PATH) | ||
|
||
update-dependencies: | ||
go get -u ./... | ||
go mod tidy | ||
|
||
install-tools: | ||
@echo Installing tools from tools.go | ||
@cat tools/tools.go | grep _ | awk -F'"' '{print $$2}' | xargs -tI % go install % | ||
|
||
lint: | ||
golangci-lint run ./... --timeout 300s | ||
|
||
test: | ||
gotestsum ./... | ||
|
||
semantic-release: | ||
semantic-release |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package cmd | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
"github.com/spf13/viper" | ||
) | ||
|
||
// initCmd represents the init command | ||
var initCmd = &cobra.Command{ | ||
Use: "init", | ||
Version: rootCmd.Version, | ||
Short: "creates a config file in the repository", | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
err := viper.SafeWriteConfig() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
}, | ||
} | ||
|
||
func init() { | ||
rootCmd.AddCommand(initCmd) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package cmd | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"os" | ||
|
||
"github.com/spf13/cobra" | ||
"github.com/spf13/viper" | ||
|
||
"github.com/fitz7/tfnew/internal/tfmodule" | ||
) | ||
|
||
// moduleCmd represents the module command | ||
var moduleCmd = &cobra.Command{ | ||
Use: "module", | ||
Version: rootCmd.Version, | ||
Short: "Creates a new terraform module", | ||
Args: func(cmd *cobra.Command, args []string) error { | ||
if len(args) != 1 { | ||
return errors.New("requires a single arg containing the path of the new module") | ||
} | ||
return validatePath(args[0]) | ||
}, | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
requiredProviders, err := cmd.Flags().GetStringSlice("required_providers") | ||
if err != nil { | ||
return err | ||
} | ||
|
||
root, err := cmd.Flags().GetBool("root") | ||
if err != nil { | ||
return err | ||
} | ||
|
||
backend := viper.GetString("backend.type") | ||
|
||
createModuleOptions := tfmodule.CreateModuleOptions{ | ||
Name: args[0], | ||
RootModule: root, | ||
RequiredProviders: requiredProviders, | ||
BackendType: backend, | ||
} | ||
|
||
err = tfmodule.CreateModule(createModuleOptions) | ||
if err != nil { | ||
return err | ||
} | ||
return nil | ||
}, | ||
} | ||
|
||
func validatePath(path string) error { | ||
if _, err := os.Stat(path); os.IsNotExist(err) { | ||
return nil | ||
} | ||
|
||
return fmt.Errorf("new module directory already exists: %s", path) | ||
} | ||
|
||
func init() { | ||
rootCmd.AddCommand(moduleCmd) | ||
|
||
moduleCmd.Flags().StringSliceP("required_providers", "p", []string{}, "") | ||
|
||
moduleCmd.Flags().BoolP("root", "r", false, "") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package cmd | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
"github.com/spf13/viper" | ||
) | ||
|
||
// initCmd represents the init command | ||
var reinitCmd = &cobra.Command{ | ||
Use: "reinit", | ||
Version: rootCmd.Version, | ||
Short: "reinitialise your config file to the defaults", | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
err := viper.WriteConfig() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
}, | ||
} | ||
|
||
func init() { | ||
rootCmd.AddCommand(reinitCmd) | ||
} |
Oops, something went wrong.