Skip to content

Bump github.com/evanphx/json-patch from 4.12.0+incompatible to 5.9.11+incompatible #20

Bump github.com/evanphx/json-patch from 4.12.0+incompatible to 5.9.11+incompatible

Bump github.com/evanphx/json-patch from 4.12.0+incompatible to 5.9.11+incompatible #20

name: Dependabot Auto-Merge
on:
pull_request:
types: [opened, synchronize, reopened, ready_for_review]
permissions:
contents: write
pull-requests: write
checks: read
actions: read
jobs:
auto-merge:
runs-on: ubuntu-latest
# Only run for Dependabot PRs
if: github.actor == 'dependabot[bot]' && github.repository == 'openshift/managed-cluster-validating-webhooks'
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Fetch Dependabot Metadata
id: metadata
uses: dependabot/fetch-metadata@v2
with:
github-token: "${{ secrets.GITHUB_TOKEN }}"
- name: Check PR Labels
id: check-labels
run: |
# Since this job only runs for Dependabot PRs (filtered at job level),
# we allow all Dependabot PRs regardless of labels since they are inherently dependency updates
echo "has-required-labels=true" >> $GITHUB_OUTPUT
echo "✅ Dependabot PR detected - auto-merge enabled for safe updates"
- name: Enable Auto-Merge for Safe Updates
if: |
steps.check-labels.outputs.has-required-labels == 'true' && (
steps.metadata.outputs.update-type == 'version-update:semver-patch' ||
steps.metadata.outputs.update-type == 'version-update:semver-minor' ||
steps.metadata.outputs.update-type == 'version-update:semver-digest'
)
run: |
echo "Enabling auto-merge for ${{ steps.metadata.outputs.update-type }} update"
echo "Dependency: ${{ steps.metadata.outputs.dependency-names }}"
echo "Previous version: ${{ steps.metadata.outputs.previous-version }}"
echo "New version: ${{ steps.metadata.outputs.new-version }}"
# Set GH_TOKEN for curl commands (token is automatically masked in logs)
GH_TOKEN="${{ secrets.GITHUB_TOKEN }}"
export GH_TOKEN
# Get PR node ID for GraphQL mutation
PR_NODE_ID=$(curl -s \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer $GH_TOKEN" \
"https://api.github.com/repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}" \
| jq -r '.node_id')
if [[ -z "$PR_NODE_ID" || "$PR_NODE_ID" == "null" ]]; then
echo "❌ Failed to fetch PR node ID"
exit 1
fi
echo "PR Node ID: $PR_NODE_ID"
# Enable auto-merge using GraphQL API (only way that works)
# GraphQL returns HTTP 200 even when mutations fail; errors are in the JSON body.
response=$(curl -s -w "%{http_code}" -o /tmp/response.json \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer $GH_TOKEN" \
"https://api.github.com/graphql" \
-d "{\"query\":\"mutation { enablePullRequestAutoMerge(input: { pullRequestId: \\\"$PR_NODE_ID\\\", mergeMethod: SQUASH }) { pullRequest { autoMergeRequest { enabledAt } } } }\"}")
if [[ "$response" -eq 200 ]] && \
jq -e '.errors == null and (.data.enablePullRequestAutoMerge.pullRequest.autoMergeRequest.enabledAt != null)' /tmp/response.json >/dev/null; then
echo "✅ Auto-merge enabled successfully via GraphQL"
cat /tmp/response.json
else
echo "❌ Failed to enable auto-merge. HTTP status: $response"
echo "Response body:"
cat /tmp/response.json
echo "::warning::Could not enable auto-merge due to permissions or repository policy. Manual review is required."
# Add a comment to the PR explaining the situation (token is automatically masked)
curl -s -X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer $GH_TOKEN" \
"https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/comments" \
-d '{"body":"🤖 **Dependabot Auto-Merge Status**\n\nThis PR meets the criteria for auto-merge but could not be automatically merged due to repository permissions.\n\n**Details:**\n- Update type: ${{ steps.metadata.outputs.update-type }}\n- Dependencies: ${{ steps.metadata.outputs.dependency-names }}\n- Previous version: ${{ steps.metadata.outputs.previous-version }}\n- New version: ${{ steps.metadata.outputs.new-version }}\n\nPlease review and merge manually if appropriate."}'
fi
- name: Comment on Major Version Updates
if: |
steps.check-labels.outputs.has-required-labels == 'true' &&
steps.metadata.outputs.update-type == 'version-update:semver-major'
run: |
# Set GH_TOKEN for curl commands (token is automatically masked in logs)
GH_TOKEN="${{ secrets.GITHUB_TOKEN }}"
export GH_TOKEN
# Add a comment to the PR explaining major version update (token is automatically masked)
curl -s -X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer $GH_TOKEN" \
"https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/comments" \
-d '{"body":"🚨 **Major Version Update Detected** 🚨\n\nThis PR contains a major version update that requires manual review:\n- **Dependency:** ${{ steps.metadata.outputs.dependency-names }}\n- **Previous version:** ${{ steps.metadata.outputs.previous-version }}\n- **New version:** ${{ steps.metadata.outputs.new-version }}\n\nPlease review the changelog and breaking changes before merging.\n\nAuto-merge has been **disabled** for this PR."}'
- name: Log Auto-Merge Decision
run: |
echo "Auto-merge decision for PR #${{ github.event.pull_request.number }}:"
echo "- Update type: ${{ steps.metadata.outputs.update-type }}"
echo "- Has required labels: ${{ steps.check-labels.outputs.has-required-labels }}"
echo "- Dependency: ${{ steps.metadata.outputs.dependency-names }}"
if [[ "${{ steps.metadata.outputs.update-type }}" == "version-update:semver-patch" ]] || \
[[ "${{ steps.metadata.outputs.update-type }}" == "version-update:semver-minor" ]] || \
[[ "${{ steps.metadata.outputs.update-type }}" == "version-update:semver-digest" ]]; then
if [[ "${{ steps.check-labels.outputs.has-required-labels }}" == "true" ]]; then
echo "✅ Auto-merge ENABLED"
else
echo "❌ Auto-merge DISABLED: Missing required labels"
fi
else
echo "❌ Auto-merge DISABLED: Major version update or unknown update type"
fi