Description

The "target" stage applies the value retrieved by a source to a "resource", such as a file in a Git repository. It is the only stage allowed to modify something, and it runs only once every condition succeeded.

A target reports one of three outcomes:

  • success - the resource already holds the expected value, nothing to do

  • attention - the resource is out of date. In diff mode Updatecli only reports the change, in apply mode it writes it

  • failure - the target could not be evaluated

When a target is attached to an scmid, applying a change also commits it and pushes it to the configured branch, which in turn triggers the actions depending on that scm.

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”.
dependsonchangeboolean
deprecatedconditionidsarray
disableconditionsboolean
disablesourceinputboolean
kindstringkind specifies the targets resource kind
namestringname specifies the resource name
scmidstringscmid specifies the scm configuration key associated to the current resource
sourceidstring
specobjectspec specifies parameters for a specific targets kind
transformersarraytransformers defines how the default input value need to be transformed
    addprefixstringAddPrefix adds a prefix to the transformer input value
    addsuffixstringAddSuffix adds a suffix to the transformer input value
    findstringFind searches for a specific value if it exists and return false if it doesn’t
    findsubmatchobjectFind searches for a specific value if it exists then return the value using regular expression[pattern]
    jsonmatchobject[key]
    quotebooleanQuote add quote around the value
    replacerobjectReplacer specifies what value needs to be changed and how[from to]
    replacersarrayReplacers specifies a list of replacer instruction
    semverincstringSemvVerInc specifies a comma separated list semantic versioning component that needs to be upgraded.
    trimprefixstringTrimPrefix removes a prefix to the transformer input value
    trimsuffixstringTrimSuffix removes the suffix from the transformer input value
    unquotebooleanUnquote remove quotes around the value

Source input

By default, a target consumes the output of a source:

  • when the manifest defines exactly one source, that source is used automatically

  • when the manifest defines more than one source, sourceid becomes mandatory

  • setting disablesourceinput: true runs the target without a source value. The target spec must then carry its own value, typically built with {{ source "id" }} templating

Note
disablesourceinput: true also hides source information, such as the changelog, from the actions that follow. A github/pullrequest action will not be able to render the changelog of a target whose source input is disabled.

Conditions

A target waits for all the conditions of the manifest and is skipped as soon as one of them does not succeed. To narrow that down, set disableconditions: true and declare the relevant conditions explicitly:

targets:
  default:
    kind: yaml
    disableconditions: true
    dependson:
      - condition#dockerImageExists
    spec:
      file: values.yaml
      key: $.image.tag

Chaining targets with dependsonchange

dependson only requires the depended-on resource to succeed. Adding dependsonchange: true narrows it further: the target runs only if the targets it depends on actually changed something.

This is how you express "only bump the changelog if the version file was really updated":

targets:
  version:
    name: Update the version file
    kind: file
    spec:
      file: VERSION

  changelog:
    name: Add a changelog entry
    kind: file
    # Only run when the "version" target modified something
    dependson:
      - version
    dependsonchange: true
    spec:
      file: CHANGELOG.md
Note
Inside dependson, an entry without a <category># prefix refers to a resource of the same category, so version above means target#version.

Examples

Update a YAML key from a GitHub release

name: "deps: bump Updatecli version"

sources:
  updatecli:
    name: Get the latest Updatecli version
    kind: githubrelease
    spec:
      owner: updatecli
      repository: updatecli
      token: '{{ requiredEnv "GITHUB_TOKEN" }}'
      versionfilter:
        kind: semver
    transformers:
      - trimprefix: "v"

targets:
  chart:
    name: 'deps: bump Updatecli version to {{ source "updatecli" }}'
    kind: yaml
    sourceid: updatecli
    scmid: default
    spec:
      file: charts/updatecli/values.yaml
      key: $.image.tag

Update several files with the same value

A target kind that accepts a files key updates every listed file in one go, and reports a single change.

targets:
  dockerfiles:
    name: 'deps: bump Golang version to {{ source "golang" }}'
    kind: dockerfile
    scmid: default
    spec:
      files:
        - Dockerfile
        - test/Dockerfile
      instruction:
        keyword: ARG
        matcher: GOLANG_VERSION

Go Further

  • To know more about the value a target receives source

  • To know more about gating targets condition

  • To know more about execution order manifest order

  • To know more about what happens after a change action