Github Release

kind: githubRelease

sourceconditiontarget

Description

source

The GitHub Release "source" retrieves the latest release version sorted by release date. If no release can be found then we fallback to release tags sorted on tag date creation. It’s important to notice that both information are mutually exclusive.

Parameter

NameRequiredDefaultDescription

owner

-

Define Github repository owner

repository

-

Define Github repository name.

token

-

Define the token needed to authenticate with the docker registry

url

github.com

Define github url

version

source output

Deprecated Define Github Release version.

versionFilter

Provide version filtering information

versionFilter.kind

"latest"

VersionFilter.kind accept on of the following values: ["semver","latest","regex"]

versionFilter.pattern

The default pattern value depends on the version kind

VersionFilter

versionFilter allows to specify the kind of version retrieved from a resource and its version pattern. Default value is "latest" as we want to retrieve the newest version from a resource.

latest

If kind is set to latest then no need to specify the patter as we gonna retrieve the newest version from the resource.

Example
sources:
  kubectl:
    kind: githubRelease
    spec:
      owner: "kubernetes"
      repository: "kubectl"
      token: "{{ requiredEnv .github.token }}"
      username: "john"
      versionFilter:
        kind: latest
    transformers:
      - trimPrefix: "kubernetes-"

Return the latest Github release and remove "kubernetes-" from it.

regex

If versionFilter.kind is set to regex then we can use versionFilter.pattern to specify a regular expression to return the newest version returned from a resource matching the regex If no versionFilter.pattern is provided then it uses '.*' which return the newest version

sources:
  kubectl:
    kind: githubRelease
    spec:
      owner: "kubernetes"
      repository: "kubectl"
      token: "{{ requiredEnv .github.token }}"
      username: "john"
      versionFilter:
        kind: regex
        pattern: "kubernetes-1.(\d*).(\d*)$"
    transformers:
      - trimPrefix: "kubernetes-"

⇒ Return the newest kubectl version matching pattern "kubernetes-1.(\d*).(\d*)$" and remove "kubernetes-" from it

semver

If versionFilter.kind is set to semver then we can use versionFilter.pattern to specify version pattern as explained here. In the process we also sort. If no versionFilter.pattern is provided then it fallback to '*' which return the newest version. If a version doesn’t respect semantic versioning, then it’s not the value is just ignored.

Remark

In the process we drop any characters not respecting semantic version like in this version "v1.0.0", we drop the "v" but we can added it back using transformers.

example
  jenkins-wiki-exporter:
    kind: githubRelease
    spec:
      owner: "jenkins-infra"
      repository: "jenkins-wiki-exporter"
      token: "{{ requiredEnv .github.token }}"
      username: "john"
      version: "~1.10"
      versioning:
        kind: semver
    transformers:
      - addPrefix: "v"

⇒ Return the version "v1.10.3"

Remark:

It’s considered a very bad practice to store credentials in an un-encrypted file. Consider using an environment variable to store the token.

source:
  kind: githubRelease
  spec:
    owner: "jenkins-infra"
    repository: "jenkins-wiki-exporter"
    token: "{{ requiredEnv "ENV_VARIABLE" }}"
    username: "john"
    version: "v1.10"

⇒ Return v1.10.3

Example

updatecli.yaml
source:
  name: Get Latest helm release version
  kind: githubRelease
  spec:
    owner: "helm"
    repository: "helm"
    token: {{ requiredEnv .github.token }}
    username: olblak
    version: latest
conditions:
  isENVSet:
    name: Is ENV HELM_VERSION set
    kind: dockerfile
    spec:
      file: docker/Dockerfile
      Instruction: ENV[1][0]
      Value: "HELM_VERSION"
    scm:
      github:
        user: "updatecli"
        email: "updatecli@olblak.com"
        owner: "olblak"
        repository: "charts"
        token: {{ requiredEnv "GITHUB_TOKEN" }}
        username: "olblak"
        branch: "master"
targets:
  updateENVHELMVERSION:
    name: Update HELM_VERSION
    kind: dockerfile
    spec:
      file: docker/Dockerfile
      Instruction: ENV[1][1]
    scm:
      github:
        user: "updatecli"
        email: "updatecli@olblak.com"
        owner: "olblak"
        repository: "charts"
        token: {{ requiredEnv "GITHUB_TOKEN" }}
        username: "olblak"
        branch: "master"

What it says:

Source

Retrieve the latest helm version from its Github release located on https://github.com/helm/helm ⇒ v3.4.2

Conditions

Then it tests one condition: If the dockerfile 'docker/Dockerfile' is located on the git repository https://github.com/olblak/charts has the instruction ENV[1][0] set to "HELM_VERSION". ENV[1][0] is a custom syntax to represent a two-dimensional array where the first element represents a specific Dockerfile instruction identifier starting from "0" at the beginning of the document, so we are looking for the second INSTRUCTION "ENV". The second element represents an instruction argument position. In this case, we want to check that ENV key is set to "HELM_VERSION"

Targets

If the condition is met, which is to be sure that the ENV key set to "HELM_VERSION" exist, then we’ll are going to update its value if needed based on the version retrieved from the source. The syntax is the same for the condition excepted that this time we are looking for ENV[1][1] which means that the second argument of the second ENV instruction.

Edit this page on GitHub