forked from RedHatQE/openshift-virtualization-tests
-
Notifications
You must be signed in to change notification settings - Fork 0
337 lines (336 loc) · 14.1 KB
/
cherrypick-to-4.99.yml
File metadata and controls
337 lines (336 loc) · 14.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
## Disabling this workflow for now until we decide how to handle the different branches
#name: PR Cherry-pick to cnv-4.99
#
#on:
# push:
# branches:
# - main
#
#concurrency:
# group: cherry-pick-cnv-4.99
# cancel-in-progress: true
#
#jobs:
# cherry-pick-pr:
# runs-on: ubuntu-latest
# permissions:
# contents: write
# pull-requests: write
# issues: write
# actions: read
#
# steps:
# - name: Checkout repository
# uses: actions/checkout@v4
# with:
# fetch-depth: 0
# token: ${{ secrets.GITHUB_TOKEN }}
#
# - name: Check if push is from PR merge
# id: check-pr
# run: |
# set -euo pipefail
#
# # Get the commit SHA that was just pushed
# COMMIT_SHA="${{ github.sha }}"
# echo "Checking commit: $COMMIT_SHA"
#
# # Validate SHA format
# if [[ ! "$COMMIT_SHA" =~ ^[a-f0-9]{40}$ ]]; then
# echo "Invalid commit SHA format: $COMMIT_SHA"
# exit 1
# fi
#
# # Use GitHub API to detect if commit is associated with a PR
# echo "Using GitHub API to check for associated PR..."
#
# # Query the commits/{sha}/pulls API endpoint
# if ! PR_RESPONSE=$(curl -sf \
# --connect-timeout 5 \
# --max-time 30 \
# -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
# -H "Accept: application/vnd.github+json" \
# -H "X-GitHub-Api-Version: 2022-11-28" \
# "https://api.github.com/repos/${{ github.repository }}/commits/$COMMIT_SHA/pulls"); then
# echo "Failed to query GitHub API for commit $COMMIT_SHA"
# echo "is_pr=false" >> "$GITHUB_OUTPUT"
# exit 0
# fi
#
# # Check if any PRs are associated with this commit
# PR_COUNT=$(echo "$PR_RESPONSE" | jq -r 'length')
#
# if [ "$PR_COUNT" -eq 0 ]; then
# echo "No PR associated with commit $COMMIT_SHA - skipping"
# echo "is_pr=false" >> "$GITHUB_OUTPUT"
# exit 0
# fi
#
# # Get the first (most relevant) PR from the response
# if ! PR_DATA=$(echo "$PR_RESPONSE" | jq -r '.[0]'); then
# echo "Failed to parse PR data from API response"
# echo "is_pr=false" >> "$GITHUB_OUTPUT"
# exit 0
# fi
#
# # Extract PR details from API response with safe fallbacks
# PR_NUMBER=$(echo "$PR_DATA" | jq -r '.number // ""')
# PR_OWNER=$(echo "$PR_DATA" | jq -r '.head.repo.owner.login // .base.repo.owner.login // ""')
# PR_REPO=$(echo "$PR_DATA" | jq -r '.head.repo.name // .base.repo.name // ""')
# BRANCH_NAME=$(echo "$PR_DATA" | jq -r '.head.ref // "deleted-branch"')
#
# # Use repository defaults when head repo is unavailable (fork deleted)
# if [ -z "$PR_OWNER" ] || [ "$PR_OWNER" = "null" ]; then
# PR_OWNER="${{ github.repository_owner }}"
# fi
# if [ -z "$PR_REPO" ] || [ "$PR_REPO" = "null" ]; then
# PR_REPO="${{ github.event.repository.name }}"
# fi
# if [ -z "$BRANCH_NAME" ] || [ "$BRANCH_NAME" = "null" ]; then
# BRANCH_NAME="deleted-branch"
# fi
#
# if [ -z "$PR_NUMBER" ] || [ "$PR_NUMBER" = "null" ]; then
# echo "Invalid PR number from API response"
# echo "is_pr=false" >> "$GITHUB_OUTPUT"
# exit 0
# fi
#
# echo "Found PR associated with commit (with safe fallbacks applied):"
# echo "PR Number: $PR_NUMBER"
# echo "PR Owner: $PR_OWNER"
# echo "PR Repo: $PR_REPO"
# echo "Branch: $BRANCH_NAME"
#
# echo "is_pr=true" >> "$GITHUB_OUTPUT"
# echo "pr_number=$PR_NUMBER" >> "$GITHUB_OUTPUT"
# echo "pr_owner=$PR_OWNER" >> "$GITHUB_OUTPUT"
# echo "pr_repo=$PR_REPO" >> "$GITHUB_OUTPUT"
# echo "branch_name=$BRANCH_NAME" >> "$GITHUB_OUTPUT"
# echo "commit_sha=$COMMIT_SHA" >> "$GITHUB_OUTPUT"
#
# - name: Get PR details via GitHub API
# if: steps.check-pr.outputs.is_pr == 'true'
# id: get-pr-details
# run: |
# set -euo pipefail
#
# PR_NUMBER="${{ steps.check-pr.outputs.pr_number }}"
#
# # Get PR details from GitHub API with error handling
# if ! PR_DATA=$(curl -sf \
# --connect-timeout 5 \
# --max-time 30 \
# -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
# -H "Accept: application/vnd.github+json" \
# -H "X-GitHub-Api-Version: 2022-11-28" \
# "https://api.github.com/repos/${{ github.repository }}/pulls/$PR_NUMBER"); then
# echo "Failed to fetch PR data for PR #$PR_NUMBER"
# exit 1
# fi
#
# # Extract relevant information with jq
# if ! PR_TITLE=$(echo "$PR_DATA" | jq -r '.title // ""'); then
# echo "Failed to extract PR title"
# exit 1
# fi
#
# if ! PR_AUTHOR=$(echo "$PR_DATA" | jq -r '.user.login // ""'); then
# echo "Failed to extract PR author"
# exit 1
# fi
#
# if ! PR_BODY=$(echo "$PR_DATA" | jq -r '.body // ""'); then
# echo "Failed to extract PR body"
# exit 1
# fi
#
# # Use random delimiters to safely set multiline outputs
# DELIMITER_TITLE=$(openssl rand -hex 16)
# DELIMITER_AUTHOR=$(openssl rand -hex 16)
# DELIMITER_BODY=$(openssl rand -hex 16)
#
# {
# echo "pr_title<<$DELIMITER_TITLE"
# echo "$PR_TITLE"
# echo "$DELIMITER_TITLE"
# } >> "$GITHUB_OUTPUT"
#
# {
# echo "pr_author<<$DELIMITER_AUTHOR"
# echo "$PR_AUTHOR"
# echo "$DELIMITER_AUTHOR"
# } >> "$GITHUB_OUTPUT"
#
# {
# echo "pr_body<<$DELIMITER_BODY"
# echo "$PR_BODY"
# echo "$DELIMITER_BODY"
# } >> "$GITHUB_OUTPUT"
#
# - name: Setup Git configuration
# if: steps.check-pr.outputs.is_pr == 'true'
# run: |
# git config user.name "github-actions[bot]"
# git config user.email "github-actions[bot]@users.noreply.github.com"
#
# - name: Prepare cherry-pick to cnv-4.99
# if: steps.check-pr.outputs.is_pr == 'true'
# id: cherry-pick
# run: |
# set -euo pipefail
#
# TARGET_BRANCH="cnv-4.99"
# COMMIT_SHA="${{ steps.check-pr.outputs.commit_sha }}"
# PR_NUMBER="${{ steps.check-pr.outputs.pr_number }}"
#
# echo "Preparing to cherry-pick $COMMIT_SHA to $TARGET_BRANCH"
#
# # Fetch and checkout target branch
# if ! git fetch origin "$TARGET_BRANCH"; then
# echo "Failed to fetch target branch: $TARGET_BRANCH"
# exit 1
# fi
#
# if ! git checkout -B "$TARGET_BRANCH" "origin/$TARGET_BRANCH"; then
# echo "Failed to checkout target branch: $TARGET_BRANCH"
# exit 1
# fi
#
# # Check if commit was already cherry-picked via -x trailer
# if git log --grep="(cherry picked from commit $COMMIT_SHA)" --oneline HEAD | grep -q "(cherry picked from commit $COMMIT_SHA)"; then
# echo "Commit $COMMIT_SHA already cherry-picked to $TARGET_BRANCH (found -x trailer) - skipping"
# echo "skip_cherry_pick=true" >> "$GITHUB_OUTPUT"
# exit 0
# fi
#
# # Check if commit already exists on target branch
# if git merge-base --is-ancestor "$COMMIT_SHA" HEAD; then
# echo "Commit $COMMIT_SHA already exists on $TARGET_BRANCH - skipping"
# echo "skip_cherry_pick=true" >> "$GITHUB_OUTPUT"
# exit 0
# fi
#
# echo "skip_cherry_pick=false" >> "$GITHUB_OUTPUT"
#
# # Attempt cherry-pick to working directory (let peter-evans handle the rest)
# echo "Attempting to cherry-pick $COMMIT_SHA"
#
# # Check if this is a merge commit (has multiple parents)
# PARENT_COUNT=$(git rev-list --parents -n 1 "$COMMIT_SHA" | wc -w)
# PARENT_COUNT=$((PARENT_COUNT - 1)) # Subtract 1 because rev-list includes the commit itself
#
# # Build cherry-pick command based on commit type
# if [ "$PARENT_COUNT" -gt 1 ]; then
# # Merge commit - use -m 1 to specify mainline parent
# CHERRY_PICK_CMD="git cherry-pick --no-commit -x -m 1 $COMMIT_SHA"
# else
# # Regular commit - no need for -m flag
# CHERRY_PICK_CMD="git cherry-pick --no-commit -x $COMMIT_SHA"
# fi
#
# echo "Commit has $PARENT_COUNT parent(s), using command: $CHERRY_PICK_CMD"
#
# if $CHERRY_PICK_CMD; then
# echo "Cherry-pick successful - changes ready for PR creation"
# echo "has_conflicts=false" >> "$GITHUB_OUTPUT"
# else
# echo "Cherry-pick failed with conflicts - staging for peter-evans"
#
# # Get list of conflicted files
# CONFLICTED_FILES=$(git diff --name-only --diff-filter=U | tr '\n' ' ' || echo "Unable to determine conflicted files")
# echo "Conflicted files: $CONFLICTED_FILES"
#
# # Use random delimiter for conflicted files output
# DELIMITER_CONFLICTS=$(openssl rand -hex 16)
# {
# echo "conflicted_files<<$DELIMITER_CONFLICTS"
# echo "$CONFLICTED_FILES"
# echo "$DELIMITER_CONFLICTS"
# } >> "$GITHUB_OUTPUT"
#
# echo "has_conflicts=true" >> "$GITHUB_OUTPUT"
#
# # Refresh index and stage all changes (including conflicts) for peter-evans to handle
# # This resolves the "you need to resolve your current index first" error
#
# git add -A :/
#
# git update-index --refresh -q || true
# fi
#
# - name: Create PR for successful cherry-pick
# if: steps.check-pr.outputs.is_pr == 'true' && steps.cherry-pick.outputs.skip_cherry_pick == 'false' && steps.cherry-pick.outputs.has_conflicts == 'false'
# id: create-pr-success
# uses: peter-evans/create-pull-request@v7
# with:
# token: ${{ secrets.GITHUB_TOKEN }}
# branch: "cherry-pick-pr-${{ steps.check-pr.outputs.pr_number }}-${{ github.run_id }}"
# title: "Cherry-pick: ${{ steps.get-pr-details.outputs.pr_title }} (PR #${{ steps.check-pr.outputs.pr_number }})"
# body: |
# ## 🍒 Automated Cherry-pick from PR
#
# This PR contains the cherry-pick of **PR #${{ steps.check-pr.outputs.pr_number }}** from `${{ steps.check-pr.outputs.pr_owner }}/${{ steps.check-pr.outputs.pr_repo }}`.
#
# **Original PR:** ${{ steps.get-pr-details.outputs.pr_title }}
# **Author:** @${{ steps.get-pr-details.outputs.pr_author }}
# **Merge Commit:** ${{ steps.check-pr.outputs.commit_sha }}
#
# The cherry-pick was applied cleanly to `cnv-4.99` without conflicts.
#
# **Original PR Link:** ${{ github.server_url }}/${{ github.repository }}/pull/${{ steps.check-pr.outputs.pr_number }}
# **Original Commit:** ${{ github.server_url }}/${{ github.repository }}/commit/${{ steps.check-pr.outputs.commit_sha }}
#
# ### Original PR Description
# ${{ steps.get-pr-details.outputs.pr_body }}
# base: "cnv-4.99"
# delete-branch: true
# labels: cherry-pick-to-4.99
#
# - name: Check if PR was created or already exists
# if: steps.check-pr.outputs.is_pr == 'true' && steps.cherry-pick.outputs.skip_cherry_pick == 'false' && steps.cherry-pick.outputs.has_conflicts == 'false'
# run: |
# if [ "${{ steps.create-pr-success.outputs.pull-request-operation }}" = "none" ]; then
# echo "No changes were found to create a PR - changes might already exist on target branch"
# else
# echo "PR created successfully: ${{ steps.create-pr-success.outputs.pull-request-url }}"
# fi
#
# - name: Create draft PR for conflicted cherry-pick
# if: steps.check-pr.outputs.is_pr == 'true' && steps.cherry-pick.outputs.skip_cherry_pick == 'false' && steps.cherry-pick.outputs.has_conflicts == 'true'
# uses: peter-evans/create-pull-request@v7
# with:
# token: ${{ secrets.GITHUB_TOKEN }}
# branch: "cherry-pick-pr-${{ steps.check-pr.outputs.pr_number }}-${{ github.run_id }}-conflicts"
# title: "🚨 Cherry-pick Conflicts: ${{ steps.get-pr-details.outputs.pr_title }} (PR #${{ steps.check-pr.outputs.pr_number }})"
# body: |
# ## ⚠️ Cherry-pick Conflicts - Manual Resolution Required
#
# The automatic cherry-pick of **PR #${{ steps.check-pr.outputs.pr_number }}** from `${{ steps.check-pr.outputs.pr_owner }}/${{ steps.check-pr.outputs.pr_repo }}` resulted in conflicts.
#
# **Original PR:** ${{ steps.get-pr-details.outputs.pr_title }}
# **Author:** @${{ steps.get-pr-details.outputs.pr_author }}
# **Merge Commit:** ${{ steps.check-pr.outputs.commit_sha }}
#
# ### 🔧 How to resolve:
# 1. Check out this branch locally: `git fetch origin && git checkout cherry-pick-pr-${{ steps.check-pr.outputs.pr_number }}-${{ github.run_id }}-conflicts`
# 2. Resolve conflicts in the affected files
# 3. Test your changes thoroughly
# 4. Commit your resolution: `git add . && git commit`
# 5. Push changes: `git push origin cherry-pick-pr-${{ steps.check-pr.outputs.pr_number }}-${{ github.run_id }}-conflicts`
# 6. Mark this PR as ready for review
#
# ### 📁 Files with conflicts:
# ```
# ${{ steps.cherry-pick.outputs.conflicted_files }}
# ```
#
# **Original PR Link:** ${{ github.server_url }}/${{ github.repository }}/pull/${{ steps.check-pr.outputs.pr_number }}
# **Original Commit:** ${{ github.server_url }}/${{ github.repository }}/commit/${{ steps.check-pr.outputs.commit_sha }}
#
# ### Original PR Description
# ${{ steps.get-pr-details.outputs.pr_body }}
# base: "cnv-4.99"
# delete-branch: true
# draft: true
# labels: cherry-pick-conflicts, cherry-pick-to-4.99