diff --git a/updatecli/scripts/update-flannel.sh b/updatecli/scripts/update-flannel.sh new file mode 100755 index 000000000..9197f539d --- /dev/null +++ b/updatecli/scripts/update-flannel.sh @@ -0,0 +1,24 @@ +#!/bin/bash +if [ -n "$FLANNEL_VERSION" ]; then + app_version=$(echo "$FLANNEL_VERSION" | grep -Eo 'v[0-9]+.[0-9]+.[0-9+]') + current_flannel_version=$(sed -nr 's/^\+ tag: ('v[0-9]+.[0-9]+.[0-9+]')/\1/p' packages/rke2-flannel/generated-changes/patch/values.yaml.patch | head -1) + current_app_version=$(echo "$current_flannel_version" | grep -Eo 'v[0-9]+.[0-9]+.[0-9+]') + if [ "$current_flannel_version" != "$FLANNEL_VERSION" ]; then + echo "Updating Flannel chart to $FLANNEL_VERSION" + if [ "$app_version" != "$current_app_version" ]; then + sed -i "s/ version: .*/ version: $app_version/g" packages/rke2-flannel/generated-changes/patch/Chart.yaml.patch + sed -i "s/- tag: $current_app_version/- tag: $app_version/g" packages/rke2-flannel/generated-changes/patch/values.yaml.patch + sed -i "s/+ tag: $current_flannel_version/+ tag: $FLANNEL_VERSION/g" packages/rke2-flannel/generated-changes/patch/values.yaml.patch + yq -i ".url = \"https://github.com/flannel-io/flannel/releases/download/$app_version/flannel.tgz\" | + .packageVersion = 00" packages/rke2-flannel/package.yaml + else + sed -i "s/+ tag: $current_flannel_version/+ tag: $FLANNEL_VERSION/g" packages/rke2-flannel/generated-changes/patch/values.yaml.patch + package_version=$(yq '.packageVersion' packages/rke2-flannel/package.yaml) + new_version=$(printf "%02d" $(($package_version + 1))) + yq -i ".packageVersion = $new_version" packages/rke2-flannel/package.yaml + fi + GOCACHE='/home/runner/.cache/go-build' GOPATH='/home/runner/go' PACKAGE='rke2-flannel' make prepare + GOCACHE='/home/runner/.cache/go-build' GOPATH='/home/runner/go' PACKAGE='rke2-flannel' make patch + make clean + fi +fi diff --git a/updatecli/updatecli.d/updateflannel.yaml b/updatecli/updatecli.d/updateflannel.yaml new file mode 100644 index 000000000..6f4d25f6c --- /dev/null +++ b/updatecli/updatecli.d/updateflannel.yaml @@ -0,0 +1,58 @@ +--- +name: "Update Flannel version" + +sources: + flannel: + name: Get flannel version + kind: githubrelease + spec: + owner: rancher + repository: image-build-flannel + token: '{{ requiredEnv .github.token }}' + username: '{{ requiredEnv .github.username }}' + typefilter: + latest: true + release: true + draft: false + prerelease: false + versionfilter: + kind: regex + # pattern accepts any semver constraint + pattern: "v[0-9]+.[0-9]+.[0-9]+-build[0-9]+" + +targets: + flannelImage: + name: "Bump to latest flannel version on the chart" + kind: shell + scmid: default + sourceid: flannel + spec: + command: 'updatecli/scripts/update-flannel.sh' + environments: + - name: FLANNEL_VERSION + value: '{{ source "flannel" }}' + + +scms: + default: + kind: github + spec: + token: '{{ requiredEnv .github.token }}' + username: '{{ requiredEnv .github.username }}' + user: '{{ .github.username }}' + email: '{{ .github.email }}' + owner: '{{ .github.owner }}' + repository: '{{ .github.repository }}' + branch: '{{ .github.branch }}' + +actions: + default: + title: 'Update Flannel version to {{ source "flannel" }}' + kind: github/pullrequest + spec: + automerge: false + labels: + - chore + - skip-changelog + - status/auto-created + scmid: default