Skip to content

Commit 92f38d5

Browse files
authored
Merge pull request #57 from matttrach/introduce-updatecli-7040
Add updatecli with a basic validation
2 parents 44411e5 + ea56d7e commit 92f38d5

4 files changed

Lines changed: 175 additions & 0 deletions

File tree

.github/workflows/updatecli.yml

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
name: "Updatecli: Dependency Management"
2+
3+
on:
4+
schedule:
5+
# Runs at 06 PM UTC
6+
- cron: '0 18 * * *'
7+
# Allows you to run this workflow manually from the Actions tab
8+
workflow_dispatch:
9+
10+
permissions:
11+
contents: write
12+
issues: write
13+
pull-requests: write
14+
15+
jobs:
16+
updatecli:
17+
runs-on: ubuntu-latest
18+
if: github.ref == 'refs/heads/master'
19+
steps:
20+
- name: Checkout
21+
uses: actions/checkout@v3
22+
23+
- name: Install Go
24+
uses: actions/setup-go@v4
25+
with:
26+
go-version: 'stable'
27+
28+
- name: Install Updatecli
29+
uses: updatecli/updatecli-action@v2
30+
31+
- name: Delete leftover UpdateCLI branches
32+
run: |
33+
gh pr list \
34+
--search "is:closed is:pr head:updatecli_" \
35+
--json headRefName \
36+
--jq ".[].headRefName" | sort -u > closed_prs_branches.txt
37+
gh pr list \
38+
--search "is:open is:pr head:updatecli_" \
39+
--json headRefName \
40+
--jq ".[].headRefName" | sort -u > open_prs_branches.txt
41+
for branch in $(comm -23 closed_prs_branches.txt open_prs_branches.txt); do
42+
if (git ls-remote --exit-code --heads origin "$branch"); then
43+
echo "Deleting leftover UpdateCLI branch - $branch";
44+
git push origin --delete "$branch";
45+
fi
46+
done
47+
env:
48+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
49+
50+
- name: Apply Updatecli
51+
# Never use '--debug' option, because it might leak the access tokens.
52+
run: "updatecli apply --clean --config ./updatecli/updatecli.d/ --values ./updatecli/values.yaml"
53+
env:
54+
UPDATECLI_GITHUB_ACTOR: ${{ github.actor }}
55+
UPDATECLI_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# This small test makes sure that updatecli is working properly on a repo.
2+
# In the future, more useful files should be added to this directory.
3+
---
4+
name: "Introduce updatecli to repo and validate basic functionality"
5+
# Make sure we can pull in github repos from multiple orgs
6+
scms:
7+
klipper-helm:
8+
kind: "github"
9+
spec:
10+
user: "{{ .github.user }}"
11+
email: "{{ .github.email }}"
12+
username: "{{ requiredEnv .github.username }}"
13+
token: '{{ requiredEnv .github.token }}'
14+
owner: "{{ .klipper-helm.org }}"
15+
repository: "{{ .klipper-helm.repo }}"
16+
branch: "{{ .klipper-helm.branch }}"
17+
go:
18+
kind: "github"
19+
spec:
20+
user: "{{ .github.user }}"
21+
email: "{{ .github.email }}"
22+
username: "{{ requiredEnv .github.username }}"
23+
token: '{{ requiredEnv .github.token }}'
24+
owner: "{{ .go.org }}"
25+
repository: "{{ .go.repo }}"
26+
branch: "{{ .go.branch }}"
27+
28+
sources:
29+
# validate gittag parsing external public repos
30+
goTag:
31+
name: "Get Go 1.20.2 tag"
32+
kind: "gittag"
33+
scmid: "go"
34+
spec:
35+
versionfilter:
36+
kind: "regex"
37+
pattern: '^go1\.20\.2$'
38+
39+
# Validate read access to local repo
40+
## continue to targets if the go version in the validate file doesn't match the goTag source
41+
conditions:
42+
testVersionShouldMatchGoTag:
43+
name: test version should match go tag
44+
kind: yaml
45+
sourceid: goTag
46+
spec:
47+
file: "updatecli/validate.yml"
48+
key: version
49+
failwhen: true #if set to true, continue to targets when condition is true rather than false
50+
51+
# Validate the ability to generate branches, commits, what the commits look like, and what branches look like
52+
## allow validation of workflow to delete unused branch after merge
53+
## generate a commit on a branch named updatecli_<256 sha of change>
54+
## the commit message will be automatically generated by updatecli based on the change
55+
targets:
56+
updateValidateFile:
57+
name: "Update the version in the validate file"
58+
kind: "yaml"
59+
scmid: "klipper-helm"
60+
sourceid: goTag
61+
spec:
62+
file: "updatecli/validate.yml"
63+
key: version
64+
65+
# Validate generating a pull request
66+
actions:
67+
# create a pull request which is not allowed to automerge
68+
# the title matches the commit message
69+
github:
70+
kind: "github/pullrequest"
71+
scmid: "klipper-helm"
72+
spec:
73+
automerge: false
74+
draft: false
75+
mergemethod: squash
76+
parent: false # this would allow for making a PR to an upstream fork, if we ran updatecli from a fork

updatecli/validate.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
---
2+
version: go1.20.1
3+

updatecli/values.yml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
github:
2+
user: "github-actions[bot]"
3+
email: "41898282+github-actions[bot]@users.noreply.github.com"
4+
username: "UPDATECLI_GITHUB_ACTOR"
5+
token: "UPDATECLI_GITHUB_TOKEN"
6+
k3s:
7+
org: "k3s-io"
8+
repo: "k3s"
9+
branch: "master"
10+
kine:
11+
org: "k3s-io"
12+
repo: "kine"
13+
branch: "master"
14+
k3s-upgrade:
15+
org: "k3s-io"
16+
repo: "k3s-upgrade"
17+
branch: "master"
18+
go:
19+
org: "golang"
20+
repo: "go"
21+
branch: "master"
22+
klipper-helm:
23+
org: "k3s-io"
24+
repo: "klipper-helm"
25+
branch: "master"
26+
klipper-lb:
27+
org: "k3s-io"
28+
repo: "klipper-lb"
29+
branch: "master"
30+
local-path-provisioner:
31+
org: "rancher"
32+
repo: "local-path-provisioner"
33+
branch: "master"
34+
helm-controller:
35+
org: "k3s-io"
36+
repo: "helm-controller"
37+
branch: "master"
38+
system-agent-installer-k3s:
39+
org: "rancher"
40+
repo: "system-agent-installer-k3s"
41+
branch: "main"

0 commit comments

Comments
 (0)