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

NameTypeDescriptionRequired
ownerstring[s][c] Owner specifies repository owner
repositorystring[s][c] Repository specifies the name of a repository for a specific owner
tagstring[c] Tag allows to check for a specific release tag, default to source output
tokenstring[s][c] Token specifies the credential used to authenticate with
typefilterobject[s][c] TypeFilter specifies the GitHub Release type to retrieve before applying the versionfilter rule
    draftboolean“Draft” enable/disable GitHub draft release
    latestboolean“Latest” if set to true will only filter the release flag as latest.
    prereleaseboolean“PreRelease” enable/disable GitHub PreRelease
    releaseboolean“Release” enable/disable GitHub release
urlstring[s][c] URL specifies the default github url in case of GitHub enterprise
usernamestring[s][c] Username specifies the username used to authenticate with GitHub API
versionfilterobject[s] VersionFilter provides parameters to specify version pattern and its type like regex, semver, or just latest.
    kindstringspecifies the version kind such as semver, regex, or latest
    patternstringspecifies the version pattern according the version kind
    strictbooleanstrict enforce strict versioning rule. Only used for semantic versioning at this time

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"
      versionFilter:
        kind: semver
        pattern: "~1.10"

⇒ 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.yaml
sources:
  lastRelease:
    kind: githubRelease
    spec:
      owner: "jenkins-infra"
      repository: "jenkins-wiki-exporter"
      token: "{{ requiredEnv "ENV_VARIABLE" }}"
      username: "john"
      versionFilter:
        kind: regexp
        pattern: "v1.10\.(.*)"

⇒ Return v1.10.3

Example

# updatecli.yaml
name: Github Release Example

# Scms defines Git repository configuration to interact with.
scms:
  default:
    kind: github
    spec:
      user: "updatecli"
      email: "updatecli@olblak.com"
      owner: "olblak"
      repository: "charts"
      token: '{{ requiredEnv "GITHUB_TOKEN" }}'
      username: "olblak"
      branch: "master"

# Sources are responsible for retrieving information from thirds location like GitHub releases.
sources:
  # Retrieve the "latest" Helm version using the Helm GitHub Release.
  helm:
    name: Get latest Helm release version
    kind: githubrelease
    spec:
      owner: "helm"
      repository: "helm"
      token: '{{ requiredEnv .github.token }}'
      username: olblak
      versionfilter:
        kind: latest

# Conditions are simple checks that need to pass before updating a target.
conditions:
  # The yaml plugin doesn't support advanced yamlpath syntax so when we need
  # to fetch information from an array, we want to be sure that the position is 
  # still relevant to the target
  keyExist:
    name: Update GitHub Action workflow
    kind: yaml
    scmid: default
    disablesourceinput: true
    spec:
      file: .github/workflows/helm.yaml
      key: .$jobs.release.steps[0].name
      value: Install Helm

# Targets define the state of files based on source information.
targets:
  # Ensure the Dockerfile arg HELM_VERSION is set to the latest Helm version retrieved by the source.
  dockerfile:
    name: Update Dockerfile ARG HELM_VERSION
    kind: dockerfile
    scmid: default
    sourceid: helm
    spec:
      file: docker/Dockerfile
      instruction:
        keyword: ARG
        matcher: HELM_VERSION

  # Ensure the GitHub workflow file is correctly set to the latest helm version retrieved from the source.
  ghWorkflow:
    name: Update GitHub Action workflow
    kind: yaml
    scmid: default
    sourceid: helm
    spec:
      file: .github/workflows/helm.yaml
      key: .$jobs.release.steps[0].with.version

actions:
  # If one of the two targets is modified, then we want to open a
  # pullrequest with the auto merge flag set to true and the label "helm"
  default:
    kind: github/pullrequest
    scmid: default
    title: 'Bump Helm version to {{ source "helm" }}'
    spec:
      automerge: true
      labels:
        - "helm"
Top