Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .github/scripts/bump-kubectl-patch-versions
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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..."
64 changes: 64 additions & 0 deletions .github/workflows/cleanup.yml
Original file line number Diff line number Diff line change
@@ -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}`);
}
27 changes: 23 additions & 4 deletions .github/workflows/kubectl-create-bump-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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' }}
Expand All @@ -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
Expand Down Expand Up @@ -92,7 +109,9 @@ jobs:
run: |
{
echo 'PR_BODY<<EOF'
echo "Automated update using the script from \`main\` branch."
echo "Bumping Kubectl versions to: ${{ steps.changes_check.outputs.pr_title_versions }}"
echo ""
echo "Automated update using the kubectl bump script from \`${{ inputs.script_ref || 'main' }}\` branch."
echo ""
echo "Triggered on: \`${{ inputs.target_branch }}\`"
echo "Initiated by: @${GITHUB_ACTOR}"
Expand All @@ -108,7 +127,7 @@ jobs:
if: ${{ env.changes_exist == 'true' }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PR_TITLE: "Automated `kubectl` update for `${{ inputs.target_branch }}`"
PR_TITLE: "[${{ inputs.target_branch }}] Automated `kubectl` updates: `${{ steps.changes_check.outputs.pr_title_versions }}`"
run: |
EXISTING_PR=$(gh pr list --limit 100 --json title,url \
| jq --arg t "${PR_TITLE}" -r '.[] | select(.title==$t) | .url')
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@
versions.txt
new-versions.txt
/image_arch_test
*.oci
*.oci
kubectl-versions.txt.log