version: "3" vars: DIST_DIR: "dist" DUMMY_DISCOVERY_VERSION: sh: echo "$(git describe --tags --dirty --broken)" DUMMY_DISCOVERY_TIMESTAMP: sh: echo "$(date -u +"%Y-%m-%dT%H:%M:%SZ")" DUMMY_DISCOVERY_LDFLAGS: > -X github.com/arduino/pluggable-discovery-protocol-handler/dummy-discovery/args.Tag={{.DUMMY_DISCOVERY_VERSION}} -X github.com/arduino/pluggable-discovery-protocol-handler/dummy-discovery/args.Timestamp={{.DUMMY_DISCOVERY_TIMESTAMP}} # Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/go-task/Taskfile.yml # Path of the project's primary Go module: DEFAULT_GO_MODULE_PATH: . DEFAULT_GO_PACKAGES: sh: | echo $( cd {{default .DEFAULT_GO_MODULE_PATH .GO_MODULE_PATH}} && go list ./... | tr '\n' ' ' || echo '"ERROR: Unable to discover Go packages"' ) # `-ldflags` flag to use for `go build` command # TODO: define flag if required by the project, or leave empty if not needed. LDFLAGS: TEST_LDFLAGS: tasks: build-dummy-discovery: desc: Build the dummy-discovery client example vars: EXECUTABLE: dummy-discovery{{if eq OS "windows"}}.exe{{end}} cmds: - go build -o dist/{{.EXECUTABLE}} -v -ldflags '{{.DUMMY_DISCOVERY_LDFLAGS}}' ./dummy-discovery # Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/test-go-task/Taskfile.yml go:test: desc: | Run unit tests. Environment variable parameters: - GO_MODULE_PATH: Path of the Go module root (default: {{.DEFAULT_GO_MODULE_PATH}}). - GO_PACKAGES: List of Go packages to test (default: all packages of the module). dir: "{{default .DEFAULT_GO_MODULE_PATH .GO_MODULE_PATH}}" cmds: - | go test \ -v \ -short \ -run '{{default ".*" .GO_TEST_REGEX}}' \ {{default "-timeout 10m -coverpkg=./... -covermode=atomic" .GO_TEST_FLAGS}} \ -coverprofile=coverage_unit.txt \ {{.TEST_LDFLAGS}} \ {{default .DEFAULT_GO_PACKAGES .GO_PACKAGES}} # Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/npm-task/Taskfile.yml npm:install-deps: desc: | Install dependencies managed by npm. Environment variable parameters: - PROJECT_PATH: Path of the npm-managed project (default: {{.DEFAULT_NPM_PROJECT_PATH}}). run: when_changed dir: "{{default .DEFAULT_NPM_PROJECT_PATH .PROJECT_PATH}}" cmds: - npm install # Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-workflows-task/Taskfile.yml ci:validate: desc: Validate GitHub Actions workflows against their JSON schema vars: # Source: https://github.com/SchemaStore/schemastore/blob/master/src/schemas/json/github-workflow.json WORKFLOW_SCHEMA_URL: https://json.schemastore.org/github-workflow WORKFLOW_SCHEMA_PATH: sh: | go tool \ github.com/go-task/task/v3/cmd/task utility:mktemp-file \ TEMPLATE="workflow-schema-XXXXXXXXXX.json" WORKFLOWS_DATA_PATH: "./.github/workflows/*.{yml,yaml}" deps: - task: npm:install-deps vars: PROJECT_PATH: . cmds: - | wget \ --quiet \ --output-document="{{.WORKFLOW_SCHEMA_PATH}}" \ {{.WORKFLOW_SCHEMA_URL}} - | npx \ --package=ajv-cli \ --package=ajv-formats \ ajv validate \ --all-errors \ --strict=false \ -c ajv-formats \ -s "{{.WORKFLOW_SCHEMA_PATH}}" \ -d "{{.WORKFLOWS_DATA_PATH}}" # Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-go-dependencies-task/Taskfile.yml general:prepare-deps: desc: Prepare project dependencies for license check # No preparation is needed for Go module-based projects. # Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-dependencies-task/Taskfile.yml general:cache-dep-licenses: desc: Cache dependency license metadata deps: - task: general:prepare-deps cmds: - | if ! which licensed \ &>/dev/null then if [[ {{OS}} == "windows" ]]; then echo "Licensed does not have Windows support." echo "Please use Linux/macOS or download the dependencies cache from the GitHub Actions workflow artifact." else echo "licensed not found or not in PATH." echo "Please install: https://github.com/licensee/licensed#installation" fi exit 1 fi - licensed cache # Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-dependencies-task/Taskfile.yml general:check-dep-licenses: desc: Check for unapproved dependency licenses deps: - task: general:cache-dep-licenses cmds: - | MATCHES="$( find \ .licenses \ -regex '.+\.yml' \ -type f \ -print0 \ | \ xargs \ --null \ go tool \ github.com/mikefarah/yq/v4 \ 'select(.license == "other") | filename' )" if [[ "$MATCHES" != "" ]]; then printf "%s" "$MATCHES" echo echo "The license cache files above have the license set to 'other'. Please manually define the license type and retry." echo "See: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/check-go-dependencies-task.md#unrecognized-licenses" exit 1 fi - licensed status # Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-general-formatting-task/Taskfile.yml general:check-formatting: desc: Check basic formatting style of all files cmds: - | if ! which ec \ &>/dev/null then echo "ec not found or not in PATH." echo "Please install: https://github.com/editorconfig-checker/editorconfig-checker#installation" exit 1 fi - ec # Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/spell-check-task/Taskfile.yml general:check-spelling: desc: Check for commonly misspelled words deps: - task: poetry:install-deps cmds: - poetry run codespell # Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/spell-check-task/Taskfile.yml general:correct-spelling: desc: Correct commonly misspelled words where possible deps: - task: poetry:install-deps cmds: - poetry run codespell --write-changes # Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/poetry-task/Taskfile.yml poetry:install-deps: desc: Install dependencies managed by Poetry cmds: - poetry install --no-root # Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/poetry-task/Taskfile.yml poetry:update-deps: desc: Update all dependencies managed by Poetry to their newest versions cmds: - poetry update # Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-go-task/Taskfile.yml go:check: desc: Check for problems with Go code deps: - task: go:vet - task: go:lint # Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-go-task/Taskfile.yml go:vet: desc: Check for errors in Go code cmds: - go vet {{default .DEFAULT_GO_PACKAGES .GO_PACKAGES}} # Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-go-task/Taskfile.yml go:fix: desc: | Modernize usages of outdated APIs. Environment variable parameters: - GO_MODULE_PATH: Path of the Go module root (default: {{.DEFAULT_GO_MODULE_PATH}}). - GO_PACKAGES: List of Go packages to modernize (default: all packages of the module). dir: "{{default .DEFAULT_GO_MODULE_PATH .GO_MODULE_PATH}}" cmds: - go fix {{default .DEFAULT_GO_PACKAGES .GO_PACKAGES}} # Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-go-task/Taskfile.yml go:format: desc: | Format Go code. Environment variable parameters: - GO_MODULE_PATH: Path of the Go module root (default: {{.DEFAULT_GO_MODULE_PATH}}). - GO_PACKAGES: List of Go packages to modernize (default: all packages of the module). dir: "{{default .DEFAULT_GO_MODULE_PATH .GO_MODULE_PATH}}" cmds: - go fmt {{default .DEFAULT_GO_PACKAGES .GO_PACKAGES}} # Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-go-task/Taskfile.yml go:lint: desc: | Lint Go code Environment variable parameters: - GO_MODULE_PATH: Path of the Go module root (default: {{.DEFAULT_GO_MODULE_PATH}}). dir: "{{default .DEFAULT_GO_MODULE_PATH .GO_MODULE_PATH}}" cmds: - | if ! which golangci-lint \ &>/dev/null then echo "golangci-lint not installed or not in PATH." echo "Please install: https://golangci-lint.run/usage/install/#local-installation" exit 1 fi - golangci-lint run # Make a temporary file and print the path passed to stdout. # Environment variable parameters: # - TEMPLATE: template for the format of the filename. # Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/windows-task/Taskfile.yml utility:mktemp-file: vars: RAW_PATH: sh: mktemp --tmpdir "{{.TEMPLATE}}" cmds: - task: utility:normalize-path vars: RAW_PATH: "{{.RAW_PATH}}" # Print a normalized version of the path to stdout. # Environment variable parameters: # - RAW_PATH: the path to be normalized. # Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/windows-task/Taskfile.yml utility:normalize-path: cmds: - | if [[ "{{.OS}}" == "Windows_NT" ]] \ && \ which cygpath \ &>/dev/null then # Even though the shell handles POSIX format absolute paths as expected, external applications do not. # So paths passed to such applications must first be converted to Windows format. cygpath \ -w \ "{{.RAW_PATH}}" else echo "{{.RAW_PATH}}" fi