1
0
mirror of https://github.com/arduino/library-registry.git synced 2025-05-19 08:13:41 +03:00

Merge pull request #358 from per1234/extendable-check-go

Make "Check Go" workflow module path support extendable
This commit is contained in:
per1234 2021-08-13 01:26:46 -07:00 committed by GitHub
commit b3f5b32428
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 61 additions and 11 deletions

View File

@ -26,8 +26,16 @@ on:
jobs:
check-errors:
name: check-errors (${{ matrix.module.path }})
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
module:
- path: .github/workflows/assets/validate-registry/
steps:
- name: Checkout repository
uses: actions/checkout@v2
@ -44,11 +52,21 @@ jobs:
version: 3.x
- name: Check for errors
env:
GO_MODULE_PATH: ${{ matrix.module.path }}
run: task go:vet
check-outdated:
name: check-outdated (${{ matrix.module.path }})
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
module:
- path: .github/workflows/assets/validate-registry/
steps:
- name: Checkout repository
uses: actions/checkout@v2
@ -65,14 +83,24 @@ jobs:
version: 3.x
- name: Modernize usages of outdated APIs
env:
GO_MODULE_PATH: ${{ matrix.module.path }}
run: task go:fix
- name: Check if any fixes were needed
run: git diff --color --exit-code
check-style:
name: check-style (${{ matrix.module.path }})
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
module:
- path: .github/workflows/assets/validate-registry/
steps:
- name: Checkout repository
uses: actions/checkout@v2
@ -92,11 +120,21 @@ jobs:
run: go install golang.org/x/lint/golint@latest
- name: Check style
env:
GO_MODULE_PATH: ${{ matrix.module.path }}
run: task --silent go:lint
check-formatting:
name: check-formatting (${{ matrix.module.path }})
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
module:
- path: .github/workflows/assets/validate-registry/
steps:
- name: Checkout repository
uses: actions/checkout@v2
@ -113,14 +151,24 @@ jobs:
version: 3.x
- name: Format code
env:
GO_MODULE_PATH: ${{ matrix.module.path }}
run: task go:format
- name: Check formatting
run: git diff --color --exit-code
check-config:
name: check-config (${{ matrix.module.path }})
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
module:
- path: .github/workflows/assets/validate-registry/
steps:
- name: Checkout repository
uses: actions/checkout@v2
@ -137,6 +185,8 @@ jobs:
version: 3.x
- name: Run go mod tidy
env:
GO_MODULE_PATH: ${{ matrix.module.path }}
run: task go:tidy
- name: Check whether any tidying was needed

View File

@ -2,10 +2,11 @@
version: "3"
vars:
GO_PROJECT_PATH: .github/workflows/assets/validate-registry
LDFLAGS:
DEFAULT_GO_MODULE_PATH: .github/workflows/assets/validate-registry/
DEFAULT_GO_PACKAGES:
sh: cd "{{.GO_PROJECT_PATH}}" && echo $(go list ./... | tr '\n' ' ')
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
@ -54,14 +55,13 @@ tasks:
# 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: "{{.GO_PROJECT_PATH}}"
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
dir: "{{.GO_PROJECT_PATH}}"
deps:
- task: go:vet
- task: go:lint
@ -69,21 +69,21 @@ tasks:
# 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: "{{.GO_PROJECT_PATH}}"
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: "{{.GO_PROJECT_PATH}}"
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: "{{.GO_PROJECT_PATH}}"
dir: "{{default .DEFAULT_GO_MODULE_PATH .GO_MODULE_PATH}}"
cmds:
- |
if ! which golint &>/dev/null; then
@ -98,20 +98,20 @@ tasks:
# 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: "{{.GO_PROJECT_PATH}}"
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: "{{.GO_PROJECT_PATH}}"
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: "{{.GO_PROJECT_PATH}}"
dir: "{{.DEFAULT_GO_MODULE_PATH}}"
deps:
- task: go:build
- task: poetry:install-deps
@ -152,7 +152,7 @@ tasks:
- task: go:build
cmds:
- |
"{{.GO_PROJECT_PATH}}/validate-registry" registry.txt
"{{.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: