1+ name : " Kubectl - Create Bump PR"
2+ on :
3+ workflow_dispatch :
4+ inputs :
5+ target_branch :
6+ description : " Branch to run the update script on"
7+ required : true
8+ type : string
9+ script_ref :
10+ description : " A git ref (hash/branch) to use for the bump script"
11+ required : false
12+ type : string
13+
14+ workflow_call :
15+ inputs :
16+ target_branch :
17+ description : " Branch to run the update script on"
18+ required : true
19+ type : string
20+ script_ref :
21+ description : " A git ref (hash/branch) to use for the bump script"
22+ required : false
23+ type : string
24+
25+ permissions :
26+ contents : write
27+ pull-requests : write
28+
29+ jobs :
30+ update-and-pr :
31+ runs-on : ubuntu-latest
32+ steps :
33+ - name : Checkout target branch
34+ uses : actions/checkout@v4
35+ with :
36+ ref : ${{ inputs.target_branch }}
37+
38+ - name : Check for new build system support
39+ id : new_build
40+ run : |
41+ if [ ! -f "kubectl-versions.txt" ]; then
42+ echo "❌ This branch does not support the new build system. Failing early."
43+ echo "is_supported=false" >> $GITHUB_ENV
44+ echo "changes_exist=false" >> $GITHUB_ENV
45+ exit 0
46+ fi
47+ echo "is_supported=true" >> $GITHUB_ENV
48+
49+ - name : Pull script from main branch
50+ if : ${{ env.is_supported == 'true' }}
51+ run : |
52+ git fetch origin ${{ inputs.script_ref || 'main' }}
53+ git checkout FETCH_HEAD -- .github/scripts/bump-kubectl-patch-versions
54+
55+ - name : Run update script
56+ if : ${{ env.is_supported == 'true' }}
57+ run : bash .github/scripts/bump-kubectl-patch-versions
58+ env :
59+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
60+
61+ - name : Check for changes
62+ if : ${{ env.is_supported == 'true' }}
63+ run : |
64+ rm -f .github/scripts/update-script.sh
65+ git restore --staged --worktree .github/scripts/update-script.sh || true
66+
67+ if git diff --quiet; then
68+ echo "No changes detected."
69+ echo "changes_exist=false" >> $GITHUB_ENV
70+ else
71+ echo "Changes detected."
72+ git diff --name-only
73+ echo "changes_exist=true" >> $GITHUB_ENV
74+ fi
75+
76+ - name : " Git: Config, create branch, commit and push"
77+ if : ${{ env.changes_exist == 'true' }}
78+ run : |
79+ safe_branch=$(echo "${{ inputs.target_branch }}" | sed 's/[^a-zA-Z0-9._-]/_/g')
80+ BRANCH="gha-kubectl/update-$safe_branch-$(date +%Y-%m-%d-%H-%M-%S)"
81+ echo "UPDATE_BRANCH=${BRANCH}" >> "$GITHUB_ENV"
82+
83+ git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
84+ git config --global user.name "github-actions[bot]"
85+
86+ git checkout -b "$BRANCH"
87+ git commit -a -m "Updating new kubectl patch versions"
88+ git push origin "$BRANCH"
89+
90+ - name : Build PR body
91+ if : ${{ env.changes_exist == 'true' }}
92+ run : |
93+ {
94+ echo 'PR_BODY<<EOF'
95+ echo "Automated update using the script from \`main\` branch."
96+ echo ""
97+ echo "Triggered on: \`${{ inputs.target_branch }}\`"
98+ echo "Initiated by: @${GITHUB_ACTOR}"
99+ echo ""
100+ echo "## Review Instructions"
101+ echo "- Review the changes"
102+ echo "- Ensure CI passes"
103+ echo "- Approve and merge"
104+ echo EOF
105+ } >> "$GITHUB_ENV"
106+
107+ - name : Create or update PR
108+ if : ${{ env.changes_exist == 'true' }}
109+ env :
110+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
111+ PR_TITLE : " Automated `kubectl` update for `${{ inputs.target_branch }}`"
112+ run : |
113+ EXISTING_PR=$(gh pr list --limit 100 --json title,url \
114+ | jq --arg t "${PR_TITLE}" -r '.[] | select(.title==$t) | .url')
115+
116+ CREATED_PR=$(gh pr create \
117+ --title "${PR_TITLE}" \
118+ --body "${PR_BODY}" \
119+ --label "status/auto-created" \
120+ --label "dependencies" \
121+ --base "${{ inputs.target_branch }}" \
122+ --head "${UPDATE_BRANCH}")
123+
124+ echo "Created PR: ${CREATED_PR}" >> $GITHUB_STEP_SUMMARY
125+
126+ if [ -n "${EXISTING_PR}" ]; then
127+ echo "Closing previous PR: ${EXISTING_PR}"
128+ gh pr close "${EXISTING_PR}" --comment "Superseded by ${CREATED_PR}" --delete-branch
129+ echo "Closed previous PR: ${EXISTING_PR}" >> $GITHUB_STEP_SUMMARY
130+ fi
0 commit comments