Skip to content

Commit 9885736

Browse files
authored
bump Go, add updatecli to do it automatically (#127)
* bump Go, add updatecli to do it automatically Signed-off-by: Brian Downs <brian.downs@gmail.com> * update Go version Signed-off-by: Brian Downs <brian.downs@gmail.com> * update Go version Signed-off-by: Brian Downs <brian.downs@gmail.com> --------- Signed-off-by: Brian Downs <brian.downs@gmail.com>
1 parent 31ef5b8 commit 9885736

4 files changed

Lines changed: 149 additions & 1 deletion

File tree

.github/workflows/updatecli.yml

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
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/main'
19+
steps:
20+
- name: Checkout
21+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
22+
with:
23+
fetch-depth: 0
24+
25+
- name: Install Go
26+
uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6
27+
with:
28+
go-version: 'stable'
29+
30+
- name: Install Updatecli
31+
uses: updatecli/updatecli-action@e71be7554f3f940bc439cf720b3e4e379823c562 # v3.2.0
32+
33+
- name: Delete leftover UpdateCLI branches
34+
run: |
35+
gh pr list \
36+
--search "is:closed is:pr head:updatecli_" \
37+
--json headRefName \
38+
--jq ".[].headRefName" | sort -u > closed_prs_branches.txt
39+
gh pr list \
40+
--search "is:open is:pr head:updatecli_" \
41+
--json headRefName \
42+
--jq ".[].headRefName" | sort -u > open_prs_branches.txt
43+
for branch in $(comm -23 closed_prs_branches.txt open_prs_branches.txt); do
44+
if (git ls-remote --exit-code --heads origin "$branch"); then
45+
echo "Deleting leftover UpdateCLI branch - $branch";
46+
git push origin --delete "$branch";
47+
fi
48+
done
49+
env:
50+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
51+
52+
- name: Apply Updatecli
53+
# Never use '--debug' option, because it might leak the access tokens.
54+
run: "updatecli apply --clean --config ./updatecli/updatecli.d/ --values ./updatecli/values.yaml"
55+
env:
56+
UPDATECLI_GITHUB_ACTOR: ${{ github.actor }}
57+
UPDATECLI_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

package/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM rancher/hardened-build-base:v1.25.11b1 AS builder
1+
FROM rancher/hardened-build-base:v1.26.5b1 AS builder
22

33
ARG TAG=''
44
ARG REPO=''
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
---
2+
name: "Update build base version"
3+
4+
sources:
5+
# Read the current version from the Dockerfile
6+
current_minor:
7+
name: Get current build base minor version from Dockerfile
8+
kind: dockerfile
9+
spec:
10+
file: Dockerfile
11+
instruction:
12+
keyword: ARG
13+
matcher: GO_IMAGE
14+
transformers:
15+
# Value is "rancher/hardened-build-base:v1.24.9b1"
16+
# Trim prefix to get "v1.24.9b1"
17+
- trimprefix: "rancher/hardened-build-base:"
18+
# Trim 'v' prefix to get "1.24.9b1"
19+
- trimprefix: "v"
20+
# This regex captures the major.minor to get "1.24"
21+
# but it will be a list that will be handled in the next step
22+
- findsubmatch:
23+
pattern: '^([0-9]+\.[0-9]+)'
24+
# Select the last element from the list
25+
- kind: lastelement
26+
27+
# Find the latest release matching that minor version
28+
latest_patch:
29+
name: Get latest build base patch for that minor
30+
kind: githubrelease
31+
dependson:
32+
- "current_minor"
33+
spec:
34+
owner: rancher
35+
repository: image-build-base
36+
token: '{{ requiredEnv .github.token }}'
37+
typefilter:
38+
release: true
39+
draft: false
40+
prerelease: false
41+
versionfilter:
42+
kind: regex
43+
# This searches for tags "v1.24.*"
44+
# using the "1.24" value from the 'current_minor' source
45+
pattern: 'v{{ source "current_minor" }}\.\S+'
46+
47+
targets:
48+
dockerfile:
49+
name: "Bump to latest build base version in Dockerfile"
50+
kind: dockerfile
51+
scmid: default
52+
sourceid: latest_patch
53+
spec:
54+
file: Dockerfile
55+
instruction:
56+
keyword: ARG
57+
matcher: "GO_IMAGE"
58+
transformers:
59+
- addprefix: "rancher/hardened-build-base:"
60+
61+
scms:
62+
default:
63+
kind: github
64+
spec:
65+
token: '{{ requiredEnv .github.token }}'
66+
username: '{{ requiredEnv .github.username }}'
67+
user: '{{ .github.user }}'
68+
email: '{{ .github.email }}'
69+
owner: '{{ .github.owner }}'
70+
repository: '{{ .github.repository }}'
71+
branch: '{{ .github.branch }}'
72+
73+
actions:
74+
default:
75+
title: 'Bump build base version to {{ source "latest_patch" }}'
76+
kind: github/pullrequest
77+
spec:
78+
automerge: false
79+
labels:
80+
- chore
81+
- skip-changelog
82+
- status/auto-created
83+
scmid: default

updatecli/values.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
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+
repository: "scc-operator"
7+
branch: "main"
8+
owner: "rancher"

0 commit comments

Comments
 (0)