sourceconditiontarget

Description

The toolversions resource reads and writes one entry in a .tool-versions file, the version manifest used by asdf and mise, where each line pairs a tool name with one or more versions:

nodejs 20.11.0
golang 1.22.0
terraform 1.7.4
source

Returns the version recorded for key.

condition

Checks that the entry holds value, or the source output when value is unset.

target

Updates that entry. Files already holding the value are reported as up to date and left untouched.

Parameters

NameTypeDescriptionRequired
createmissingkeyboolean[t] CreateMissingKey allows non-existing keys. If the key does not exist, the key is created if AllowsMissingKey is true, otherwise an error is raised (the default). Only supported if Key is used
filestring[s][c][t] File specifies the .tool-versions file to manipulate
filesarray[c][t] Files specifies a list of .tool-versions file to manipulate
keystring[s][c][t] Key specifies the query to retrieve an information from a .tool-versions file
valuestring[s][c][t] Value specifies the value for a specific key. Default to source output

file or files is mandatory, as is key; missing either aborts the run with wrong spec content, preceded by .tool-versions file undefined or tool-versions key undefined. file and files are mutually exclusive.

key

The tool name as it appears at the start of the line (golang, not a path expression).

value

Defaults to the source output.

createmissingkey

Target only. Appends the tool when the file does not mention it yet, instead of failing. Unlike the "TOML" resource, there is no engine restriction on it.

Remote files

For a source and a condition, file accepts https://, http:// and file://. A target must write locally and refuses a URL.

Example

# updatecli.yaml
name: Basic .tool-versions Example

scms:
  default:
    kind: git
    spec:
      url: https://github.com/asdf-vm/asdf.git

sources:
  local:
    name: Get value from .tool-versions
    kind: toolversions
    scmid: default
    spec:
      file: .tool-versions
      key: bats
  http:
    name: Get value from .tool-versions
    kind: toolversions
      file: https://raw.githubusercontent.com/updatecli/updatecli/master/pkg/plugins/resources/toolversions/testdata/.tool-versions
      key: bats

conditions:
  local:
    name: Test value from .tool-versions
    kind: toolversions
    sourceid: local
    scmid: default
    spec:
      file: .tool-versions
      path: bats
  http:
    name: Test value from .tool-versions
    kind: toolversions
    disablesourceinput: true
    spec:
      file: https://raw.githubusercontent.com/updatecli/updatecli/master/pkg/plugins/resources/toolversions/testdata/.tool-versions
      path: bats
      value: "1.0.0"

targets:
  local:
    name: Ensure bats is set to "1.8.2" in the .tool-versions file
    kind: toolversions
    sourceid: local
    scmid: default
    spec:
      file: .tool-versions
      key: bats
      value: "1.8.2"