1
0
mirror of https://github.com/arduino/library-registry.git synced 2025-07-29 14:01:15 +03:00

Make "Check Go" workflow module path support extendable

Since it is not a primary component of the project, I puth the registry validator Go module in a subfolder of the
repository. The standardized Arduino tooling project "assets" at that time were designed for the more common project
structure of the module in the repository root. This meant some small modifications to the assets were required in order
to make them applicable to this repository's structure.

Since that time, the standardized assets have been improved so they can support arbitrary Go module locations, as is
needed here. A different approach was taken in order to also support any number of modules. Although this particular
repository is not likely to gain multiple modules, that is needed by other projects, and so it is a better approach in
general.
This commit is contained in:
per1234
2021-08-12 17:58:15 -07:00
parent 720e8d1c4b
commit a6634af0c7
2 changed files with 61 additions and 11 deletions

View File

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

View File

@ -2,10 +2,11 @@
version: "3" version: "3"
vars: vars:
GO_PROJECT_PATH: .github/workflows/assets/validate-registry
LDFLAGS: LDFLAGS:
DEFAULT_GO_MODULE_PATH: .github/workflows/assets/validate-registry/
DEFAULT_GO_PACKAGES: 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: tasks:
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-workflows-task/Taskfile.yml # 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 # Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/go-task/Taskfile.yml
go:build: go:build:
desc: Build the Go code desc: Build the Go code
dir: "{{.GO_PROJECT_PATH}}" dir: "{{.DEFAULT_GO_MODULE_PATH}}"
cmds: cmds:
- go build -v {{.LDFLAGS}} - go build -v {{.LDFLAGS}}
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-go-task/Taskfile.yml # Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-go-task/Taskfile.yml
go:check: go:check:
desc: Check for problems with Go code desc: Check for problems with Go code
dir: "{{.GO_PROJECT_PATH}}"
deps: deps:
- task: go:vet - task: go:vet
- task: go:lint - 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 # Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-go-task/Taskfile.yml
go:vet: go:vet:
desc: Check for errors in Go code desc: Check for errors in Go code
dir: "{{.GO_PROJECT_PATH}}" dir: "{{default .DEFAULT_GO_MODULE_PATH .GO_MODULE_PATH}}"
cmds: cmds:
- go vet {{default .DEFAULT_GO_PACKAGES .GO_PACKAGES}} - 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 # Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-go-task/Taskfile.yml
go:fix: go:fix:
desc: Modernize usages of outdated APIs desc: Modernize usages of outdated APIs
dir: "{{.GO_PROJECT_PATH}}" dir: "{{default .DEFAULT_GO_MODULE_PATH .GO_MODULE_PATH}}"
cmds: cmds:
- go fix {{default .DEFAULT_GO_PACKAGES .GO_PACKAGES}} - 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 # Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-go-task/Taskfile.yml
go:lint: go:lint:
desc: Lint Go code desc: Lint Go code
dir: "{{.GO_PROJECT_PATH}}" dir: "{{default .DEFAULT_GO_MODULE_PATH .GO_MODULE_PATH}}"
cmds: cmds:
- | - |
if ! which golint &>/dev/null; then 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 # Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-go-task/Taskfile.yml
go:format: go:format:
desc: Format Go code desc: Format Go code
dir: "{{.GO_PROJECT_PATH}}" dir: "{{default .DEFAULT_GO_MODULE_PATH .GO_MODULE_PATH}}"
cmds: cmds:
- go fmt {{default .DEFAULT_GO_PACKAGES .GO_PACKAGES}} - go fmt {{default .DEFAULT_GO_PACKAGES .GO_PACKAGES}}
go:tidy: go:tidy:
desc: Run go mod tidy desc: Run go mod tidy
dir: "{{.GO_PROJECT_PATH}}" dir: "{{default .DEFAULT_GO_MODULE_PATH .GO_MODULE_PATH}}"
cmds: cmds:
- go mod tidy - go mod tidy
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/test-go-integration-task/Taskfile.yml # Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/test-go-integration-task/Taskfile.yml
go:test-integration: go:test-integration:
desc: Run integration tests desc: Run integration tests
dir: "{{.GO_PROJECT_PATH}}" dir: "{{.DEFAULT_GO_MODULE_PATH}}"
deps: deps:
- task: go:build - task: go:build
- task: poetry:install-deps - task: poetry:install-deps
@ -152,7 +152,7 @@ tasks:
- task: go:build - task: go:build
cmds: 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 # Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-yaml-task/Taskfile.yml
yaml:lint: yaml:lint: