GitHub Action

Automate Updatecli with GitHub Action

Description

Updatecli is most effective when executed regularly and automatically. So, lets see how to use updatecli in a GitHub Action.

Migration

From V1 to v2

The updatecli action v1 was a "GitHub Action" of type docker. While it was easier to start with, that type of GitHub Action runs in a docker container and so in a fully isolated environment. Updatecli uses many other tools. So switching to a Javascript GitHub action, allows installing updatecli directly on the GitHub Action runner next to those other tools. Now, the goal of this GitHub action evolved from running updatecli to installing updatecli.

Parameter

Version

version: specifies the Updatecli version to install. Accepted values are any valid releases such as v0.25.0. The default value corresponds to the latest Updatecli version

Required: false

Example

The current example takes uses the repository jenkins-infra/jenkins-infra.

Once you have your update strategy configuration in the directory ./updatecli/updatecli.d, you need following files in order to run updatecli from Github Action.

./updatecli/values.yaml

---
github:
  user: "GitHub Actions Bot"
  email: "bots@udpatecli.io"
  username: "github-actions"
  token: "UPDATECLI_GITHUB_TOKEN"

./github/workflows/updatecli.yaml

---
name: Updatecli

on:
  # Trigger Updatecli if a new commit land on the main branch
  push:
    branches: [main]
  # Trigger Updatecli if a pullrequest is open targeting the main branch.
  # This is useful to test Updatecli manifest change
  pull_request:
    branches: [main]
  # Manually trigger Updatecli via GitHub UI
  workflow_dispatch:
  # Trigger Updatecli once day by a cronjob
  schedule:
    # * is a special character in YAML so you have to quote this string
    # Run once a day 
    - cron: '0 0 * * *'

permissions:
  contents: "write"
  pull-requests: "write"

jobs:
  updatecli:
    runs-on: "ubuntu-latest"
    steps:
      - name: Checkout
        uses: actions/checkout@v2

      - name: Install Updatecli in the runner
        uses: updatecli/updatecli-action@v2

      - name: Run Updatecli in Dry Run mode
        run: "updatecli diff --config ./updatecli/updatecli.d --values updatecli/values.yaml"
        env:
          UPDATECLI_GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"

      - name: Run Updatecli in apply mode
        run: "updatecli apply --config ./updatecli/updatecli.d --values updatecli/values.yaml"
        env:
          UPDATECLI_GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
Important
Environment variables starting with GITHUB_ are reserved by GitHub Actions.
Top