Skip to content

Commit

Permalink
feat(updatecli): add policy to update githubaction (#16)
Browse files Browse the repository at this point in the history
Signed-off-by: Olivier Vernin <olivier.vernin@suse.com>
  • Loading branch information
olblak authored Dec 4, 2023
1 parent eef3eef commit 62411ea
Show file tree
Hide file tree
Showing 7 changed files with 184 additions and 0 deletions.
5 changes: 5 additions & 0 deletions updatecli/policies/updatecli/githubaction/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Changelog

## 0.1.0

* Introduce a new version of the policy
14 changes: 14 additions & 0 deletions updatecli/policies/updatecli/githubaction/Policy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
authors:
- Olblak <me@olblak.com>

url: "https://github.com/updatecli/policies/"
documentation: "https://github.com/updatecli/policies/tree/main/updatecli/policies/updatecli/githubaction/README.md"
source: "https://github.com/updatecli/policies/tree/main/updatecli/policies/updatecli/githubaction/"
version: 0.1.0
vendor: Updatecli Project

licenses:
- "Apache-2.0 license"

description: |
Automatically update the Updatecli version used by GitHub action workflows.
3 changes: 3 additions & 0 deletions updatecli/policies/updatecli/githubaction/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# README

This policy updates GitHub Action workflows with the latest Updatecli version
10 changes: 10 additions & 0 deletions updatecli/policies/updatecli/githubaction/testdata/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
scm:
enabled: true
user: updatecli-bot
email: updatecli-bot@updatecli.io
owner: updatecli
repository: website
username: "updatecli-bot"
branch: master

versionpattern: ">=0.0.0-0"
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
---
# Helpers
# {{ $GitHubUser := env "GITHUB_ACTOR"}}
# {{ $GitHubRepositoryList := env "GITHUB_REPOSITORY" | split "/"}}
# {{ $GitHubPAT := env "GITHUB_TOKEN"}}
# {{ $GitHubUsername := env "GITHUB_ACTOR"}}}

name : 'deps: Updatecli version used by GitHub action'
pipelineid: '{{ .pipelineid }}'

# Only enable the scm section if Updatecli is executed from a Github Action
# {{ if or (.scm.enabled) (env "GITHUB_REPOSITORY") }}
actions:
default:
title: 'deps: bump Updatecli version to {{ source "updatecli" }}'
kind: "github/pullrequest"
spec:
automerge: {{ .automerge }}
labels:
- "chore"
- "dependencies"
mergemethod: "squash"
scmid: "default"

scms:
default:
kind: "github"
spec:
# Priority set to the environment variable
user: '{{ default $GitHubUser .scm.user }}'
email: '{{ .scm.email }}'
owner: '{{ default $GitHubRepositoryList._0 .scm.owner }}'
repository: '{{ default $GitHubRepositoryList._1 .scm.repository }}'
token: '{{ default $GitHubPAT .scm.token }}'
username: '{{ default $GitHubUsername .scm.username }}'
branch: '{{ .scm.branch }}'
# {{ end }}

sources:
updatecli:
name: "Get latest Updatecli version"
kind: "githubrelease"
spec:
owner: "updatecli"
repository: "updatecli"
token: '{{ default .scm.token $GitHubPAT }}'
username: '{{ default .scm.username $GitHubUsername }}'
versionfilter:
kind: "semver"
pattern: '{{ .versionpattern }}'

targets:
githubaction:
name: 'deps: update Updatecli used by Github Action to {{ source "updatecli" }}'
kind: yaml
spec:
engine: yamlpath
key: '$.jobs.*.steps[?(@.uses =~ /^updatecli\/updatecli-action/)].with.version'
files:
- '.github/workflows/*'
searchpattern: true
# Only enable the scm section if Updatecli is executed from a Github Action
# {{ if or (.scm.enabled) (env "GITHUB_REPOSITORY") }}
scmid: default
# {{ end }}

# Represent the minimum version of Updatecli required to run this policy
version: v0.68.0
70 changes: 70 additions & 0 deletions updatecli/policies/updatecli/githubaction/updatecli.d/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
---
# Helpers
# {{ $GitHubUser := env "GITHUB_ACTOR"}}
# {{ $GitHubRepositoryList := env "GITHUB_REPOSITORY" | split "/"}}
# {{ $GitHubPAT := env "GITHUB_TOKEN"}}
# {{ $GitHubUsername := env "GITHUB_ACTOR"}}}

name : 'deps: bump Updatecli GH action'
pipelineid: '{{ .pipelineid }}'

# Only enable the scm section if Updatecli is executed from a Github Action
# {{ if or (.scm.enabled) (env "GITHUB_REPOSITORY") }}
actions:
default:
title: 'deps: bump Updatecli GitHub action to {{ source "updatecli" }}'
kind: "github/pullrequest"
spec:
automerge: {{ .automerge }}
labels:
- "chore"
- "dependencies"
mergemethod: "squash"
scmid: "default"

scms:
default:
kind: "github"
spec:
# Priority set to the environment variable
user: '{{ default $GitHubUser .scm.user }}'
email: '{{ .scm.email }}'
owner: '{{ default $GitHubRepositoryList._0 .scm.owner }}'
repository: '{{ default $GitHubRepositoryList._1 .scm.repository }}'
token: '{{ default $GitHubPAT .scm.token }}'
username: '{{ default $GitHubUsername .scm.username }}'
branch: '{{ .scm.branch }}'
# {{ end }}

sources:
updatecli:
name: "Get latest Updatecli version"
kind: "githubrelease"
spec:
owner: "updatecli"
repository: "updatecli-action"
token: '{{ default .scm.token $GitHubPAT }}'
username: '{{ default .scm.username $GitHubUsername }}'
versionfilter:
kind: "semver"
pattern: '{{ .versionpattern }}'

targets:
githubaction:
name: 'deps: update Updatecli used by Github Action to {{ source "updatecli" }}'
kind: yaml
disablesourceinput: true
spec:
engine: yamlpath
key: '$.jobs.*.steps[?(@.uses =~ /^updatecli\/updatecli-action/)].uses'
value: 'updatecli/updatecli-action@{{ source "updatecli" }}'
files:
- '.github/workflows/*'
searchpattern: true
# Only enable the scm section if Updatecli is executed from a Github Action
# {{ if or (.scm.enabled) (env "GITHUB_REPOSITORY") }}
scmid: default
# {{ end }}

# Represent the minimum version of Updatecli required to run this policy
version: v0.68.0
14 changes: 14 additions & 0 deletions updatecli/policies/updatecli/githubaction/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
pipelineid: updatecli
automerge: false

scm:
enabled: false
# user: updatecli-bot
# email: updatecli-bot@updatecli.io
# owner: updatecli
# repository: website
# #token: "xxx"
# username: "updatecli-bot"
# branch: main

versionpattern: "*"

0 comments on commit 62411ea

Please sign in to comment.