Skip to content

Commit 3e11a89

Browse files
authored
Retry gem compare ... commands and others (#3)
Try to make the action more stable (main issue is fedora-ruby/gem-compare#31)
1 parent 22dd771 commit 3e11a89

File tree

2 files changed

+36
-5
lines changed

2 files changed

+36
-5
lines changed

action.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ runs:
3333
echo "PR_NUMBER=${{ github.event.pull_request.number || inputs.pr_number }}" >> $GITHUB_ENV
3434
echo "PR_TITLE=${{ github.event.pull_request.title || inputs.pr_title }}" >> $GITHUB_ENV
3535
36-
# So the "parse_title" script can be found?
36+
# Ensure our scripts can be found when running the action
3737
# https://docs.github.com/en/actions/creating-actions/creating-a-composite-action#creating-an-action-metadata-file
3838
- run: echo "${{ github.action_path }}" >> $GITHUB_PATH
3939
shell: bash
@@ -48,17 +48,17 @@ runs:
4848
- name: Run gem install gem-compare
4949
shell: bash
5050
run: |
51-
gem install gem-compare --version ${{ inputs.gem_compare_version }}
51+
with_retries gem install gem-compare --version ${{ inputs.gem_compare_version }}
5252
5353
- name: Run gem compare
5454
shell: bash
5555
run: |
56-
gem compare $COMPARE_GEM $COMPARE_FROM_VERSION $COMPARE_TO_VERSION > compare_output.txt
56+
with_retries gem compare $COMPARE_GEM $COMPARE_FROM_VERSION $COMPARE_TO_VERSION > compare_output.txt
5757
5858
- name: Run gem compare --diff
5959
shell: bash
6060
run: |
61-
gem compare --diff $COMPARE_GEM $COMPARE_FROM_VERSION $COMPARE_TO_VERSION > compare_diff.txt
61+
with_retries gem compare --diff $COMPARE_GEM $COMPARE_FROM_VERSION $COMPARE_TO_VERSION > compare_diff.txt
6262
6363
- name: Run gh pr comment
6464
shell: bash
@@ -80,5 +80,5 @@ runs:
8080
echo '````' >> comment2.txt
8181
echo '</Details>' >> comment2.txt
8282
83-
gh pr comment $PR_NUMBER --body-file comment1.txt --repo ${{ github.repository }}
83+
with_retries gh pr comment $PR_NUMBER --body-file comment1.txt --repo ${{ github.repository }}
8484
gh pr comment $PR_NUMBER --body-file comment2.txt --repo ${{ github.repository }} || true

with_retries

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/bin/bash
2+
3+
# Modified version of travis_retry
4+
# https://github.com/travis-ci/travis-build/blob/04a1963de816b8618bb3d7e2e22d873f05ab4091/lib/travis/build/bash/travis_retry.bash
5+
6+
SLEEP_SECONDS=5
7+
RETRY_COUNT=5
8+
9+
retry_command() {
10+
local result=0
11+
local count=1
12+
while [[ "${count}" -le $RETRY_COUNT ]]; do
13+
[[ "${result}" -ne 0 ]] && {
14+
echo -e "\\n${ANSI_RED}The command \"${*}\" failed. Retrying, ${count} of ${RETRY_COUNT}.${ANSI_RESET}\\n" >&2
15+
}
16+
# run the command in a way that doesn't disable setting `errexit`
17+
"${@}"
18+
result="${?}"
19+
if [[ $result -eq 0 ]]; then break; fi
20+
count="$((count + 1))"
21+
sleep $SLEEP_SECONDS
22+
done
23+
24+
[[ "${count}" -gt ${RETRY_COUNT} ]] && {
25+
echo -e "\\n${ANSI_RED}The command \"${*}\" failed ${RETRY_COUNT} times.${ANSI_RESET}\\n" >&2
26+
}
27+
28+
return "${result}"
29+
}
30+
31+
retry_command "$@"

0 commit comments

Comments
 (0)