|
| 1 | +version: "3" |
| 2 | + |
| 3 | +tasks: |
| 4 | + build: |
| 5 | + desc: Build the project |
| 6 | + cmds: |
| 7 | + - go build -v |
| 8 | + |
| 9 | + test: |
| 10 | + desc: Run tests |
| 11 | + cmds: |
| 12 | + - task: go:test-unit |
| 13 | + - task: schema:compile |
| 14 | + |
| 15 | + go:test-unit: |
| 16 | + desc: Run unit tests |
| 17 | + cmds: |
| 18 | + - go test -short -run '{{ default ".*" .TEST_REGEX }}' {{ default "-v" .GOFLAGS }} -coverprofile=coverage_unit.txt {{ default .DEFAULT_PACKAGES .PACKAGES }} |
| 19 | + |
| 20 | + schema:compile: |
| 21 | + desc: Compile JSON schema |
| 22 | + cmds: |
| 23 | + - npx ajv-cli compile -s "./etc/schema/*.json" |
| 24 | + |
| 25 | + check: |
| 26 | + desc: Lint and check formatting of all files |
| 27 | + cmds: |
| 28 | + - task: go:check |
| 29 | + - task: docs:check |
| 30 | + - task: config:check |
| 31 | + - task: check-spelling |
| 32 | + |
| 33 | + lint: |
| 34 | + desc: Lint all files |
| 35 | + cmds: |
| 36 | + - task: go:lint |
| 37 | + - task: docs:lint |
| 38 | + - task: config:lint |
| 39 | + |
| 40 | + check-formatting: |
| 41 | + desc: Check formatting of all files |
| 42 | + cmds: |
| 43 | + - task: go:check-formatting |
| 44 | + - task: docs:check-formatting |
| 45 | + - task: config:check-formatting |
| 46 | + |
| 47 | + format: |
| 48 | + desc: Format all files |
| 49 | + cmds: |
| 50 | + - task: go:format |
| 51 | + - task: docs:format |
| 52 | + - task: config:format |
| 53 | + |
| 54 | + go:check: |
| 55 | + desc: Lint and check formatting of Go code |
| 56 | + cmds: |
| 57 | + - task: go:lint |
| 58 | + - task: go:check-formatting |
| 59 | + |
| 60 | + go:lint: |
| 61 | + desc: Lint Go code |
| 62 | + cmds: |
| 63 | + - go vet {{ default .DEFAULT_PACKAGES .PACKAGES }} |
| 64 | + - "'{{.GOLINTBIN}}' {{.GOLINTFLAGS}} {{ default .DEFAULT_TARGETS .TARGETS }}" |
| 65 | + |
| 66 | + go:check-formatting: |
| 67 | + desc: Check Go code formatting |
| 68 | + cmds: |
| 69 | + - | |
| 70 | + RESULTS="$(gofmt -l {{ default .DEFAULT_PATHS .PATHS }})" |
| 71 | + echo "$RESULTS" |
| 72 | + test -z "$RESULTS" |
| 73 | +
|
| 74 | + go:format: |
| 75 | + desc: Format Go code |
| 76 | + cmds: |
| 77 | + - go fmt {{ default .DEFAULT_PACKAGES .PACKAGES }} |
| 78 | + |
| 79 | + docs:check: |
| 80 | + desc: Lint and check formatting of documentation files |
| 81 | + cmds: |
| 82 | + - task: docs:check-formatting |
| 83 | + - task: docs:check-links |
| 84 | + |
| 85 | + docs:lint: |
| 86 | + desc: Lint documentation files |
| 87 | + cmds: |
| 88 | + - task: docs:check-license |
| 89 | + |
| 90 | + docs:check-license: |
| 91 | + desc: Check if the license file is correctly formatted |
| 92 | + cmds: |
| 93 | + - | |
| 94 | + EXPECTED_LICENSE_FILE="\"LICENSE.txt\"" |
| 95 | + EXPECTED_LICENSE_TYPE="\"GPL-3.0\"" # https://spdx.org/licenses/ |
| 96 | +
|
| 97 | + # See: https://github.com/licensee/licensee |
| 98 | + LICENSEE_OUTPUT="$(licensee detect --json --confidence=100)" |
| 99 | +
|
| 100 | + DETECTED_LICENSE_FILE="$(echo "$LICENSEE_OUTPUT" | jq .matched_files[0].filename | tr --delete '\r')" |
| 101 | + echo "Detected license file: $DETECTED_LICENSE_FILE" |
| 102 | + if [ "$DETECTED_LICENSE_FILE" != "$EXPECTED_LICENSE_FILE" ]; then |
| 103 | + echo "ERROR: detected license file doesn't match expected: $EXPECTED_LICENSE_FILE" |
| 104 | + exit 1 |
| 105 | + fi |
| 106 | +
|
| 107 | + DETECTED_LICENSE_TYPE="$(echo "$LICENSEE_OUTPUT" | jq .matched_files[0].matched_license | tr --delete '\r')" |
| 108 | + echo "Detected license type: $DETECTED_LICENSE_TYPE" |
| 109 | + if [ "$DETECTED_LICENSE_TYPE" != "$EXPECTED_LICENSE_TYPE" ]; then |
| 110 | + echo "ERROR: detected license type doesn't match expected $EXPECTED_LICENSE_TYPE" |
| 111 | + exit 1 |
| 112 | + fi |
| 113 | +
|
| 114 | + docs:check-links: |
| 115 | + desc: Check for dead links in documentation |
| 116 | + cmds: |
| 117 | + - | |
| 118 | + npx --package markdown-link-check --call ' |
| 119 | + STATUS=0 |
| 120 | + for file in $(find -name "*.md"); do |
| 121 | + markdown-link-check --quiet "$file" |
| 122 | + STATUS=$(( $STATUS + $? )) |
| 123 | + done |
| 124 | + exit $STATUS' |
| 125 | +
|
| 126 | + docs:check-formatting: |
| 127 | + desc: Check formatting of documentation files |
| 128 | + cmds: |
| 129 | + - npx {{ .PRETTIER }} --check "**/*.md" |
| 130 | + |
| 131 | + docs:format: |
| 132 | + desc: Format documentation files |
| 133 | + cmds: |
| 134 | + - npx {{ .PRETTIER }} --write "**/*.md" |
| 135 | + |
| 136 | + config:check: |
| 137 | + desc: Lint and check formatting of configuration files |
| 138 | + cmds: |
| 139 | + - task: config:check-formatting |
| 140 | + - task: config:lint |
| 141 | + |
| 142 | + config:lint: |
| 143 | + desc: Lint configuration files |
| 144 | + cmds: |
| 145 | + - task: workflow:validate |
| 146 | + |
| 147 | + workflow:validate: |
| 148 | + desc: Validate GitHub Actions workflows against JSON schema |
| 149 | + cmds: |
| 150 | + - wget --output-document={{ .WORKFLOW_SCHEMA_PATH }} https://json.schemastore.org/github-workflow |
| 151 | + - npx ajv-cli validate -s {{ .WORKFLOW_SCHEMA_PATH }} -d "./.github/workflows/*.{yml,yaml}" |
| 152 | + |
| 153 | + config:check-formatting: |
| 154 | + desc: Check formatting of configuration files |
| 155 | + cmds: |
| 156 | + - npx {{ .PRETTIER }} --check "**/*.{yml,yaml}" |
| 157 | + - npx {{ .PRETTIER }} --check "**/*.json" |
| 158 | + |
| 159 | + config:format: |
| 160 | + desc: Format configuration files |
| 161 | + cmds: |
| 162 | + - npx {{ .PRETTIER }} --write "**/*.{yml,yaml}" |
| 163 | + - npx {{ .PRETTIER }} --write "**/*.json" |
| 164 | + |
| 165 | + check-spelling: |
| 166 | + desc: Check for commonly misspelled words |
| 167 | + cmds: |
| 168 | + - poetry install --no-root |
| 169 | + - poetry run codespell {{ .CODESPELL_SKIP_OPTION }} {{ .CODESPELL_IGNORE_WORDS_OPTION }} |
| 170 | + |
| 171 | + correct-spelling: |
| 172 | + desc: Correct commonly misspelled words where possible |
| 173 | + cmds: |
| 174 | + - poetry install --no-root |
| 175 | + - poetry run codespell --write-changes {{ .CODESPELL_SKIP_OPTION }} {{ .CODESPELL_IGNORE_WORDS_OPTION }} |
| 176 | + |
| 177 | +vars: |
| 178 | + DEFAULT_PACKAGES: |
| 179 | + sh: echo `go list ./... | tr '\n' ' '` |
| 180 | + DEFAULT_PATHS: |
| 181 | + sh: echo '`go list -f '{{"{{"}}.Dir{{"}}"}}' ./...`' |
| 182 | + GOFLAGS: "-timeout 10m -v -coverpkg=./... -covermode=atomic" |
| 183 | + |
| 184 | + GOLINTBIN: |
| 185 | + sh: go list -f {{"{{"}}".Target{{"}}"}}" golang.org/x/lint/golint |
| 186 | + GOLINTFLAGS: "-min_confidence 0.8 -set_exit_status" |
| 187 | + |
| 188 | + |
| 189 | + |
| 190 | + WORKFLOW_SCHEMA_PATH: "$(mktemp -t gha-workflow-schema-XXXXXXXXXX.json)" |
| 191 | + |
| 192 | + CODESPELL_SKIP_OPTION: '--skip "./.git,./go.mod,./go.sum,./arduino-check,./arduino-check.exe"' |
| 193 | + CODESPELL_IGNORE_WORDS_OPTION: "--ignore-words ./etc/codespell-ignore-words-list.txt" |
0 commit comments