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:

  1. Open rules.json.
  2. Add a new JSON object to the array.
  3. Set directory to the directory to search, relative to base-dir.
  4. Set file to the filename or filename pattern to match.
  5. Set find to the text pattern that currently matches the old Go version.
  6. Set replace to the new text, using GO_FULL_VERSION or GO_SHORT_VERSION as needed.
  7. Set find_recursive: true only if files may appear in subdirectories.
  8. Set go_mod_tidy: true only for go.mod or go.work rules 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:

Use GO_SHORT_VERSION when the destination file should contain only the major and minor version, such as 1.23.

Typical examples:

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

Current built-in rules

The built-in rules.json updates:

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: "...".