mirror of
https://github.com/HackTricks-wiki/hacktricks.git
synced 2025-10-10 18:36:50 +00:00
f
This commit is contained in:
parent
fa5cfe7668
commit
bb7354fc35
48
.github/workflows/auto_merge_approved_prs.yml
vendored
48
.github/workflows/auto_merge_approved_prs.yml
vendored
@ -15,6 +15,20 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
token: ${{ secrets.PAT_TOKEN }}
|
||||
|
||||
- name: Configure git
|
||||
run: |
|
||||
git config --global user.email "action@github.com"
|
||||
git config --global user.name "GitHub Action"
|
||||
|
||||
- name: Make conflict resolution script executable
|
||||
run: chmod +x ./resolve_searchindex_conflicts.sh
|
||||
|
||||
- name: Check for running workflows
|
||||
id: check_workflows
|
||||
run: |
|
||||
@ -93,6 +107,11 @@ jobs:
|
||||
if [ "$has_merge_comment" = true ]; then
|
||||
echo "Attempting to merge PR #$pr_number..."
|
||||
|
||||
# Get PR details including head branch
|
||||
pr_details=$(gh pr view "$pr_number" --json headRefName,baseRefName --repo "$GITHUB_REPOSITORY")
|
||||
head_branch=$(echo "$pr_details" | jq -r '.headRefName')
|
||||
base_branch=$(echo "$pr_details" | jq -r '.baseRefName')
|
||||
|
||||
# --- Polling for non-UNKNOWN mergeable status ---
|
||||
max_retries=10
|
||||
retry=0
|
||||
@ -118,6 +137,35 @@ jobs:
|
||||
else
|
||||
echo "Failed to merge PR #$pr_number: $pr_title"
|
||||
fi
|
||||
elif [ "$pr_mergeable" = "CONFLICTED" ]; then
|
||||
echo "PR #$pr_number has conflicts. Attempting to resolve searchindex.js conflicts..."
|
||||
|
||||
# Try to resolve conflicts by updating the branch
|
||||
export GITHUB_REPOSITORY="$GITHUB_REPOSITORY"
|
||||
export GH_TOKEN="${{ secrets.PAT_TOKEN }}"
|
||||
if ./resolve_searchindex_conflicts.sh "$pr_number" "$head_branch" "$base_branch"; then
|
||||
echo "Successfully resolved searchindex.js conflicts for PR #$pr_number"
|
||||
|
||||
# Wait for GitHub to update the mergeable status after conflict resolution
|
||||
echo "Waiting for GitHub to process the conflict resolution..."
|
||||
sleep 15
|
||||
|
||||
# Check if it's now mergeable
|
||||
pr_mergeable_after=$(gh pr view "$pr_number" --json mergeable --jq '.mergeable' --repo "$GITHUB_REPOSITORY")
|
||||
if [ "$pr_mergeable_after" = "MERGEABLE" ]; then
|
||||
if gh pr merge "$pr_number" --merge --delete-branch --repo "$GITHUB_REPOSITORY"; then
|
||||
echo "Successfully merged PR #$pr_number after resolving conflicts: $pr_title"
|
||||
current_count=$(cat /tmp/merged_count)
|
||||
echo $((current_count + 1)) > /tmp/merged_count
|
||||
else
|
||||
echo "Failed to merge PR #$pr_number after conflict resolution: $pr_title"
|
||||
fi
|
||||
else
|
||||
echo "PR #$pr_number still not mergeable after conflict resolution (status: $pr_mergeable_after)"
|
||||
fi
|
||||
else
|
||||
echo "Failed to resolve conflicts for PR #$pr_number"
|
||||
fi
|
||||
else
|
||||
echo "PR #$pr_number is not mergeable (status: $pr_mergeable)"
|
||||
fi
|
||||
|
139
resolve_searchindex_conflicts.sh
Normal file
139
resolve_searchindex_conflicts.sh
Normal file
@ -0,0 +1,139 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Script to resolve searchindex.js conflicts by accepting master branch version
|
||||
# This script is designed to handle merge conflicts that occur when PRs become
|
||||
# desynchronized due to the auto-generated searchindex.js file.
|
||||
#
|
||||
# The searchindex.js file is automatically generated by the build process and
|
||||
# frequently causes conflicts when multiple PRs are waiting to be merged.
|
||||
# This script automatically resolves those conflicts by accepting the master
|
||||
# branch version of the file.
|
||||
#
|
||||
# Usage: resolve_searchindex_conflicts.sh <pr_number> <head_branch> <base_branch>
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
# Validate arguments
|
||||
if [ $# -ne 3 ]; then
|
||||
echo "Usage: $0 <pr_number> <head_branch> <base_branch>"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
PR_NUMBER="$1"
|
||||
HEAD_BRANCH="$2"
|
||||
BASE_BRANCH="$3"
|
||||
|
||||
# Validate required environment variables
|
||||
if [ -z "${GITHUB_REPOSITORY:-}" ]; then
|
||||
echo "Error: GITHUB_REPOSITORY environment variable is required"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ -z "${GH_TOKEN:-}" ]; then
|
||||
echo "Error: GH_TOKEN environment variable is required"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Resolving conflicts for PR #$PR_NUMBER (branch: $HEAD_BRANCH -> $BASE_BRANCH)"
|
||||
|
||||
# Get current directory for safety
|
||||
ORIGINAL_DIR=$(pwd)
|
||||
|
||||
# Create a temporary directory for the operation
|
||||
TEMP_DIR=$(mktemp -d)
|
||||
echo "Working in temporary directory: $TEMP_DIR"
|
||||
|
||||
cleanup() {
|
||||
echo "Cleaning up..."
|
||||
cd "$ORIGINAL_DIR"
|
||||
rm -rf "$TEMP_DIR"
|
||||
}
|
||||
trap cleanup EXIT
|
||||
|
||||
# Clone the repository to the temp directory
|
||||
echo "Cloning repository..."
|
||||
cd "$TEMP_DIR"
|
||||
gh repo clone "$GITHUB_REPOSITORY" . --branch "$HEAD_BRANCH"
|
||||
|
||||
# Configure git
|
||||
git config user.email "action@github.com"
|
||||
git config user.name "GitHub Action"
|
||||
|
||||
# Fetch all branches
|
||||
git fetch origin
|
||||
|
||||
# Make sure we're on the correct branch
|
||||
git checkout "$HEAD_BRANCH"
|
||||
|
||||
# Try to merge the base branch
|
||||
echo "Attempting to merge $BASE_BRANCH into $HEAD_BRANCH..."
|
||||
if git merge "origin/$BASE_BRANCH" --no-edit; then
|
||||
echo "No conflicts found, merge successful"
|
||||
|
||||
# Push the updated branch
|
||||
echo "Pushing merged branch..."
|
||||
git push origin "$HEAD_BRANCH"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Check what files have conflicts
|
||||
echo "Checking for conflicts..."
|
||||
conflicted_files=$(git diff --name-only --diff-filter=U)
|
||||
echo "Conflicted files: $conflicted_files"
|
||||
|
||||
# Check if searchindex.js is the only conflict or if conflicts are only in acceptable files
|
||||
acceptable_conflicts=true
|
||||
searchindex_conflict=false
|
||||
|
||||
for file in $conflicted_files; do
|
||||
case "$file" in
|
||||
"searchindex.js")
|
||||
searchindex_conflict=true
|
||||
echo "Found searchindex.js conflict (acceptable)"
|
||||
;;
|
||||
*)
|
||||
echo "Found unacceptable conflict in: $file"
|
||||
acceptable_conflicts=false
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [ "$acceptable_conflicts" = false ]; then
|
||||
echo "Cannot auto-resolve: conflicts found in files other than searchindex.js"
|
||||
git merge --abort
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ "$searchindex_conflict" = false ]; then
|
||||
echo "No searchindex.js conflicts found, but merge failed for unknown reason"
|
||||
git merge --abort
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Resolving searchindex.js conflict by accepting $BASE_BRANCH version..."
|
||||
|
||||
# Accept the base branch version of searchindex.js (--theirs refers to the branch being merged in)
|
||||
git checkout --theirs searchindex.js
|
||||
git add searchindex.js
|
||||
|
||||
# Check if there are any other staged changes from the merge
|
||||
staged_files=$(git diff --cached --name-only || true)
|
||||
echo "Staged files after resolution: $staged_files"
|
||||
|
||||
# Complete the merge
|
||||
if git commit --no-edit; then
|
||||
echo "Successfully resolved merge conflicts"
|
||||
|
||||
# Push the updated branch
|
||||
echo "Pushing resolved branch..."
|
||||
if git push origin "$HEAD_BRANCH"; then
|
||||
echo "Successfully pushed resolved branch"
|
||||
exit 0
|
||||
else
|
||||
echo "Failed to push resolved branch"
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
echo "Failed to commit merge resolution"
|
||||
exit 1
|
||||
fi
|
Loading…
x
Reference in New Issue
Block a user