Skip to content

Avoid unnecessary go list command execution when running tasks #355

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 1 commit into from
Mar 16, 2022
Merged

Avoid unnecessary go list command execution when running tasks #355

merged 1 commit into from
Mar 16, 2022

Conversation

per1234
Copy link
Contributor

@per1234 per1234 commented Mar 15, 2022

Introduction

Go commands used during the development of this project may take a list of packages as argument. Generally, we will want to run the command on most of the packages of the targeted module, excluding selected packages which are not of interest (e.g., the automatically generated github.com/arduino/arduino-lint/internal/rule/schema/schemadata package).

The list of packages is generated using the go list command.

Problem

Previously, the list was defined via a "dynamic" taskfile variable. The benefit to that approach was that the go list command ran only once per execution of task. However, there were some serious disadvantages:

The module path could not be adjusted on the fly

The list would always be for the module path set at the time the task command ran (either by setting the GO_MODULE_PATH environment variable in advance, or by the default of the repo root). This meant it was not possible to call the Go tasks multiple times from an "umbrella" task to cover the multiple modules in the repository (example).

The go list command ran on all task executions

Many of the tasks don't have any need for the information generated by this command, meaning this was inefficient.

More significantly, this command can have a side effect of changing the dependency metadata a la go mod tidy.

Since the CI ensures the project is always in a tidy state, you would not expect this to cause an inappropriate diff. However, go mod tidy can have a different result depending on which version of Go is in use.

Although we always use the same version of Go for development and for the runs of the Go-related CI workflows, that is not done for the non Go-related workflows. This meant that the go list command ran with whatever Go version happened to be pre-installed in the GitHub Actions runner (currently 1.15.15), resulting in an unexpected diff. Since some of those workflows use git diff to detect problems, this would cause spurious workflow failures. For example:

https://github.com/arduino/arduino-lint/runs/5561403607?check_suite_focus=true#step:5:35

Solution

The solution is to change this taskfile variable so that it is not "dynamic".

With this new approach, the variable is only a string, which is interpreted by the shell at the time of the task is ran.

Although this does mean that the go list command runs each time the variable occurs in the task being ran, in practice that does not usually result in inefficiency since most often the variable only occurs once in the task run via a task execution, and when it does occur multiple times it is in order to run the task for each module, in which case the go list command needs to run again anyway.

Introduction
============

Go commands used during the development of this project may take a list of packages as argument. Generally, we will want
to run the command on most of the packages of the targeted module, excluding selected packages which are not of interest
(the automatically generated `github.com/arduino/arduino-lint/internal/rule/schema/schemadata` data package for example).

The list of packages is generated using the `go list` command.

Problem
=======

Previously, the list was defined via a "dynamic" taskfile variable. The benefit to that approach was that the `go list`
command ran only once per execution of `task`. However,
there were some serious disadvantages:

**The module path could not be adjusted on the fly**

The list would always be for the module path set at the time the `task` command ran (either by setting the
`GO_MODULE_PATH` environment variable in advance, or by the default of the repo root). This meant it was not possible to
call the Go tasks multiple times from an "umbrella" task to cover the multiple modules in the repository.

**The `go list` command ran on all `task` executions**

Many of the tasks don't have any need for the information generated by this command, meaning this was inefficient.

More significantly, this command can have a side effect of changing the dependency metadata a la `go mod tidy`.

Since the CI ensures the project is always in a tidy state, you would not expect this to cause an inappropriate diff.
However, `go mod tidy` can have a different result depending on which version of Go is in use.

Although we always use the same version of Go for development and for the runs of the Go-related CI workflows, that is
not done for the non Go-related workflows. This meant that the `go list` command ran with whatever Go version happened
to be pre-installed in the GitHub Actions runner (currently 1.15.15), resulting in an unexpected diff. Since some of
those workflows use `git diff` to detect problems, this would cause spurious workflow failures.

Solution
========

The solution is to change this taskfile variable so that it is not "dynamic".

With this new approach, the variable is only a string, which is interpreted by the shell at the time of the task is ran.

Although this does mean that the `go list` command runs each time the variable occurs in the task being ran, in practice
that does not usually result in inefficiency since most often the variable only occurs once in the task run via a `task`
execution, and when it does occur multiple times it is in order to run the task for each module, in which case the
`go list` command needs to run again anyway.
@per1234 per1234 added topic: infrastructure Related to project infrastructure type: imperfection Perceived defect in any part of project labels Mar 15, 2022
@per1234 per1234 requested review from silvanocerza and umbynos March 15, 2022 22:11
@per1234 per1234 self-assigned this Mar 15, 2022
@per1234 per1234 merged commit 9145f6a into arduino:main Mar 16, 2022
@per1234 per1234 deleted the on-demand-go-list branch March 16, 2022 10:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: infrastructure Related to project infrastructure type: imperfection Perceived defect in any part of project
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants