Skip to content

Commit

Permalink
Merge pull request #166 from matttrach/auto-dependency-update-7040
Browse files Browse the repository at this point in the history
Lay groundwork for using updatecli
  • Loading branch information
matttrach authored Mar 31, 2023
2 parents f9a7545 + 2e007ae commit f185b8f
Show file tree
Hide file tree
Showing 8 changed files with 189 additions and 6 deletions.
13 changes: 12 additions & 1 deletion .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,15 @@ updates:
- package-ecosystem: "docker"
directory: "/"
schedule:
interval: "weekly"
interval: "weekly"

- package-ecosystem: "docker"
directory: "/package"
schedule:
interval: "weekly"

# Maintain dependencies for GitHub Actions
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"
55 changes: 55 additions & 0 deletions .github/workflows/updatecli.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: "Updatecli: Dependency Management"

on:
schedule:
# Runs at 06 PM UTC
- cron: '0 18 * * *'
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

permissions:
contents: write
issues: write
pull-requests: write

jobs:
updatecli:
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/master'
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Install Go
uses: actions/setup-go@v3
with:
go-version: 'stable'

- name: Install Updatecli
uses: updatecli/updatecli-action@v2

- name: Delete leftover UpdateCLI branches
run: |
gh pr list \
--search "is:closed is:pr head:updatecli_" \
--json headRefName \
--jq ".[].headRefName" | sort -u > closed_prs_branches.txt
gh pr list \
--search "is:open is:pr head:updatecli_" \
--json headRefName \
--jq ".[].headRefName" | sort -u > open_prs_branches.txt
for branch in $(comm -23 closed_prs_branches.txt open_prs_branches.txt); do
if (git ls-remote --exit-code --heads origin "$branch"); then
echo "Deleting leftover UpdateCLI branch - $branch";
git push origin --delete "$branch";
fi
done
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Apply Updatecli
# Never use '--debug' option, because it might leak the access tokens.
run: "updatecli apply --clean --config ./updatecli/updatecli.d/ --values ./updatecli/values.yaml"
env:
UPDATECLI_GITHUB_ACTOR: ${{ github.actor }}
UPDATECLI_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4 changes: 4 additions & 0 deletions .golangci.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
{
"linters": "revive",
"text": "should have comment"
},
{
"linters": "revive",
"text": "unused-parameter"
}
]
}
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile.dapper
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ RUN GOPROXY=direct go install golang.org/x/tools/cmd/goimports@gopls/v0.9.5
RUN rm -rf /go/src /go/pkg

RUN if [ "${ARCH}" == "amd64" ]; then \
curl -sL https://raw.githubusercontent.com/golangci/golangci-lint/v1.50.0/install.sh | sh -s; \
curl -sL https://raw.githubusercontent.com/golangci/golangci-lint/v1.52.2/install.sh | sh -s; \
fi

ENV DAPPER_RUN_ARGS --privileged -v kine-cache:/go/src/github.com/k3s-io/kine/.cache
Expand Down
7 changes: 3 additions & 4 deletions pkg/logstructured/sqllog/sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,11 +149,10 @@ outer:
// last iteration because another client has compacted, or the requested revision has already been compacted.
if err == server.ErrCompacted {
break
} else {
logrus.Errorf("Compact failed: %v", err)
metrics.CompactTotal.WithLabelValues(metrics.ResultError).Inc()
continue outer
}
logrus.Errorf("Compact failed: %v", err)
metrics.CompactTotal.WithLabelValues(metrics.ResultError).Inc()
continue outer
}
}

Expand Down
79 changes: 79 additions & 0 deletions updatecli/updatecli.d/updatecli.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# This small test makes sure that updatecli is working properly on a repo.
# In the future, more useful files should be added to this directory.
---
name: "Introduce updatecli to repo and validate basic functionality"
# Make sure we can pull in github repos from multiple orgs
scms:
kine:
kind: "github"
spec:
user: "{{ .github.user }}"
email: "{{ .github.email }}"
username: "{{ requiredEnv .github.username }}"
token: '{{ requiredEnv .github.token }}'
owner: "{{ .kine.org }}"
repository: "{{ .kine.repo }}"
branch: "{{ .kine.branch }}"
go:
kind: "github"
spec:
user: "{{ .github.user }}"
email: "{{ .github.email }}"
username: "{{ requiredEnv .github.username }}"
token: '{{ requiredEnv .github.token }}'
owner: "{{ .go.org }}"
repository: "{{ .go.repo }}"
branch: "{{ .go.branch }}"

sources:
# validate gittag parsing external public repos
goTag:
name: "Get Go 1.20.2 tag"
kind: "gittag"
scmid: "go"
spec:
versionfilter:
kind: "regex"
pattern: '^go1\.20\.2$'
transformers:
- trimprefix: "go"

# Validate read access to local repo
## continue to targets if the go version in the validate file doesn't match the goTag source
conditions:
testVersionShouldMatchGoTag:
name:
kind: yaml
sourceid: goTag
spec:
file: "updatecli/validate.yml"
key: version
failwhen: true #if set to true, continue to targets when condition is true rather than false

# Validate the ability to generate branches, commits, what the commits look like, and what branches look like
## allow validation of workflow to delete unused branch after merge
## generate a commit on a branch named updatecli_<256 sha of change>
## the commit message will be automatically generated by updatecli based on the change
targets:
updateValidateFile:
name: "Update the version in the validate file"
kind: "yaml"
scmid: "kine"
sourceid: goTag
spec:
file: "updatecli/validate.yml"
key: version

# Validate generating a pull request
actions:
# create a pull request which is not allowed to automerge
# the title matches the commit message
github:
kind: "github/pullrequest"
scmid: "kine"
spec:
automerge: false
draft: false
mergemethod: squash
parent: false # this would allow for making a PR to an upstream fork, if we ran updatecli from a fork

2 changes: 2 additions & 0 deletions updatecli/validate.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
version: go1.20.1
33 changes: 33 additions & 0 deletions updatecli/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
github:
user: "github-actions[bot]"
email: "41898282+github-actions[bot]@users.noreply.github.com"
username: "UPDATECLI_GITHUB_ACTOR"
token: "UPDATECLI_GITHUB_TOKEN"
k3s:
org: "k3s-io"
repo: "k3s"
branch: "master"
kine:
org: "k3s-io"
repo: "kine"
branch: "master"
go:
org: "golang"
repo: "go"
branch: "master"
klipper_helm:
org: "k3s-io"
repo: "klipper-helm"
branch: "master"
klipper_lb:
org: "k3s-io"
repo: "klipper-lb"
branch: "master"
local_path_provisioner:
org: "rancher"
repo: "local-path-provisioner"
branch: "master"
helm_controller:
org: "k3s-io"
repo: "helm-controller"
branch: "master"

0 comments on commit f185b8f

Please sign in to comment.