mirror of
https://github.com/prowler-cloud/prowler.git
synced 2026-01-25 02:08:11 +00:00
Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Pepe Fagoaga <pepe@prowler.com>
124 lines
4.4 KiB
YAML
124 lines
4.4 KiB
YAML
name: 'Tools: PR Conflict Checker'
|
|
|
|
on:
|
|
pull_request_target:
|
|
types:
|
|
- 'opened'
|
|
- 'synchronize'
|
|
- 'reopened'
|
|
branches:
|
|
- 'master'
|
|
- 'v5.*'
|
|
|
|
concurrency:
|
|
group: ${{ github.workflow }}-${{ github.event.pull_request.number }}
|
|
cancel-in-progress: true
|
|
|
|
jobs:
|
|
check-conflicts:
|
|
runs-on: ubuntu-latest
|
|
timeout-minutes: 15
|
|
permissions:
|
|
contents: read
|
|
pull-requests: write
|
|
issues: write
|
|
|
|
steps:
|
|
- name: Checkout PR head
|
|
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
|
|
with:
|
|
ref: ${{ github.event.pull_request.head.sha }}
|
|
fetch-depth: 0
|
|
|
|
- name: Get changed files
|
|
id: changed-files
|
|
uses: tj-actions/changed-files@e0021407031f5be11a464abee9a0776171c79891 # v47.0.1
|
|
with:
|
|
files: '**'
|
|
|
|
- name: Check for conflict markers
|
|
id: conflict-check
|
|
run: |
|
|
echo "Checking for conflict markers in changed files..."
|
|
|
|
CONFLICT_FILES=""
|
|
HAS_CONFLICTS=false
|
|
|
|
# Check each changed file for conflict markers
|
|
for file in ${{ steps.changed-files.outputs.all_changed_files }}; do
|
|
if [ -f "$file" ]; then
|
|
echo "Checking file: $file"
|
|
|
|
# Look for conflict markers (more precise regex)
|
|
if grep -qE '^(<<<<<<<|=======|>>>>>>>)' "$file" 2>/dev/null; then
|
|
echo "Conflict markers found in: $file"
|
|
CONFLICT_FILES="${CONFLICT_FILES}- \`${file}\`"$'\n'
|
|
HAS_CONFLICTS=true
|
|
fi
|
|
fi
|
|
done
|
|
|
|
if [ "$HAS_CONFLICTS" = true ]; then
|
|
echo "has_conflicts=true" >> $GITHUB_OUTPUT
|
|
{
|
|
echo "conflict_files<<EOF"
|
|
echo "$CONFLICT_FILES"
|
|
echo "EOF"
|
|
} >> $GITHUB_OUTPUT
|
|
echo "Conflict markers detected"
|
|
else
|
|
echo "has_conflicts=false" >> $GITHUB_OUTPUT
|
|
echo "No conflict markers found in changed files"
|
|
fi
|
|
|
|
- name: Manage conflict label
|
|
env:
|
|
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
PR_NUMBER: ${{ github.event.pull_request.number }}
|
|
HAS_CONFLICTS: ${{ steps.conflict-check.outputs.has_conflicts }}
|
|
run: |
|
|
LABEL_NAME="has-conflicts"
|
|
|
|
# Add or remove label based on conflict status
|
|
if [ "$HAS_CONFLICTS" = "true" ]; then
|
|
echo "Adding conflict label to PR #${PR_NUMBER}..."
|
|
gh pr edit "$PR_NUMBER" --add-label "$LABEL_NAME" --repo ${{ github.repository }} || true
|
|
else
|
|
echo "Removing conflict label from PR #${PR_NUMBER}..."
|
|
gh pr edit "$PR_NUMBER" --remove-label "$LABEL_NAME" --repo ${{ github.repository }} || true
|
|
fi
|
|
|
|
- name: Find existing comment
|
|
uses: peter-evans/find-comment@b30e6a3c0ed37e7c023ccd3f1db5c6c0b0c23aad # v4.0.0
|
|
id: find-comment
|
|
with:
|
|
issue-number: ${{ github.event.pull_request.number }}
|
|
comment-author: 'github-actions[bot]'
|
|
body-includes: '<!-- conflict-checker-comment -->'
|
|
|
|
- name: Create or update comment
|
|
uses: peter-evans/create-or-update-comment@e8674b075228eee787fea43ef493e45ece1004c9 # v5.0.0
|
|
with:
|
|
comment-id: ${{ steps.find-comment.outputs.comment-id }}
|
|
issue-number: ${{ github.event.pull_request.number }}
|
|
edit-mode: replace
|
|
body: |
|
|
<!-- conflict-checker-comment -->
|
|
${{ steps.conflict-check.outputs.has_conflicts == 'true' && '⚠️ **Conflict Markers Detected**' || '✅ **Conflict Markers Resolved**' }}
|
|
|
|
${{ steps.conflict-check.outputs.has_conflicts == 'true' && format('This pull request contains unresolved conflict markers in the following files:
|
|
|
|
{0}
|
|
|
|
Please resolve these conflicts by:
|
|
1. Locating the conflict markers: `<<<<<<<`, `=======`, and `>>>>>>>`
|
|
2. Manually editing the files to resolve the conflicts
|
|
3. Removing all conflict markers
|
|
4. Committing and pushing the changes', steps.conflict-check.outputs.conflict_files) || 'All conflict markers have been successfully resolved in this pull request.' }}
|
|
|
|
- name: Fail workflow if conflicts detected
|
|
if: steps.conflict-check.outputs.has_conflicts == 'true'
|
|
run: |
|
|
echo "::error::Workflow failed due to conflict markers detected in the PR"
|
|
exit 1
|