-
Notifications
You must be signed in to change notification settings - Fork 0
/
Taskfile.yaml
183 lines (162 loc) · 5.61 KB
/
Taskfile.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
version: '3'
dotenv: ['.env']
env:
LOCAL_CONFIG_YAML: "config.yaml"
LOCAL_DIR: "local"
OPSLEVEL_GO_PKG: "github.com/opslevel/opslevel-go/v2024"
SRC_DIR: "{{.TASKFILE_DIR}}"
tasks:
ci:
desc: Workflow to run in CI
deps:
- install-nilaway
- install-gofumpt
- install-golangci-lint
cmds:
- task: workspace
- task: has-latest-opslevel-go
- which jq > /dev/null
- task: lint
- task: test
lint:
desc: Formatting and linting
dir: "{{.SRC_DIR}}"
cmds:
- test -z "$(gofumpt -d -e . | tee /dev/stderr)"
- golangci-lint run
- nilaway -test=false ./...
fix:
desc: Fix formatting, linting, go.mod, and update submodule
dir: "{{.SRC_DIR}}"
cmds:
- task: update-opslevel-go
- gofumpt -w .
- go get -u
- go mod tidy
- golangci-lint run --fix
- nilaway -fix -test=false -include-pkgs='github.com/opslevel/opslevel-jq-parser' ./...
parse:
desc: Locally parse config YAML files. Optionally pass in config with 'task parse -- myconfig.yaml'
dir: "{{.LOCAL_DIR}}"
cmds:
- '[[ -s {{.LOCAL_CONFIG_YAML}} ]] || cp {{.ROOT_DIR}}/testdata/sample_config.yaml {{.LOCAL_CONFIG_YAML}}'
- >
if [[ {{.CLI_ARGS | default "config.yaml" }} != {{.LOCAL_CONFIG_YAML}} ]]; then
echo "Copying {{.ROOT_DIR}}/{{.CLI_ARGS}} to {{.LOCAL_DIR}}/{{.LOCAL_CONFIG_YAML}} for local testing..."
cp {{.ROOT_DIR}}/{{.CLI_ARGS}} {{.LOCAL_CONFIG_YAML}}
fi
- go run parse.go
setup:
desc: Setup linter, formatter, etc. for local testing and CI
cmds:
- cmd: echo "Installing development tools..."
silent: true
- task: brew-install-jq
- task: install-changie
- task: install-nilaway
- task: install-gofumpt
- task: install-golangci-lint
- cmd: echo "Development tools installed!"
silent: true
- task: workspace
test:
desc: Run tests
dir: "{{.SRC_DIR}}"
cmds:
- go test -race -coverprofile=coverage.txt -covermode=atomic -v ./... {{ .CLI_ARGS }}
workspace:
desc: Setup workspace for opslevel-jq-parser & opslevel-go development
dir: "{{.SRC_DIR}}"
cmds:
- cmd: echo "Setting up opslevel-go workspace..."
silent: true
- git submodule update --init --remote
- go work init || true
- go work use . submodules/opslevel-go
- cmd: echo "opslevel-go workspace ready!"
silent: true
# internal (not directly called) tasks
brew-install-jq:
internal: true
platforms: [darwin]
cmds: ["which jq > /dev/null || brew install jq"]
preconditions:
- sh: 'which brew'
msg: '"brew" needed to install "jq"- see https://brew.sh'
go-install-tool:
desc: go install '{{.GO_TOOL}}' and set GOBIN if not set
internal: true
silent: true
vars:
IS_TOOL_INSTALLED:
sh: which {{.GO_TOOL}} > /dev/null || echo "1"
cmds:
- test -z "{{.IS_TOOL_INSTALLED}}" || echo "Installing {{.GO_TOOL}}..."
- test -z "{{.IS_TOOL_INSTALLED}}" || go install {{.GO_TOOL_PATH}}
- test -n $(go env GOBIN) || go env -w GOBIN=$(go env GOPATH)/bin
- echo " '{{.GO_TOOL}}' is installed."
requires:
vars: [GO_TOOL, GO_TOOL_PATH]
has-latest-opslevel-go:
desc: Check if latest release of opslevel-go in go.mod
dir: "{{.SRC_DIR}}"
silent: true
vars:
GO_WORK: "go.work"
TMP_GO_WORK: "tmp_go.work"
LATEST_OPSLEVEL_GO_VERSION:
sh: go list -u -m -versions github.com/opslevel/opslevel-go/v2024 | awk '{print $NF}'
cmds:
- if [[ -f {{.GO_WORK}} ]]; then mv {{.GO_WORK}} {{.TMP_GO_WORK}}; fi
- defer: if [[ -f {{.TMP_GO_WORK}} ]]; then mv {{.TMP_GO_WORK}} {{.GO_WORK}}; fi
- |-
if [[ {{.LATEST_OPSLEVEL_GO_VERSION}} == $(go list -m --json '{{.OPSLEVEL_GO_PKG}}' | jq -r '.Version') ]]; then
echo "Using latest version of opslevel-go - {{.LATEST_OPSLEVEL_GO_VERSION}}";
else
echo "WARNING: current version of opslevel-go is behind '{{.LATEST_OPSLEVEL_GO_VERSION}}'"
echo "Run 'task lintfix' to get latest version"
exit 1
fi
install-changie:
desc: go install "changie"
internal: true
cmds:
- task: go-install-tool
vars: { GO_TOOL: "changie", GO_TOOL_PATH: "github.com/miniscruff/changie@latest" }
install-nilaway:
desc: go install "nilaway"
internal: true
cmds:
- task: go-install-tool
vars: { GO_TOOL: "nilaway", GO_TOOL_PATH: "go.uber.org/nilaway/cmd/nilaway@latest" }
install-gofumpt:
desc: go install "gofumpt"
internal: true
cmds:
- task: go-install-tool
vars: { GO_TOOL: "gofumpt", GO_TOOL_PATH: "mvdan.cc/gofumpt@latest" }
install-golangci-lint:
desc: go install "golangci-lint"
internal: true
cmds:
- task: go-install-tool
vars: { GO_TOOL: "golangci-lint", GO_TOOL_PATH: "github.com/golangci/golangci-lint/cmd/golangci-lint@latest" }
install-go-tool:
desc: go install '{{.GO_TOOL}}' and set GOBIN if not set
internal: true
silent: true
vars:
IS_TOOL_INSTALLED:
sh: which {{.GO_TOOL}} > /dev/null || echo "1"
cmds:
- test -z "{{.IS_TOOL_INSTALLED}}" || echo "Installing {{.GO_TOOL}}..."
- test -z "{{.IS_TOOL_INSTALLED}}" || go install {{.GO_TOOL_PATH}}
- test -n $(go env GOBIN) || go env -w GOBIN=$(go env GOPATH)/bin
- echo " '{{.GO_TOOL}}' is installed."
requires:
vars: [GO_TOOL, GO_TOOL_PATH]
update-opslevel-go:
desc: Update opslevel-go version to latest release
dir: "{{.SRC_DIR}}"
cmds:
- go get -u "{{.OPSLEVEL_GO_PKG}}"