mirror of
https://github.com/arduino/library-registry.git
synced 2025-05-20 18:53:42 +03:00
A task and GitHub Actions workflow are provided here for checking the license types of Go project dependencies. On every push and pull request that affects relevant files, the CI workflow will check: - If the dependency licenses cache is up to date - If any of the project's dependencies have an unapproved license type. Approval can be based on: - Universally allowed license type - Individual dependency
188 lines
6.8 KiB
YAML
188 lines
6.8 KiB
YAML
# See: https://taskfile.dev/#/usage
|
|
version: "3"
|
|
|
|
vars:
|
|
LDFLAGS:
|
|
DEFAULT_GO_MODULE_PATH: .github/workflows/assets/validate-registry/
|
|
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"')
|
|
|
|
tasks:
|
|
# 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: mktemp -t workflow-schema-XXXXXXXXXX.json
|
|
WORKFLOWS_DATA_PATH: "./.github/workflows/*.{yml,yaml}"
|
|
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-dependencies-task/Taskfile.yml
|
|
general:cache-dep-licenses:
|
|
desc: Cache dependency license metadata
|
|
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. Please install: https://github.com/github/licensed#as-an-executable"
|
|
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:
|
|
- 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. 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/check-prettier-formatting-task/Taskfile.yml
|
|
general:format-prettier:
|
|
desc: Format all supported files with Prettier
|
|
cmds:
|
|
- npx prettier --write .
|
|
|
|
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/go-task/Taskfile.yml
|
|
go:build:
|
|
desc: Build the Go code
|
|
dir: "{{.DEFAULT_GO_MODULE_PATH}}"
|
|
cmds:
|
|
- go build -v {{.LDFLAGS}}
|
|
|
|
# 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
|
|
dir: "{{default .DEFAULT_GO_MODULE_PATH .GO_MODULE_PATH}}"
|
|
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
|
|
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:lint:
|
|
desc: Lint Go code
|
|
dir: "{{default .DEFAULT_GO_MODULE_PATH .GO_MODULE_PATH}}"
|
|
cmds:
|
|
- |
|
|
if ! which golint &>/dev/null; then
|
|
echo "golint not installed or not in PATH. Please install: https://github.com/golang/lint#installation"
|
|
exit 1
|
|
fi
|
|
- |
|
|
golint \
|
|
{{default "-min_confidence 0.8 -set_exit_status" .GO_LINT_FLAGS}} \
|
|
{{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
|
|
dir: "{{default .DEFAULT_GO_MODULE_PATH .GO_MODULE_PATH}}"
|
|
cmds:
|
|
- go fmt {{default .DEFAULT_GO_PACKAGES .GO_PACKAGES}}
|
|
|
|
go:tidy:
|
|
desc: Run go mod tidy
|
|
dir: "{{default .DEFAULT_GO_MODULE_PATH .GO_MODULE_PATH}}"
|
|
cmds:
|
|
- go mod tidy
|
|
|
|
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/test-go-integration-task/Taskfile.yml
|
|
go:test-integration:
|
|
desc: Run integration tests
|
|
dir: "{{.DEFAULT_GO_MODULE_PATH}}"
|
|
deps:
|
|
- task: go:build
|
|
- task: poetry:install-deps
|
|
cmds:
|
|
- poetry run pytest tests
|
|
|
|
# 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-python-task/Taskfile.yml
|
|
python:lint:
|
|
desc: Lint Python code
|
|
deps:
|
|
- task: poetry:install-deps
|
|
cmds:
|
|
- poetry run flake8 --show-source
|
|
|
|
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-python-task/Taskfile.yml
|
|
python:format:
|
|
desc: Format Python files
|
|
deps:
|
|
- task: poetry:install-deps
|
|
cmds:
|
|
- poetry run black .
|
|
|
|
registry:validate:
|
|
desc: Validate registry data file
|
|
deps:
|
|
- task: go:build
|
|
cmds:
|
|
- |
|
|
"{{.DEFAULT_GO_MODULE_PATH}}/validate-registry" registry.txt
|
|
|
|
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-yaml-task/Taskfile.yml
|
|
yaml:lint:
|
|
desc: Check for problems with YAML files
|
|
deps:
|
|
- task: poetry:install-deps
|
|
cmds:
|
|
- poetry run yamllint --format {{default "colored" .YAMLLINT_FORMAT}} .
|