Description

The "source" stage retrieves information from a third "resource" like a file, or an API and then uses that information in later stages.

A source is the only stage that never modifies anything: it just reads a value, optionally reshapes it with transformers, and hands it over to the conditions and targets of the manifest.

Most sources return a list of candidate versions and pick one according to their versionfilter. See version filter for the available strategies.

Tip
Within a single Updatecli run, sources sharing the same kind, spec, and resolved repository are executed only once, and the result is reused. Naming them differently, or attaching different transformers, does not trigger a second call (which keeps API rate limits under control when many pipelines track the same dependency).

Parameters

NameTypeDescriptionRequired
dependsonarray

“dependson” allows to specify the order of execution of resources. It accepts a list of rules like “(resourceType#)resourceId(:booleanOperator)”.

The resourceType is optional and can be one of “condition”, “source” or “target” By default the resourceType is the current resource type

The resourceId is the name of the resource to depend on

The booleanOperator is optional and can be “AND” or “OR”

examples: dependson: * condition#myCondition:and * source#mySource

remarks:

  • The parameters “sourceid” and “conditionsids” affect the order of resource execution.
  • To avoid circular dependencies, the depended resource may need to remove any conditionids or set “disablesourceinput to true”.
kindstringkind specifies the sources resource kind
namestringname specifies the resource name
scmidstringscmid specifies the scm configuration key associated to the current resource
specobjectspec specifies parameters for a specific sources kind
transformersarraytransformers defines how the default input value need to be transformed
    addprefixstring

“addprefix” defines a prefix added to the value.

example:

  • addprefix: v
    addsuffixstring

“addsuffix” defines a suffix added to the value.

example:

  • addsuffix: -alpine
    findstring

“find” defines a regular expression, and replaces the value with its first match.

remark:

  • when nothing matches, the value becomes empty.

example:

  • find: \d+.\d+.\d+
    findsubmatchobject

“findsubmatch” defines a regular expression, and replaces the value with one of its capture groups.

example:

findsubmatch:
  pattern: 'v(\d+)\.(\d+)'
  captureindex: 1
[pattern]
    jsonmatchobject

“jsonmatch” defines a query extracting a value from a json input.

example:

jsonmatch:
  key: .version
[key]
    quoteboolean

“quote” wraps the value in double quotes.

default: false

remark:

  • special characters in the value are escaped, following Go string syntax.
    replacerobject

“replacer” defines a single replacement applied to the value.

example:

replacer:
  from: "_"
  to: "."
[from to]
    replacersarray

“replacers” defines a list of replacements applied to the value.

remark:

  • all replacements run in a single pass, so a replaced text is never replaced again.

example:

replacers:
  - from: "_"
    to: "."
  - from: "v"
    to: ""
    semverincstring

“semverinc” defines a comma separated list of semantic version components to increment.

remark:

  • accepted components are “major”, “minor” and “patch”, applied in the order given.
  • the value must be a valid semantic version.
  • spaces around the commas are not accepted.

example:

  • semverinc: patch
  • semverinc: minor,patch
    trimprefixstring

“trimprefix” defines a prefix removed from the value.

example:

  • trimprefix: v
    trimsuffixstring

“trimsuffix” defines a suffix removed from the value.

example:

  • trimsuffix: -alpine
    unquoteboolean

“unquote” removes the double quotes around the value.

default: false

Example

Transform source output

updatecli.yaml
sources:
  latestVersion:
    name: Get latest Venom release
    kind: githubrelease
    spec:
      owner: ovh
      repository: venom
      # Value from environment variable '$UPDATECLI_GITHUB_TOKEN'
      token: '{{ requiredEnv "UPDATECLI_GITHUB_TOKEN" }}'
      versionfilter:
        kind: semver
    transformers:
      - trimprefix: "v"

The ovh/venom releases are tagged like v1.2.0, while the value we want to write in a target is 1.2.0. The trimprefix transformer removes the leading v, so the output of this source becomes 1.2.0.

Combine multiple sources

In Updatecli, sources define values (like version numbers) to use in your update logic.

You can combine outputs from multiple sources in a target, a condition, or even another source by using Go templating, like this:

sources:
  appVersion:
    kind: githubrelease
    spec:
      owner: myorg
      repository: myapp

  chartVersion:
    kind: helmchart
    spec:
      name: mychart

targets:
  updateChart:
    name: "Update Helm chart with app and chart versions"
    kind: file
    disablesourceinput: true
    spec:
      file: charts/myapp/Chart.yaml
      matchpattern: "version: .*"
      replacepattern: 'version: {{ source "chartVersion" }}'

Now, if you wanted to use both versions in one target, for example in a file or title, you can do something like this:

replacepattern: 'appVersion: {{ source "appVersion" }}, chartVersion: {{ source "chartVersion" }}'

Here are a few important concepts to understand: By default any condition or target inherites a source output, so we want to disable that behavior by setting disablesourceinput: true.

Combining multiple sources output is useful when:

Another resource needs information from more than one source, like updating multiple versions in the same file or message.

You want to compose a more informative or specific change, like:

image: 'myapp:{{ source "appVersion" }}-{{ source "buildNumber" }}'

PR titles like:

"chore: 'bump app to {{ source "appVersion" }} and chart to {{ source "chartVersion" }}"'