Skip to content

Commit 7596051

Browse files
authored
Add retry logic to reviewer workflows (#56141)
1 parent 0560de3 commit 7596051

File tree

5 files changed

+61
-8
lines changed

5 files changed

+61
-8
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
name: 'Retry command'
2+
description: 'Retries any command with configurable attempts and delay'
3+
inputs:
4+
command:
5+
description: 'The command to retry'
6+
required: true
7+
max_attempts:
8+
description: 'Maximum number of retry attempts'
9+
required: false
10+
default: '8'
11+
delay:
12+
description: 'Delay between attempts in seconds'
13+
required: false
14+
default: '15'
15+
16+
runs:
17+
using: 'composite'
18+
steps:
19+
- name: Retry command
20+
shell: bash
21+
run: |
22+
# Generic retry function: configurable attempts and delay
23+
retry_command() {
24+
local max_attempts=${{ inputs.max_attempts }}
25+
local delay=${{ inputs.delay }}
26+
local attempt=1
27+
local command="${{ inputs.command }}"
28+
29+
while [ $attempt -le $max_attempts ]; do
30+
echo "Attempt $attempt/$max_attempts: Running command..."
31+
echo "Command: $command"
32+
if eval "$command"; then
33+
echo "Command succeeded on attempt $attempt"
34+
return 0
35+
else
36+
echo "Attempt $attempt failed"
37+
if [ $attempt -lt $max_attempts ]; then
38+
echo "Waiting $delay seconds before retry..."
39+
sleep $delay
40+
fi
41+
fi
42+
attempt=$((attempt + 1))
43+
done
44+
45+
echo "Command failed after $max_attempts attempts"
46+
return 1
47+
}
48+
49+
retry_command

.github/workflows/reviewers-content-systems.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,6 @@ jobs:
3939
uses: actions/checkout@v4
4040

4141
- name: Add content systems as a reviewer
42-
run: |
43-
gh pr edit $PR --add-reviewer github/docs-content-systems --add-label reviewers-content-systems
42+
uses: ./.github/actions/retry-command
43+
with:
44+
command: gh pr edit $PR --add-reviewer github/docs-content-systems --add-label reviewers-content-systems

.github/workflows/reviewers-dependabot.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,6 @@ jobs:
4040
uses: actions/checkout@v4
4141

4242
- name: Add dependabot as a reviewer
43-
run: |
44-
gh pr edit $PR --add-reviewer github/dependabot-updates-reviewers --add-label reviewers-dependabot
43+
uses: ./.github/actions/retry-command
44+
with:
45+
command: gh pr edit $PR --add-reviewer github/dependabot-updates-reviewers --add-label reviewers-dependabot

.github/workflows/reviewers-docs-engineering.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,5 +51,6 @@ jobs:
5151
uses: actions/checkout@v4
5252

5353
- name: Add docs engineering as a reviewer
54-
run: |
55-
gh pr edit $PR --add-reviewer github/docs-engineering --add-label reviewers-docs-engineering
54+
uses: ./.github/actions/retry-command
55+
with:
56+
command: gh pr edit $PR --add-reviewer github/docs-engineering --add-label reviewers-docs-engineering

.github/workflows/reviewers-legal.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,9 @@ jobs:
5454

5555
- name: Add legal as a reviewer
5656
if: steps.checkContentType.outputs.containsContentType == 'true'
57+
uses: ./.github/actions/retry-command
5758
env:
5859
GH_TOKEN: ${{ secrets.DOCS_BOT_PAT_BASE }}
5960
PR: ${{ github.event.pull_request.html_url }}
60-
run: |
61-
gh pr edit $PR --add-reviewer github/legal-product --add-label reviewers-legal
61+
with:
62+
command: gh pr edit $PR --add-reviewer github/legal-product --add-label reviewers-legal

0 commit comments

Comments
 (0)