Rules reference
The action uses rules.json to decide which files to update and how to update them.
Rule fields
Each rule is a JSON object with these fields:
| Field | Required | Description |
|---|---|---|
file |
Yes | File name or pattern passed to find -name. |
directory |
Yes | Directory to search from, relative to base-dir. |
find |
Yes | Pattern passed to sed for replacement. |
replace |
Yes | Replacement string. Can include GO_FULL_VERSION or GO_SHORT_VERSION. |
find_recursive |
No | If true, search subdirectories. If omitted, the search is limited to the configured directory. |
go_mod_tidy |
No | If true, run go mod tidy for matching go.mod files or go work sync for matching go.work files after replacements. |
How to add rules
To add a new built-in rule:
- Open
rules.json. - Add a new JSON object to the array.
- Set
directoryto the directory to search, relative tobase-dir. - Set
fileto the filename or filename pattern to match. - Set
findto the text pattern that currently matches the old Go version. - Set
replaceto the new text, usingGO_FULL_VERSIONorGO_SHORT_VERSIONas needed. - Set
find_recursive: trueonly if files may appear in subdirectories. - Set
go_mod_tidy: trueonly forgo.modorgo.workrules that should trigger Go tooling after replacement.
After adding a rule, run the local test harness or add a targeted test case under testing/ so the new replacement behaviour is covered.
Choosing the replacement value
Use GO_FULL_VERSION when the destination file should contain the full Docker image version, such as 1.23.4.
Typical examples:
- GitHub Actions inputs like
go-version: 1.23.4 - README snippets or badges like
go-v1.23.4 - CI images like
golang:1.23.4
Use GO_SHORT_VERSION when the destination file should contain only the major and minor version, such as 1.23.
Typical examples:
go.modgo.work
Example: add a workflow rule
If a workflow file contains:
go-version: "1.22.7"
add a rule like:
{
"file": "my-workflow.yml",
"directory": ".github/workflows/",
"find": "go-version: \"[0-9.]*\"$",
"replace": "go-version: \"GO_FULL_VERSION\""
}
Example: add a README rule
If a README contains a version badge like:
go-v1.22.7
add a rule like:
{
"file": "README.md",
"directory": ".",
"find": "go-v[0-9.]*",
"replace": "go-vGO_FULL_VERSION"
}
Example: add a recursive go.mod rule
If a repository has multiple modules in subdirectories, use a recursive go.mod rule:
{
"file": "go.mod",
"directory": ".",
"find_recursive": true,
"go_mod_tidy": true,
"find": "^go [0-9.]*$",
"replace": "go GO_SHORT_VERSION"
}
This updates all matching go.mod files and then runs go mod tidy once per changed module directory.
Tips
- Keep
findpatterns narrow enough that they only match the intended Go version line. - Prefer a filename pattern when several files in the same directory share the same version format.
- Use
GO_FULL_VERSIONfor image tags and tool versions. - Use
GO_SHORT_VERSIONforgo.modandgo.worklanguage versions. - If a new file type should be updated in tests, add a fixture under
testing/and extendtesting/run_tests_locally.sh.
Current built-in rules
The built-in rules.json updates:
go.modgo.work- GitHub workflow files under
.github/workflows/that containgo_version: "..." README.md.circleci/config.yml
Placeholder behaviour
Use GO_FULL_VERSION when the target file should contain the full version from the Docker image tag.
Example:
{
"find": "go_version: \"[0-9.]*\"$",
"replace": "go_version: \"GO_FULL_VERSION\""
}
Use GO_SHORT_VERSION when the target file should contain only the major and minor version.
Example:
{
"find": "^go [0-9.]*$",
"replace": "go GO_SHORT_VERSION"
}
Custom rules
To use your own rule set, pass the rules input and point it at a JSON file in the target repository. This replaces the bundled rules.json; rules are not merged. To keep built-in behaviour (such as recursive updates to go.mod and go.work), copy the entries you need from rules.json into the custom file before adding your own rules.
with:
dockerfile: Dockerfile
rules: .github/update-go-rules.json
This is useful when your repository stores the Go version in additional files beyond the defaults covered by the built-in rules.json. The built-in workflow rule already covers .github/workflows/*.yml files that store the version as go_version: "...".