Skip to content

Commit c64f0e5

Browse files
authored
Merge pull request #21 from mdb/housekeeping
NOOP: misc housekeeping and cleanup
2 parents 749cb1b + c81251e commit c64f0e5

File tree

6 files changed

+56
-45
lines changed

6 files changed

+56
-45
lines changed

.github/workflows/main.yml

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
---
12
name: CI/CD
23

34
on: [push, pull_request]
@@ -6,15 +7,15 @@ jobs:
67
build-snapshot:
78
runs-on: ubuntu-latest
89
steps:
9-
- uses: actions/checkout@v3
10-
- name: Set up Go
11-
uses: actions/setup-go@v3
12-
with:
13-
go-version-file: go.mod
14-
- name: Build
15-
run: make
16-
- name: Ensure unique version
17-
run: make check-tag
10+
- uses: actions/checkout@v3
11+
- name: Set up Go
12+
uses: actions/setup-go@v3
13+
with:
14+
go-version-file: go.mod
15+
- name: Build
16+
run: make
17+
- name: Ensure unique version
18+
run: make check-tag
1819

1920
build-and-publish-release:
2021
if: github.ref == 'refs/heads/main'

.goreleaser.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
---
12
project_name: terraputs
23
before:
34
hooks:

Makefile

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,11 @@
1-
VERSION = 0.1.6
1+
VERSION = 0.1.7
22
SOURCE = ./...
33

4-
.PHONY: help \
5-
build \
6-
vet \
7-
test-fmt \
8-
test \
9-
testdata \
10-
clean
11-
124
.DEFAULT_GOAL := build
135

146
help:
157
# build: build terraputs (default make target)
16-
# tools: install build dependencies cited in tools.go
8+
# tools: install build dependencies cited in tools.go
179
# vet: run 'go vet' against source code
1810
# test-fmt: validate that source code is formatted correctly
1911
# test: run automated tests
@@ -22,25 +14,31 @@ help:
2214
# tag: create a $(VERSION) git tag
2315
# release: build and publish a terraputs GitHub release
2416
# clean: remove testdata fixtures and compiled artifacts
17+
.PHONY: help
2518

2619
tools:
2720
echo "Installing tools from tools.go"
2821
cat tools.go | grep _ | awk -F'"' '{print $$2}' | xargs -tI % go install %
22+
.PHONY: tools
2923

3024
build: tools
3125
goreleaser release \
3226
--snapshot \
3327
--skip-publish \
3428
--rm-dist
29+
.PHONY: build
3530

3631
vet:
3732
go vet $(SOURCE)
33+
.PHONY: vet
3834

3935
test-fmt:
4036
test -z $(shell go fmt $(SOURCE))
37+
.PHONY: test-fmt
4138

4239
test: vet test-fmt
4340
go test -cover $(SOURCE) -count=1
41+
.PHONY: test
4442

4543
define generate-testdata
4644
docker run \
@@ -62,25 +60,30 @@ testdata:
6260
$(call generate-testdata,emptyconfig,1.0.5)
6361
$(call generate-testdata,emptyconfig-1.1.5,1.1.5)
6462
$(call generate-testdata,basic-1.1.5,1.1.5)
63+
.PHONY: testdata
6564

6665
check-tag:
6766
./scripts/ensure_unique_version.sh "$(VERSION)"
67+
.PHONY: check-tag
6868

6969
tag: check-tag
7070
@echo "creating git tag $(VERSION)"
7171
@git tag $(VERSION)
7272
@git push origin $(VERSION)
73+
.PHONY: tag
7374

7475
release: tools
7576
goreleaser release \
7677
--rm-dist
78+
.PHONY: release
7779

7880
demo:
7981
svg-term \
8082
--cast 423523 \
8183
--out demo.svg \
8284
--window \
8385
--no-cursor
86+
.PHONY: demo
8487

8588
define clean-testdata
8689
rm -rf testdata/$(1)/.terraform*
@@ -93,3 +96,4 @@ clean:
9396
$(call clean-testdata,nooutputs)
9497
$(call clean-testdata,emptyconfig)
9598
rm -rf dist
99+
.PHONY: clean

main.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ var (
2727
const (
2828
stateDesc string = "Optional; the state JSON output by 'terraform show -json'. Read from stdin if omitted"
2929
stateFileDesc string = "Optional; the path to a local file containing 'terraform show -json' output"
30-
headingDesc string = "Optional; the heading text for use in the printed output."
31-
outputDesc string = "Optional; the output format. Supported values: md, html."
32-
descriptionDesc string = "Optional; a contextual description preceding the outputs."
30+
headingDesc string = "Optional; the heading text for use in the printed output"
31+
outputDesc string = "Optional; the output format. Supported values: md, html"
32+
descriptionDesc string = "Optional; a contextual description preceding the outputs"
3333
versionDesc string = "Print the current version and exit"
3434
defaultHeading string = "Outputs"
3535
defaultDescription string = "Terraform state outputs."

main_test.go

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212

1313
const (
1414
testVersion string = "test"
15+
testExecutable string = "terraputs-test"
1516
expectedEmptyOutput string = `## foo
1617
1718
Terraform state outputs.
@@ -23,8 +24,8 @@ Terraform state outputs.
2324
)
2425

2526
func TestMain(m *testing.M) {
26-
// compile an 'terraputs' for for use in running tests
27-
exe := exec.Command("go", "build", "-ldflags", fmt.Sprintf("-X main.version=%s", testVersion), "-o", "terraputs")
27+
// compile a 'terraputs' for use in running tests
28+
exe := exec.Command("go", "build", "-ldflags", fmt.Sprintf("-X main.version=%s", testVersion), "-o", testExecutable)
2829
err := exe.Run()
2930
if err != nil {
3031
os.Exit(1)
@@ -33,7 +34,7 @@ func TestMain(m *testing.M) {
3334
m.Run()
3435

3536
// delete the compiled terraputs
36-
err = os.Remove("terraputs")
37+
err = os.Remove(testExecutable)
3738
if err != nil {
3839
log.Fatal(err)
3940
}
@@ -64,7 +65,7 @@ func TestHelpFlag(t *testing.T) {
6465

6566
for _, test := range tests {
6667
t.Run(fmt.Sprintf("when terraputs is passed '%s'", test.arg), func(t *testing.T) {
67-
output, err := exec.Command("./terraputs", test.arg).CombinedOutput()
68+
output, err := exec.Command(fmt.Sprintf("./%s", testExecutable), test.arg).CombinedOutput()
6869

6970
if err != nil {
7071
t.Errorf("expected '%s' not to error; got '%v'", test.arg, err)
@@ -89,7 +90,7 @@ func TestVersionArg(t *testing.T) {
8990

9091
for _, arg := range args {
9192
t.Run(fmt.Sprintf("when terraputs is passed '%s'", arg), func(t *testing.T) {
92-
output, err := exec.Command("./terraputs", arg).CombinedOutput()
93+
output, err := exec.Command(fmt.Sprintf("./%s", testExecutable), arg).CombinedOutput()
9394

9495
if err != nil {
9596
t.Errorf("expected '%s' not to cause error; got '%v'", arg, err)
@@ -108,63 +109,67 @@ func TestVersionArg(t *testing.T) {
108109
// terraputs < stateFile
109110
// cat stateFile | terraputs
110111
func TestTerraputs(t *testing.T) {
112+
command := func(cmd string) string {
113+
return fmt.Sprintf("./%s ", testExecutable) + cmd
114+
}
115+
111116
tests := []struct {
112117
command string
113118
expectedError error
114119
expectedOutput string
115120
}{{
116-
command: `./terraputs -state $(cat testdata/basic/show.json)`,
121+
command: command("-state $(cat testdata/basic/show.json)"),
117122
expectedOutput: expectedOutput("Outputs"),
118123
}, {
119-
command: `./terraputs < testdata/basic/show.json`,
124+
command: command("< testdata/basic/show.json"),
120125
expectedOutput: expectedOutput("Outputs"),
121126
}, {
122-
command: `cat testdata/basic/show.json | ./terraputs`,
127+
command: fmt.Sprintf("cat testdata/basic/show.json | ./%s", testExecutable),
123128
expectedOutput: expectedOutput("Outputs"),
124129
}, {
125-
command: `./terraputs -state $(cat testdata/basic/show.json) -heading foo`,
130+
command: command("-state $(cat testdata/basic/show.json) -heading foo"),
126131
expectedOutput: expectedOutput("foo"),
127132
}, {
128-
command: `./terraputs -state $(cat testdata/basic/show.json) -description "A custom description."`,
133+
command: command(`-state $(cat testdata/basic/show.json) -description "A custom description."`),
129134
expectedOutput: strings.Replace(expectedOutput("Outputs"), "Terraform state outputs", "A custom description", 1),
130135
}, {
131-
command: `./terraputs -state $(cat testdata/nooutputs/show.json) -heading foo`,
136+
command: command("-state $(cat testdata/nooutputs/show.json) -heading foo"),
132137
expectedOutput: expectedEmptyOutput,
133138
}, {
134-
command: `./terraputs -state $(cat testdata/emptyconfig/show.json) -heading foo`,
139+
command: command("-state $(cat testdata/emptyconfig/show.json) -heading foo"),
135140
expectedOutput: expectedEmptyOutput,
136141
}, {
137-
command: `./terraputs -state-file testdata/basic/show.json -heading foo`,
142+
command: command("-state-file testdata/basic/show.json -heading foo"),
138143
expectedOutput: expectedOutput("foo"),
139144
}, {
140-
command: `./terraputs -state-file testdata/basic/show.json -heading foo -output html`,
145+
command: command("-state-file testdata/basic/show.json -heading foo -output html"),
141146
expectedOutput: expectedHTMLOutput("foo"),
142147
}, {
143-
command: `./terraputs -state-file testdata/basic/show.json -description "A custom description." -output html`,
148+
command: command(`-state-file testdata/basic/show.json -description "A custom description." -output html`),
144149
expectedOutput: strings.Replace(expectedHTMLOutput("Outputs"), "Terraform state outputs", "A custom description", 1),
145150
}, {
146-
command: `./terraputs -state-file testdata/nooutputs/show.json -heading foo`,
151+
command: command("-state-file testdata/nooutputs/show.json -heading foo"),
147152
expectedOutput: expectedEmptyOutput,
148153
}, {
149-
command: `./terraputs -state-file testdata/emptyconfig/show.json -heading foo`,
154+
command: command("-state-file testdata/emptyconfig/show.json -heading foo"),
150155
expectedOutput: expectedEmptyOutput,
151156
}, {
152-
command: `./terraputs -state-file testdata/basic/i-do-not-exist.json -heading foo`,
157+
command: command("-state-file testdata/basic/i-do-not-exist.json -heading foo"),
153158
expectedError: errors.New("exit status 1"),
154159
expectedOutput: "open testdata/basic/i-do-not-exist.json: no such file or directory",
155160
}, {
156-
command: `./terraputs -state $(cat testdata/basic/show.json) -state-file testdata/basic/show.json -heading foo`,
161+
command: command("-state $(cat testdata/basic/show.json) -state-file testdata/basic/show.json -heading foo"),
157162
expectedError: errors.New("exit status 1"),
158163
expectedOutput: "'-state' and '-state-file' are mutually exclusive; specify just one",
159164
}, {
160-
command: `./terraputs -state $(cat testdata/basic/show.json) -output foo`,
165+
command: command("-state $(cat testdata/basic/show.json) -output foo"),
161166
expectedError: errors.New("exit status 1"),
162167
expectedOutput: "'foo' is not a supported output format. Supported formats: 'md' (default), 'html'",
163168
}, {
164-
command: `./terraputs -state-file testdata/emptyconfig-1.1.5/show.json -heading foo`,
169+
command: command("-state-file testdata/emptyconfig-1.1.5/show.json -heading foo"),
165170
expectedOutput: expectedEmptyOutput,
166171
}, {
167-
command: `./terraputs -state $(cat testdata/basic-1.1.5/show.json)`,
172+
command: command("-state $(cat testdata/basic-1.1.5/show.json)"),
168173
expectedOutput: expectedOutput("Outputs"),
169174
}}
170175

scripts/ensure_unique_version.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ repo="mdb/terraputs"
66
result="$(curl \
77
--header "Accept: application/vnd.github.v3+json" \
88
--write "%{http_code}" \
9-
--out "/dev/null" \
9+
--output "/dev/null" \
1010
"https://api.github.com/repos/${repo}/releases/tags/${version}")"
1111

1212
if [ "${result}" = "404" ]; then

0 commit comments

Comments
 (0)