Skip to content

Commit

Permalink
updatecli: create an issue in rancher/rke2 when an updatecli run fails.
Browse files Browse the repository at this point in the history
The script uses a Github App to authenticate to the rke2 repo.
It also checks whether the issue already exists before creating it.
  • Loading branch information
thomasferrandiz committed Dec 3, 2024
1 parent 50fc373 commit 6db484f
Show file tree
Hide file tree
Showing 12 changed files with 85 additions and 2 deletions.
16 changes: 15 additions & 1 deletion .github/workflows/updatecli.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ permissions:
jobs:
updatecli:
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main-source'
# if you want to testupdatecli on another branch, you also need to modify updatecli/values.yaml
if: ${{github.ref == 'refs/heads/main-source' && github.repository == 'rancher/rke2-charts'}}
steps:
- name: Checkout
uses: actions/checkout@v4
Expand All @@ -28,6 +29,16 @@ jobs:
- name: Install Updatecli
uses: updatecli/updatecli-action@v2

- name: Get token
id: get_token
uses: actions/create-github-app-token@5d869da34e18e7287c1daad50e0b8ea0f506ce69 # v1.11.0
with:
app-id: ${{ secrets.CREATE_ISSUE_APP_ID }}
private-key: ${{ secrets.CREATE_ISSUE_PRIVATE_KEY }}
owner: rancher
repositories: |
rke2
- name: Delete leftover UpdateCLI branches
run: |
gh pr list \
Expand All @@ -53,3 +64,6 @@ jobs:
env:
UPDATECLI_GITHUB_ACTOR: ${{ github.actor }}
UPDATECLI_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
UPDATECLI_GITHUB_WORKFLOW_URL: "https://github.com/${{github.repository}}/actions/runs/${{github.run_id}}"
GH_TOKEN: ${{ steps.get_token.outputs.token }}

29 changes: 29 additions & 0 deletions updatecli/scripts/create-issue.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/usr/bin/env bash

TARGET_REPOSITORY="rancher/rke2"
BODY="Url of the failed run: ${UPDATECLI_GITHUB_WORKFLOW_URL}"

report-error() {
exit_code=$?
trap - EXIT INT

if [[ $exit_code != 0 ]]; then
#check if issue already exists
issues=$(gh issue list -R ${TARGET_REPOSITORY} \
--search "is:open ${ISSUE_TITLE}" \
--app rke2-issues-updatecli --json number --jq ".[].number" | wc -l)

if [[ $issues = 0 ]]; then
echo "Creating issue for: $title"
gh issue create -R ${TARGET_REPOSITORY} \
--title "${ISSUE_TITLE}" \
--body "${BODY}"
else
echo "Issue already exists for: ${ISSUE_TITLE}"
fi
fi

exit $exit_code
}

export -f report-error
6 changes: 6 additions & 0 deletions updatecli/scripts/update-calico.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
#!/bin/bash
set -eu

source $(dirname $0)/create-issue.sh

ISSUE_TITLE="Updatecli failed for calico ${CALICO_VERSION}"
trap report-error EXIT INT

if [ -n "$CALICO_VERSION" ]; then
current_calico_version=$(yq '.version' packages/rke2-calico/templates/crd-template/Chart.yaml)
if [ "$current_calico_version" != "$CALICO_VERSION" ]; then
Expand Down
6 changes: 6 additions & 0 deletions updatecli/scripts/update-canal.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
#!/bin/bash
set -eu

source $(dirname $0)/create-issue.sh

ISSUE_TITLE="Updatecli failed for canal ${CALICO_VERSION} / ${FLANNEL_VERSION}"
trap report-error EXIT INT

if [ -n "$FLANNEL_VERSION" ]; then
current_flannel_version=$(yq '.flannel.image.tag' packages/rke2-canal/charts/values.yaml)
if [ "$current_flannel_version" != "$FLANNEL_VERSION" ]; then
Expand Down
6 changes: 6 additions & 0 deletions updatecli/scripts/update-cilium.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
#!/bin/bash
set -eu

source $(dirname $0)/create-issue.sh

ISSUE_TITLE="Updatecli failed for cilium ${CILIUM_VERSION}"
trap report-error EXIT INT

if [ -n "$CILIUM_VERSION" ]; then
current_cilium_version=$(sed -nr 's/^\ version: ('[0-9]+.[0-9]+.[0-9]+')/\1/p' packages/rke2-cilium/generated-changes/patch/Chart.yaml.patch)
if [ "v$current_cilium_version" != "$CILIUM_VERSION" ]; then
Expand Down
6 changes: 6 additions & 0 deletions updatecli/scripts/update-flannel.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
#!/bin/bash
set -eu

source $(dirname $0)/create-issue.sh

ISSUE_TITLE="Updatecli failed for flannel ${FLANNEL_VERSION}"
trap report-error EXIT INT

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)
Expand Down
8 changes: 7 additions & 1 deletion updatecli/scripts/update-multus.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
#!/bin/bash
set -eu
set -eux

source $(dirname $0)/create-issue.sh

ISSUE_TITLE="Updatecli failed for multus ${MULTUS_VERSION}"
trap report-error EXIT INT

if [ -n "$MULTUS_VERSION" ]; then
app_version=$(echo "$MULTUS_VERSION" | grep -Eo '^v*[0-9]+.[0-9]+.[0-9]+' | tr -d 'v')
current_multus_version=$(yq '.image.tag' packages/rke2-multus/charts/values.yaml)
Expand Down
2 changes: 2 additions & 0 deletions updatecli/updatecli.d/updatecalico.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ targets:
- name: CALICO_VERSION
value: '{{ source "calico" }}'
- name: PATH
- name: UPDATECLI_GITHUB_WORKFLOW_URL
- name: GH_TOKEN


scms:
Expand Down
2 changes: 2 additions & 0 deletions updatecli/updatecli.d/updatecanal.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ targets:
- name: CALICO_VERSION
value: '{{ source "calico" }}'
- name: PATH
- name: UPDATECLI_GITHUB_WORKFLOW_URL
- name: GH_TOKEN

scms:
default:
Expand Down
2 changes: 2 additions & 0 deletions updatecli/updatecli.d/updatecilium.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ targets:
- name: CILIUM_VERSION
value: '{{ source "cilium" }}'
- name: PATH
- name: UPDATECLI_GITHUB_WORKFLOW_URL
- name: GH_TOKEN


scms:
Expand Down
2 changes: 2 additions & 0 deletions updatecli/updatecli.d/updateflannel.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ targets:
- name: FLANNEL_VERSION
value: '{{ source "flannel" }}'
- name: PATH
- name: UPDATECLI_GITHUB_WORKFLOW_URL
- name: GH_TOKEN


scms:
Expand Down
2 changes: 2 additions & 0 deletions updatecli/updatecli.d/updatemultus.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ targets:
- name: MULTUS_VERSION
value: '{{ source "multus" }}'
- name: PATH
- name: UPDATECLI_GITHUB_WORKFLOW_URL
- name: GH_TOKEN


scms:
Expand Down

0 comments on commit 6db484f

Please sign in to comment.