Skip to content

Commit cc3d2b0

Browse files
chore: replace reusable workflow with standalone dependabot auto-merge
1 parent 9820a44 commit cc3d2b0

1 file changed

Lines changed: 67 additions & 10 deletions

File tree

Lines changed: 67 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,73 @@
11
name: Dependabot Auto-Merge
22

33
on:
4-
pull_request:
4+
pull_request_target:
55
types: [opened, synchronize, reopened, ready_for_review]
6-
check_suite:
7-
types: [completed]
6+
7+
permissions:
8+
contents: write
9+
pull-requests: write
10+
checks: read
811

912
jobs:
10-
dependabot-auto-merge:
11-
uses: Checkmarx-Containers/containers-github-actions-workflows/.github/workflows/dependabot-auto-merge.yml@main
12-
with:
13-
service-name: ${{ github.event.repository.name }}
14-
timeout-seconds: 2700
15-
auto-merge-major: true
16-
secrets: inherit
13+
auto-merge:
14+
runs-on: ubuntu-latest
15+
if: github.event.pull_request.user.login == 'dependabot[bot]'
16+
steps:
17+
- name: Fetch dependabot metadata
18+
id: metadata
19+
uses: dependabot/fetch-metadata@d7267f607e9d3fb96fc2fbe83e0af444713e90b7 # v2.3.0
20+
with:
21+
github-token: ${{ github.token }}
22+
23+
- name: Wait for required checks
24+
run: |
25+
MAX_ATTEMPTS=60
26+
SLEEP_SECONDS=30
27+
28+
IFS=',' read -ra CHECKS <<< "$REQUIRED_CHECKS"
29+
30+
for check in "${CHECKS[@]}"; do
31+
check=$(echo "$check" | xargs)
32+
echo "Waiting for check: '$check'"
33+
attempts=0
34+
while [ $attempts -lt $MAX_ATTEMPTS ]; do
35+
conclusion=$(gh api "repos/$GITHUB_REPOSITORY/commits/$HEAD_SHA/check-runs" \
36+
--jq ".check_runs[] | select(.name == \"$check\") | .conclusion" 2>/dev/null | head -1)
37+
status=$(gh api "repos/$GITHUB_REPOSITORY/commits/$HEAD_SHA/check-runs" \
38+
--jq ".check_runs[] | select(.name == \"$check\") | .status" 2>/dev/null | head -1)
39+
40+
if [ "$conclusion" = "success" ] || [ "$conclusion" = "skipped" ] || [ "$conclusion" = "neutral" ]; then
41+
echo "✅ Check '$check' passed ($conclusion)"
42+
break
43+
elif [ "$conclusion" = "failure" ] || [ "$conclusion" = "cancelled" ]; then
44+
echo "❌ Check '$check' failed ($conclusion) — aborting"
45+
exit 1
46+
else
47+
echo "⏳ Check '$check' status=${status:-pending}, conclusion=${conclusion:-none} (attempt $((attempts+1))/$MAX_ATTEMPTS)"
48+
sleep $SLEEP_SECONDS
49+
attempts=$((attempts + 1))
50+
fi
51+
done
52+
if [ $attempts -eq $MAX_ATTEMPTS ]; then
53+
echo "⏰ Timed out waiting for check '$check'"
54+
exit 1
55+
fi
56+
done
57+
echo "✅ All required checks passed"
58+
env:
59+
GH_TOKEN: ${{ github.token }}
60+
HEAD_SHA: ${{ github.event.pull_request.head.sha }}
61+
REQUIRED_CHECKS: "unit-tests,validate_jira_key"
62+
63+
- name: Auto-approve PR
64+
run: gh pr review "$PR_NUMBER" --approve --repo "$GITHUB_REPOSITORY"
65+
env:
66+
GH_TOKEN: ${{ github.token }}
67+
PR_NUMBER: ${{ github.event.pull_request.number }}
68+
69+
- name: Merge PR
70+
run: gh pr merge "$PR_NUMBER" --squash --delete-branch --repo "$GITHUB_REPOSITORY"
71+
env:
72+
GH_TOKEN: ${{ github.token }}
73+
PR_NUMBER: ${{ github.event.pull_request.number }}

0 commit comments

Comments
 (0)