Skip to content

Use "Check Go" template workflow and related tasks #213

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 17 commits into from
Jul 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions .github/workflows/check-formatting.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ on:
- ".github/workflows/check-formatting.yml"
- "Taskfile.yml"
- ".prettierrc"
- "**.go"
- "**.json"
- "**.md"
- "**.yaml"
Expand All @@ -16,7 +15,6 @@ on:
- ".github/workflows/check-formatting.yml"
- "Taskfile.yml"
- ".prettierrc"
- "**.go"
- "**.json"
- "**.md"
- "**.yaml"
Expand All @@ -36,9 +34,6 @@ jobs:
repo-token: ${{ secrets.GITHUB_TOKEN }}
version: 3.x

- name: Check Go code formatting
run: task go:check-formatting

- name: Check shell script formatting
# https://github.com/mvdan/sh
run: |
Expand Down
134 changes: 134 additions & 0 deletions .github/workflows/check-go-task.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/check-go-task.md
name: Check Go

env:
# See: https://github.com/actions/setup-go/tree/v2#readme
GO_VERSION: "1.14"

# See: https://docs.github.com/en/actions/reference/events-that-trigger-workflows
on:
push:
paths:
- ".github/workflows/check-go-task.ya?ml"
- "Taskfile.ya?ml"
- "go.mod"
- "go.sum"
- "**.go"
pull_request:
paths:
- ".github/workflows/check-go-task.ya?ml"
- "Taskfile.ya?ml"
- "go.mod"
- "go.sum"
- "**.go"
workflow_dispatch:
repository_dispatch:

jobs:
check-errors:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Install Go
uses: actions/setup-go@v2
with:
go-version: ${{ env.GO_VERSION }}

- name: Install Task
uses: arduino/setup-task@v1
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
version: 3.x

- name: Check for errors
run: task go:vet

check-outdated:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Install Go
uses: actions/setup-go@v2
with:
go-version: ${{ env.GO_VERSION }}

- name: Install Task
uses: arduino/setup-task@v1
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
version: 3.x

- name: Modernize usages of outdated APIs
run: task go:fix

- name: Check if any fixes were needed
run: git diff --color --exit-code

check-style:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Install Go
uses: actions/setup-go@v2
with:
go-version: ${{ env.GO_VERSION }}

- name: Install Task
uses: arduino/setup-task@v1
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
version: 3.x

- name: Check style
run: task --silent go:lint

check-formatting:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Install Go
uses: actions/setup-go@v2
with:
go-version: ${{ env.GO_VERSION }}

- name: Install Task
uses: arduino/setup-task@v1
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
version: 3.x

- name: Format code
run: task go:format

- name: Check formatting
run: git diff --color --exit-code

check-config:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Install Go
uses: actions/setup-go@v2
with:
go-version: ${{ env.GO_VERSION }}

- name: Run go mod tidy
run: go mod tidy

- name: Check whether any tidying was needed
run: git diff --color --exit-code
37 changes: 0 additions & 37 deletions .github/workflows/lint-code.yml

This file was deleted.

1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Arduino Lint

[![Tests Status](https://github.com/arduino/arduino-lint/workflows/Run%20tests/badge.svg)](https://github.com/arduino/arduino-lint/actions?workflow=Run+tests)
[![Check Go status](https://github.com/arduino/arduino-lint/actions/workflows/check-go-task.yml/badge.svg)](https://github.com/arduino/arduino-lint/actions/workflows/check-go-task.yml)
[![Nightly Status](https://github.com/arduino/arduino-lint/workflows/Nightly%20build/badge.svg)](https://github.com/arduino/arduino-lint/actions?workflow=Nightly+build)
[![Docs Status](https://github.com/arduino/arduino-lint/workflows/Publish%20documentation/badge.svg)](https://github.com/arduino/arduino-lint/actions?workflow=Publish+documentation)
[![Codecov](https://codecov.io/gh/arduino/arduino-lint/branch/main/graph/badge.svg?token=nprqPQMbdh)](https://codecov.io/gh/arduino/arduino-lint)
Expand Down
53 changes: 32 additions & 21 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ tasks:
go:test-unit:
desc: Run unit tests
cmds:
- go test -short -run '{{ default ".*" .TEST_REGEX }}' {{ default "-v" .GOFLAGS }} -coverprofile=coverage_unit.txt {{ default .DEFAULT_PACKAGES .PACKAGES }}
- go test -short -run '{{ default ".*" .TEST_REGEX }}' {{ default "-v" .GOFLAGS }} -coverprofile=coverage_unit.txt {{ default .DEFAULT_GO_PACKAGES .GO_PACKAGES }}

test-integration:
desc: Run integration tests
Expand All @@ -49,6 +49,7 @@ tasks:
lint:
desc: Lint all files
cmds:
- task: go:vet
- task: go:lint
- task: python:lint
- task: docs:lint
Expand All @@ -57,7 +58,6 @@ tasks:
check-formatting:
desc: Check formatting of all files
cmds:
- task: go:check-formatting
- task: docs:check-formatting
- task: config:check-formatting

Expand All @@ -69,32 +69,46 @@ tasks:
- task: docs:format
- task: config:format

# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-go-task/Taskfile.yml
go:check:
desc: Lint and check formatting of Go code
cmds:
desc: Check for problems with Go code
deps:
- task: go:vet
- task: go:lint
- task: go:check-formatting

# 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
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
cmds:
- go vet {{ default .DEFAULT_PACKAGES .PACKAGES }}
- |
PROJECT_PATH="$PWD"
# `go get` and `go list` commands must be run from a temporary folder to avoid polluting go.mod
cd "$(mktemp -d "${TMPDIR-${TMP-/tmp}}/task-temporary-XXXXX")"
go get golang.org/x/lint/golint
GOLINT_PATH="$(go list -f '{{"{{"}}.Target{{"}}"}}' golang.org/x/lint/golint || echo "false")"
"$GOLINT_PATH" {{.GOLINTFLAGS}} "{{ default .DEFAULT_TARGETS .TARGETS }}"

go:check-formatting:
desc: Check Go code formatting
cmds:
- |
RESULTS="$(gofmt -l {{ default .DEFAULT_PATHS .PATHS }})"
echo "$RESULTS"
test -z "$RESULTS"
# `golint` must be run from the module folder
cd "$PROJECT_PATH"
"$GOLINT_PATH" \
{{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
cmds:
- gofmt -l -w {{ default .DEFAULT_PATHS .PATHS }}
- go fmt {{default .DEFAULT_GO_PACKAGES .GO_PACKAGES}}

python:check:
cmds:
Expand Down Expand Up @@ -263,10 +277,8 @@ tasks:
vars:
PROJECT_NAME: "arduino-lint"
DIST_DIR: "dist"
DEFAULT_PACKAGES:
sh: echo `go list ./... | tr '\n' ' '`
DEFAULT_PATHS:
sh: echo '`go list -f '{{"{{"}}.Dir{{"}}"}}' ./...`'
DEFAULT_GO_PACKAGES:
sh: echo `go list ./... | grep --invert-match 'github.com/arduino/arduino-lint/internal/rule/schema/schemadata' | tr '\n' ' '`
# build vars
COMMIT:
sh: echo "$(git log -n 1 --format=%h)"
Expand All @@ -286,7 +298,6 @@ vars:
-X {{ .CONFIGURATION_PACKAGE }}.buildTimestamp={{.TIMESTAMP}}
'
GOFLAGS: "-timeout 10m -v -coverpkg=./... -covermode=atomic"
GOLINTFLAGS: "-min_confidence 0.8 -set_exit_status"

DOCS_VERSION: dev
DOCS_ALIAS: ""
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1194,8 +1194,6 @@ golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzB
golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.3.0 h1:RM4zey1++hCTbCVQfnWeKs9/IEsaBLA8vTkd0WVtmH4=
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.4.1 h1:Kvvh58BN8Y9/lBi7hTekvtMpm07eUZ0ck5pRHpsMWrY=
golang.org/x/mod v0.4.1/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.4.2 h1:Gz96sIWK3OalVv/I/qNygP42zyoKp3xptRVCWRFEBvo=
golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/net v0.0.0-20180406214816-61147c48b25b/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
Expand Down
18 changes: 12 additions & 6 deletions internal/project/projecttype/projecttype.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,18 @@ import (
type Type int

const (
Sketch Type = iota // sketch
Library // library
Platform // platform
PackageIndex // package-index
All // all
Not // N/A
// Sketch is used for Arduino sketch projects.
Sketch Type = iota // sketch
// Library is used for Arduino library projects.
Library // library
// Platform is used for Arduino boards platform projects.
Platform // platform
// PackageIndex is used for Arduino package index projects.
PackageIndex // package-index
// All is the catch-all for all supported Arduino project types.
All // all
// Not is the project type used when an Arduino project was not detected.
Not // N/A
)

// FromString parses the --project-type flag value and returns the corresponding project type.
Expand Down
4 changes: 3 additions & 1 deletion internal/result/outputformat/outputformat.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@ import (
type Type int

const (
// Text is the text output format.
Text Type = iota // text
JSON // json
// JSON is the JSON output format.
JSON // json
)

// FromString parses the --format flag value and returns the corresponding output format type.
Expand Down
4 changes: 2 additions & 2 deletions internal/result/result.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,9 +200,9 @@ func (results *Type) AddProjectSummary(lintedProject project.Type) {
for _, ruleReport := range results.Projects[projectReportIndex].Rules {
if ruleReport.Result == ruleresult.Fail.String() {
if ruleReport.Level == rulelevel.Warning.String() {
warningCount += 1
warningCount++
} else if ruleReport.Level == rulelevel.Error.String() {
errorCount += 1
errorCount++
pass = false
}
}
Expand Down
2 changes: 1 addition & 1 deletion internal/result/result_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ func TestAddProjectSummary(t *testing.T) {
if (result == ruleresult.Fail) || configuration.Verbose() {
level := testTable.levels[testDataIndex].String()
results.Projects[0].Rules[ruleIndex].Level = level
ruleIndex += 1
ruleIndex++
}
}
results.AddProjectSummary(lintedProject)
Expand Down
Loading