gomod.star¶
Read and raise the go directive in go.mod files.
load("@fleet//gomod.star", "modules", "go_version", "set_go_version", "requires", "outdated", "set_work_go_version")
| Function | What it does |
|---|---|
modules |
Lists the repo's Go modules. |
go_version |
Reads the version in a go.mod's go directive. |
set_go_version |
Raises the go directive in every go.mod, never lowering it. |
requires |
Reads every module a go.mod requires, in single-line and block form. |
outdated |
Finds the modules that require a dependency below a version. |
set_work_go_version |
Raises the go directive in go.work, never lowering it. |
modules¶
Lists the repo's Go modules.
Arguments
| Name | Description |
|---|---|
repo |
The repo passed to change(repo). |
Returns: The sorted paths of every go.mod outside vendor and testdata directories.
Example
go_version¶
Reads the version in a go.mod's go directive.
Arguments
| Name | Description |
|---|---|
repo |
The repo passed to change(repo). |
path |
The go.mod to read. |
Returns: The version, such as 1.22.1, or None when the file has no go
directive or does not exist.
Example
set_go_version¶
Raises the go directive in every go.mod, never lowering it.
A go.mod without a directive gets one after its module line. A
toolchain line the new version covers is removed; a newer one is kept.
Arguments
| Name | Description |
|---|---|
repo |
The repo passed to change(repo). |
version |
The Go version, such as 1.27.3. |
paths |
The go.mod files to change; every module by default. |
Returns: The list of paths that changed.
Example
Used in: bump-go-version, make-go-version
requires¶
Reads every module a go.mod requires, in single-line and block form.
Arguments
| Name | Description |
|---|---|
repo |
The repo passed to change(repo). |
path |
The go.mod to read. |
Returns: A dict of module path to version, in file order; empty when the file does not exist.
Example
outdated¶
Finds the modules that require a dependency below a version.
Use it to pick where a run step should run go get module@version.
Arguments
| Name | Description |
|---|---|
repo |
The repo passed to change(repo). |
module |
The dependency's module path. |
version |
The version it should be at least, such as v0.33.0. |
Returns: The directories of the matching go.mod files; the repo root is ..
Example
Used in: go-module-bump
set_work_go_version¶
Raises the go directive in go.work, never lowering it.
Arguments
| Name | Description |
|---|---|
repo |
The repo passed to change(repo). |
version |
The Go version, such as 1.27.3. |
Returns: True when the file changed; False when the repo has no go.work.
Example