From 9dfbb1d1fe6c527686561738ca1cd3416f8dc37f Mon Sep 17 00:00:00 2001 From: Dan Pock Date: Fri, 25 Jul 2025 09:49:11 -0400 Subject: [PATCH 1/3] Add branch clean up upon close of Auto-bumps --- .github/workflows/cleanup.yml | 64 +++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 .github/workflows/cleanup.yml diff --git a/.github/workflows/cleanup.yml b/.github/workflows/cleanup.yml new file mode 100644 index 0000000..5ed7ef4 --- /dev/null +++ b/.github/workflows/cleanup.yml @@ -0,0 +1,64 @@ +name: Clean PR Branch + +on: + pull_request: + types: [closed] + +jobs: + cleanup: + runs-on: ubuntu-latest + if: contains(github.event.pull_request.labels.*.name, 'status/auto-created') + steps: + - name: Checkout repository + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + - name: Check PR branch exists + id: check-branch + uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1 + with: + script: | + try { + let {status: status} = await github.rest.git.getRef({ + owner: context.repo.owner, + repo: context.repo.repo, + ref: "heads/${{ github.event.pull_request.head.ref }}" + }) + if (status == 200) { + await core.summary + .addHeading("PR Branch Found", 2) + .addRaw("The PR branch was found and will be cleaned up.") + .write(); + } else { + + core.setFailed("Branch not found, nothing to clean. (failure can be ignored)"); + } + } + catch (err) { + if (err.response && err.response.status === 404) { + await core.summary + .addHeading("PR Branch Not Found", 2) + .addRaw("The PR branch didn't exist; the action failure can be ignored.") + .write(); + core.setFailed("Branch not found, nothing to clean. (failure can be ignored)"); + } else { + core.setFailed(`Action failed with error ${err}`); + } + } + - name: Delete the PR branch + uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1 + with: + script: | + try { + let {status: status} = github.rest.git.deleteRef({ + owner: context.repo.owner, + repo: context.repo.repo, + ref: "heads/${{ github.event.pull_request.head.ref }}" + }) + await core.summary + .addHeading("PR Branch Deleted", 2) + .addRaw("The PR's branch `${{ github.event.pull_request.head.ref }}` was deleted.") + .write(); + } + catch (err) { + // setFailed logs the message and sets a failing exit code + core.setFailed(`Action failed with error ${err}`); + } From 529aa3cda8f4e83b0f7edc6e8a5a6d11814569e5 Mon Sep 17 00:00:00 2001 From: Dan Pock Date: Fri, 25 Jul 2025 10:00:57 -0400 Subject: [PATCH 2/3] Add update log for PR title --- .github/scripts/bump-kubectl-patch-versions | 5 +++++ .gitignore | 3 ++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/.github/scripts/bump-kubectl-patch-versions b/.github/scripts/bump-kubectl-patch-versions index 5b1853e..2d5496b 100755 --- a/.github/scripts/bump-kubectl-patch-versions +++ b/.github/scripts/bump-kubectl-patch-versions @@ -5,9 +5,11 @@ set -euo pipefail # Otherwise, default to "kubectl-versions.txt". VERSIONS_FILE=${1:-"kubectl-versions.txt"} TEMP_FILE="${VERSIONS_FILE}.tmp" +UPDATE_LOG_FILE="${VERSIONS_FILE}.log" echo "Using versions file: $VERSIONS_FILE" echo "Temporary file will be: $TEMP_FILE" +echo "Log file will be: $UPDATE_LOG_FILE" # Check if the input file exists if [[ ! -f "$VERSIONS_FILE" ]]; then @@ -30,6 +32,7 @@ while IFS= read -r VERSION; do fi echo "Found newer patch $NEWEST_OPTION to replace $VERSION" echo "$NEWEST_OPTION" >> "$TEMP_FILE" + echo "$NEWEST_OPTION" >> "$UPDATE_LOG_FILE" done < "$VERSIONS_FILE" # Check if the temporary file was created successfully @@ -41,3 +44,5 @@ else echo "Error: Temporary file not created. No changes made." exit 1 fi + +echo "Remember the $UPDATE_LOG_FILE must be cleaned up after reading..." \ No newline at end of file diff --git a/.gitignore b/.gitignore index e1ae7e9..3e51a61 100644 --- a/.gitignore +++ b/.gitignore @@ -10,4 +10,5 @@ versions.txt new-versions.txt /image_arch_test -*.oci \ No newline at end of file +*.oci +kubectl-versions.txt.log \ No newline at end of file From a4721cf43866ce4719a9310ec669b27209f312ec Mon Sep 17 00:00:00 2001 From: Dan Pock Date: Fri, 25 Jul 2025 10:08:19 -0400 Subject: [PATCH 3/3] Update PR workflow to use versions in name --- .github/workflows/kubectl-create-bump-pr.yml | 27 +++++++++++++++++--- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/.github/workflows/kubectl-create-bump-pr.yml b/.github/workflows/kubectl-create-bump-pr.yml index c07cb27..715a20e 100644 --- a/.github/workflows/kubectl-create-bump-pr.yml +++ b/.github/workflows/kubectl-create-bump-pr.yml @@ -46,7 +46,7 @@ jobs: fi echo "is_supported=true" >> $GITHUB_ENV - - name: Pull script from main branch + - name: "Pull script from `${{ inputs.script_ref || 'main' }}` branch" if: ${{ env.is_supported == 'true' }} run: | git fetch origin ${{ inputs.script_ref || 'main' }} @@ -59,11 +59,28 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: Check for changes + id: changes_check if: ${{ env.is_supported == 'true' }} run: | - rm -f .github/scripts/bump-kubectl-patch-versions + rm -f .github/scripts/bump-kubectl-patch-versions || true git restore --staged --worktree .github/scripts/bump-kubectl-patch-versions || true + # Read log for PR title and clean up log file + LOG_FILE="kubectl-versions.txt.log" + if [[ -f "$LOG_FILE" ]]; then + echo "Log file exists, parsing for title text..." + # Check if the log file exists and is not empty + if [[ -s "$LOG_FILE" ]]; then + LOG_TITLE=$(cat "$LOG_FILE" | awk '{printf "%s%s", (NR==1?"":", "), $0} END{print ""}') + echo "Log file content found, created title:" + echo "$LOG_TITLE" + echo "pr_title_versions=$LOG_TITLE" >> $GITHUB_OUTPUT + fi + + echo "Removing log file: $LOG_FILE" + rm "$LOG_FILE" + fi + if git diff --quiet; then echo "No changes detected." echo "changes_exist=false" >> $GITHUB_ENV @@ -92,7 +109,9 @@ jobs: run: | { echo 'PR_BODY<