| 1 |
version: "3" |
| 2 |
|
| 3 |
vars: |
| 4 |
DIST_DIR: "dist" |
| 5 |
DUMMY_DISCOVERY_VERSION: |
| 6 |
sh: echo "$(git describe --tags --dirty --broken)" |
| 7 |
DUMMY_DISCOVERY_TIMESTAMP: |
| 8 |
sh: echo "$(date -u +"%Y-%m-%dT%H:%M:%SZ")" |
| 9 |
DUMMY_DISCOVERY_LDFLAGS: > |
| 10 |
-X github.com/arduino/pluggable-discovery-protocol-handler/dummy-discovery/args.Tag={{.DUMMY_DISCOVERY_VERSION}} |
| 11 |
-X github.com/arduino/pluggable-discovery-protocol-handler/dummy-discovery/args.Timestamp={{.DUMMY_DISCOVERY_TIMESTAMP}} |
| 12 |
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/go-task/Taskfile.yml |
| 13 |
# Path of the project's primary Go module: |
| 14 |
DEFAULT_GO_MODULE_PATH: . |
| 15 |
DEFAULT_GO_PACKAGES: |
| 16 |
sh: | |
| 17 |
echo $( |
| 18 |
cd {{default .DEFAULT_GO_MODULE_PATH .GO_MODULE_PATH}} && |
| 19 |
go list ./... | tr '\n' ' ' || |
| 20 |
echo '"ERROR: Unable to discover Go packages"' |
| 21 |
) |
| 22 |
# `-ldflags` flag to use for `go build` command |
| 23 |
# TODO: define flag if required by the project, or leave empty if not needed. |
| 24 |
LDFLAGS: |
| 25 |
TEST_LDFLAGS: |
| 26 |
|
| 27 |
tasks: |
| 28 |
build-dummy-discovery: |
| 29 |
desc: Build the dummy-discovery client example |
| 30 |
vars: |
| 31 |
EXECUTABLE: dummy-discovery{{if eq OS "windows"}}.exe{{end}} |
| 32 |
cmds: |
| 33 |
- go build -o dist/{{.EXECUTABLE}} -v -ldflags '{{.DUMMY_DISCOVERY_LDFLAGS}}' ./dummy-discovery |
| 34 |
|
| 35 |
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/test-go-task/Taskfile.yml |
| 36 |
go:test: |
| 37 |
desc: | |
| 38 |
Run unit tests. |
| 39 |
Environment variable parameters: |
| 40 |
- GO_MODULE_PATH: Path of the Go module root (default: {{.DEFAULT_GO_MODULE_PATH}}). |
| 41 |
- GO_PACKAGES: List of Go packages to test (default: all packages of the module). |
| 42 |
dir: "{{default .DEFAULT_GO_MODULE_PATH .GO_MODULE_PATH}}" |
| 43 |
cmds: |
| 44 |
- | |
| 45 |
go test \ |
| 46 |
-v \ |
| 47 |
-short \ |
| 48 |
-run '{{default ".*" .GO_TEST_REGEX}}' \ |
| 49 |
{{default "-timeout 10m -coverpkg=./... -covermode=atomic" .GO_TEST_FLAGS}} \ |
| 50 |
-coverprofile=coverage_unit.txt \ |
| 51 |
{{.TEST_LDFLAGS}} \ |
| 52 |
{{default .DEFAULT_GO_PACKAGES .GO_PACKAGES}} |
| 53 |
|
| 54 |
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/npm-task/Taskfile.yml |
| 55 |
npm:install-deps: |
| 56 |
desc: | |
| 57 |
Install dependencies managed by npm. |
| 58 |
Environment variable parameters: |
| 59 |
- PROJECT_PATH: Path of the npm-managed project (default: {{.DEFAULT_NPM_PROJECT_PATH}}). |
| 60 |
run: when_changed |
| 61 |
dir: "{{default .DEFAULT_NPM_PROJECT_PATH .PROJECT_PATH}}" |
| 62 |
cmds: |
| 63 |
- npm install |
| 64 |
|
| 65 |
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-workflows-task/Taskfile.yml |
| 66 |
ci:validate: |
| 67 |
desc: Validate GitHub Actions workflows against their JSON schema |
| 68 |
vars: |
| 69 |
# Source: https://github.com/SchemaStore/schemastore/blob/master/src/schemas/json/github-workflow.json |
| 70 |
WORKFLOW_SCHEMA_URL: https://json.schemastore.org/github-workflow |
| 71 |
WORKFLOW_SCHEMA_PATH: |
| 72 |
sh: | |
| 73 |
go tool \ |
| 74 |
github.com/go-task/task/v3/cmd/task utility:mktemp-file \ |
| 75 |
TEMPLATE="workflow-schema-XXXXXXXXXX.json" |
| 76 |
WORKFLOWS_DATA_PATH: "./.github/workflows/*.{yml,yaml}" |
| 77 |
deps: |
| 78 |
- task: npm:install-deps |
| 79 |
vars: |
| 80 |
PROJECT_PATH: . |
| 81 |
cmds: |
| 82 |
- | |
| 83 |
wget \ |
| 84 |
--quiet \ |
| 85 |
--output-document="{{.WORKFLOW_SCHEMA_PATH}}" \ |
| 86 |
{{.WORKFLOW_SCHEMA_URL}} |
| 87 |
- | |
| 88 |
npx \ |
| 89 |
--package=ajv-cli \ |
| 90 |
--package=ajv-formats \ |
| 91 |
ajv validate \ |
| 92 |
--all-errors \ |
| 93 |
--strict=false \ |
| 94 |
-c ajv-formats \ |
| 95 |
-s "{{.WORKFLOW_SCHEMA_PATH}}" \ |
| 96 |
-d "{{.WORKFLOWS_DATA_PATH}}" |
| 97 |
|
| 98 |
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-go-dependencies-task/Taskfile.yml |
| 99 |
general:prepare-deps: |
| 100 |
desc: Prepare project dependencies for license check |
| 101 |
# No preparation is needed for Go module-based projects. |
| 102 |
|
| 103 |
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-dependencies-task/Taskfile.yml |
| 104 |
general:cache-dep-licenses: |
| 105 |
desc: Cache dependency license metadata |
| 106 |
deps: |
| 107 |
- task: general:prepare-deps |
| 108 |
cmds: |
| 109 |
- | |
| 110 |
if |
| 111 |
! which licensed \ |
| 112 |
&>/dev/null |
| 113 |
then |
| 114 |
if [[ {{OS}} == "windows" ]]; then |
| 115 |
echo "Licensed does not have Windows support." |
| 116 |
echo "Please use Linux/macOS or download the dependencies cache from the GitHub Actions workflow artifact." |
| 117 |
else |
| 118 |
echo "licensed not found or not in PATH." |
| 119 |
echo "Please install: https://github.com/licensee/licensed#installation" |
| 120 |
fi |
| 121 |
exit 1 |
| 122 |
fi |
| 123 |
- licensed cache |
| 124 |
|
| 125 |
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-dependencies-task/Taskfile.yml |
| 126 |
general:check-dep-licenses: |
| 127 |
desc: Check for unapproved dependency licenses |
| 128 |
deps: |
| 129 |
- task: general:cache-dep-licenses |
| 130 |
cmds: |
| 131 |
- | |
| 132 |
MATCHES="$( |
| 133 |
find \ |
| 134 |
.licenses \ |
| 135 |
-regex '.+\.yml' \ |
| 136 |
-type f \ |
| 137 |
-print0 \ |
| 138 |
| \ |
| 139 |
xargs \ |
| 140 |
--null \ |
| 141 |
go tool \ |
| 142 |
github.com/mikefarah/yq/v4 \ |
| 143 |
'select(.license == "other") | filename' |
| 144 |
)" |
| 145 |
if [[ "$MATCHES" != "" ]]; then |
| 146 |
printf "%s" "$MATCHES" |
| 147 |
echo |
| 148 |
echo "The license cache files above have the license set to 'other'. Please manually define the license type and retry." |
| 149 |
echo "See: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/check-go-dependencies-task.md#unrecognized-licenses" |
| 150 |
exit 1 |
| 151 |
fi |
| 152 |
- licensed status |
| 153 |
|
| 154 |
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-general-formatting-task/Taskfile.yml |
| 155 |
general:check-formatting: |
| 156 |
desc: Check basic formatting style of all files |
| 157 |
cmds: |
| 158 |
- | |
| 159 |
if |
| 160 |
! which ec \ |
| 161 |
&>/dev/null |
| 162 |
then |
| 163 |
echo "ec not found or not in PATH." |
| 164 |
echo "Please install: https://github.com/editorconfig-checker/editorconfig-checker#installation" |
| 165 |
exit 1 |
| 166 |
fi |
| 167 |
- ec |
| 168 |
|
| 169 |
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/spell-check-task/Taskfile.yml |
| 170 |
general:check-spelling: |
| 171 |
desc: Check for commonly misspelled words |
| 172 |
deps: |
| 173 |
- task: poetry:install-deps |
| 174 |
cmds: |
| 175 |
- poetry run codespell |
| 176 |
|
| 177 |
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/spell-check-task/Taskfile.yml |
| 178 |
general:correct-spelling: |
| 179 |
desc: Correct commonly misspelled words where possible |
| 180 |
deps: |
| 181 |
- task: poetry:install-deps |
| 182 |
cmds: |
| 183 |
- poetry run codespell --write-changes |
| 184 |
|
| 185 |
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/poetry-task/Taskfile.yml |
| 186 |
poetry:install-deps: |
| 187 |
desc: Install dependencies managed by Poetry |
| 188 |
cmds: |
| 189 |
- poetry install --no-root |
| 190 |
|
| 191 |
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/poetry-task/Taskfile.yml |
| 192 |
poetry:update-deps: |
| 193 |
desc: Update all dependencies managed by Poetry to their newest versions |
| 194 |
cmds: |
| 195 |
- poetry update |
| 196 |
|
| 197 |
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-go-task/Taskfile.yml |
| 198 |
go:check: |
| 199 |
desc: Check for problems with Go code |
| 200 |
deps: |
| 201 |
- task: go:vet |
| 202 |
- task: go:lint |
| 203 |
|
| 204 |
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-go-task/Taskfile.yml |
| 205 |
go:vet: |
| 206 |
desc: Check for errors in Go code |
| 207 |
cmds: |
| 208 |
- go vet {{default .DEFAULT_GO_PACKAGES .GO_PACKAGES}} |
| 209 |
|
| 210 |
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-go-task/Taskfile.yml |
| 211 |
go:fix: |
| 212 |
desc: | |
| 213 |
Modernize usages of outdated APIs. |
| 214 |
Environment variable parameters: |
| 215 |
- GO_MODULE_PATH: Path of the Go module root (default: {{.DEFAULT_GO_MODULE_PATH}}). |
| 216 |
- GO_PACKAGES: List of Go packages to modernize (default: all packages of the module). |
| 217 |
dir: "{{default .DEFAULT_GO_MODULE_PATH .GO_MODULE_PATH}}" |
| 218 |
cmds: |
| 219 |
- go fix {{default .DEFAULT_GO_PACKAGES .GO_PACKAGES}} |
| 220 |
|
| 221 |
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-go-task/Taskfile.yml |
| 222 |
go:format: |
| 223 |
desc: | |
| 224 |
Format Go code. |
| 225 |
Environment variable parameters: |
| 226 |
- GO_MODULE_PATH: Path of the Go module root (default: {{.DEFAULT_GO_MODULE_PATH}}). |
| 227 |
- GO_PACKAGES: List of Go packages to modernize (default: all packages of the module). |
| 228 |
dir: "{{default .DEFAULT_GO_MODULE_PATH .GO_MODULE_PATH}}" |
| 229 |
cmds: |
| 230 |
- go fmt {{default .DEFAULT_GO_PACKAGES .GO_PACKAGES}} |
| 231 |
|
| 232 |
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-go-task/Taskfile.yml |
| 233 |
go:lint: |
| 234 |
desc: | |
| 235 |
Lint Go code |
| 236 |
Environment variable parameters: |
| 237 |
- GO_MODULE_PATH: Path of the Go module root (default: {{.DEFAULT_GO_MODULE_PATH}}). |
| 238 |
dir: "{{default .DEFAULT_GO_MODULE_PATH .GO_MODULE_PATH}}" |
| 239 |
cmds: |
| 240 |
- | |
| 241 |
if |
| 242 |
! which golangci-lint \ |
| 243 |
&>/dev/null |
| 244 |
then |
| 245 |
echo "golangci-lint not installed or not in PATH." |
| 246 |
echo "Please install: https://golangci-lint.run/usage/install/#local-installation" |
| 247 |
exit 1 |
| 248 |
fi |
| 249 |
- golangci-lint run |
| 250 |
|
| 251 |
# Make a temporary file and print the path passed to stdout. |
| 252 |
# Environment variable parameters: |
| 253 |
# - TEMPLATE: template for the format of the filename. |
| 254 |
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/windows-task/Taskfile.yml |
| 255 |
utility:mktemp-file: |
| 256 |
vars: |
| 257 |
RAW_PATH: |
| 258 |
sh: mktemp --tmpdir "{{.TEMPLATE}}" |
| 259 |
cmds: |
| 260 |
- task: utility:normalize-path |
| 261 |
vars: |
| 262 |
RAW_PATH: "{{.RAW_PATH}}" |
| 263 |
|
| 264 |
# Print a normalized version of the path to stdout. |
| 265 |
# Environment variable parameters: |
| 266 |
# - RAW_PATH: the path to be normalized. |
| 267 |
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/windows-task/Taskfile.yml |
| 268 |
utility:normalize-path: |
| 269 |
cmds: |
| 270 |
- | |
| 271 |
if |
| 272 |
[[ "{{.OS}}" == "Windows_NT" ]] \ |
| 273 |
&& \ |
| 274 |
which cygpath \ |
| 275 |
&>/dev/null |
| 276 |
then |
| 277 |
# Even though the shell handles POSIX format absolute paths as expected, external applications do not. |
| 278 |
# So paths passed to such applications must first be converted to Windows format. |
| 279 |
cygpath \ |
| 280 |
-w \ |
| 281 |
"{{.RAW_PATH}}" |
| 282 |
else |
| 283 |
echo "{{.RAW_PATH}}" |
| 284 |
fi |