diff --git a/updatecli/policies/updatecli/githubaction/CHANGELOG.md b/updatecli/policies/updatecli/githubaction/CHANGELOG.md new file mode 100644 index 0000000..14b033f --- /dev/null +++ b/updatecli/policies/updatecli/githubaction/CHANGELOG.md @@ -0,0 +1,5 @@ +# Changelog + +## 0.1.0 + +* Introduce a new version of the policy diff --git a/updatecli/policies/updatecli/githubaction/Policy.yaml b/updatecli/policies/updatecli/githubaction/Policy.yaml new file mode 100644 index 0000000..149a83a --- /dev/null +++ b/updatecli/policies/updatecli/githubaction/Policy.yaml @@ -0,0 +1,14 @@ +authors: + - Olblak + +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. diff --git a/updatecli/policies/updatecli/githubaction/README.md b/updatecli/policies/updatecli/githubaction/README.md new file mode 100644 index 0000000..19c491b --- /dev/null +++ b/updatecli/policies/updatecli/githubaction/README.md @@ -0,0 +1,3 @@ +# README + +This policy updates GitHub Action workflows with the latest Updatecli version diff --git a/updatecli/policies/updatecli/githubaction/testdata/values.yaml b/updatecli/policies/updatecli/githubaction/testdata/values.yaml new file mode 100644 index 0000000..0f4131c --- /dev/null +++ b/updatecli/policies/updatecli/githubaction/testdata/values.yaml @@ -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" diff --git a/updatecli/policies/updatecli/githubaction/updatecli.d/action-version.yaml b/updatecli/policies/updatecli/githubaction/updatecli.d/action-version.yaml new file mode 100644 index 0000000..a6f6a5c --- /dev/null +++ b/updatecli/policies/updatecli/githubaction/updatecli.d/action-version.yaml @@ -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 diff --git a/updatecli/policies/updatecli/githubaction/updatecli.d/action.yaml b/updatecli/policies/updatecli/githubaction/updatecli.d/action.yaml new file mode 100644 index 0000000..d76c684 --- /dev/null +++ b/updatecli/policies/updatecli/githubaction/updatecli.d/action.yaml @@ -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 diff --git a/updatecli/policies/updatecli/githubaction/values.yaml b/updatecli/policies/updatecli/githubaction/values.yaml new file mode 100644 index 0000000..dc88cf3 --- /dev/null +++ b/updatecli/policies/updatecli/githubaction/values.yaml @@ -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: "*"