Skip to content

Commit

Permalink
feat: auto-retry commands twice and improve support for multiline pro…
Browse files Browse the repository at this point in the history
…grams (#517)

includes: fix: fail correctly if there is a failure after all repetitions
  • Loading branch information
DanySK committed Feb 9, 2024
1 parent 53d5824 commit 7ffe29c
Showing 2 changed files with 30 additions and 10 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -53,7 +53,10 @@ jobs:
- uses: ./action
with:
build-command: ./gradlew tasks
check-command: true
check-command: |
for x in 1 2 3; do
echo $x
done
working-directory: target
should-run-codecov: false
clean-command: ./gradlew clean
35 changes: 26 additions & 9 deletions action.yml
Original file line number Diff line number Diff line change
@@ -23,7 +23,7 @@ inputs:
required: false
retries-on-failure:
description: 'How many times every command should be retried before giving up'
default: '1'
default: '2'
required: false
wait-between-retries:
description: 'How many seconds to wait after a step failure before attempting a new run'
@@ -152,14 +152,21 @@ runs:
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-gradle-
- name: Compute the heredoc id
id: hd-id
shell: bash
run: echo heredoc=${{ github.sha }} >> $GITHUB_OUTPUT
- name: Pre-build
working-directory: ${{ inputs.working-directory }}
shell: bash
run: |
echo "::group::Pre-build"
COMMAND='${{ inputs.pre-build-command }}'
echo "::group::Pre-Build"
for attempt in $(seq 1 "${{ inputs.retries-on-failure}}"); do
$(echo $COMMAND) && break || sleep "${{ inputs.wait-between-retries }}"
echo "Attempt $attempt/${{ inputs.retries-on-failure }}"
{
${{ inputs.pre-build-command }}
} && break || sleep "${{ inputs.wait-between-retries }}"
if [ "$attempt" = "${{ inputs.retries-on-failure}}" ]; then false; fi
done
echo "::endgroup::"
- name: Build
@@ -169,17 +176,24 @@ runs:
echo "::group::Build"
COMMAND='${{ inputs.build-command }}'
for attempt in $(seq 1 "${{ inputs.retries-on-failure}}"); do
$(echo $COMMAND) && break || sleep "${{ inputs.wait-between-retries }}"
echo "Attempt $attempt/${{ inputs.retries-on-failure }}"
{
${{ inputs.build-command }}
} && break || sleep "${{ inputs.wait-between-retries }}"
if [ "$attempt" = "${{ inputs.retries-on-failure}}" ]; then false; fi
done
echo "::endgroup::"
- name: Check
shell: bash
working-directory: ${{ inputs.working-directory }}
run: |
echo "::group::Check"
COMMAND='${{ inputs.check-command }}'
for attempt in $(seq 1 "${{ inputs.retries-on-failure}}"); do
$(echo $COMMAND) && break || sleep "${{ inputs.wait-between-retries }}"
echo "Attempt $attempt/${{ inputs.retries-on-failure }}"
{
${{ inputs.check-command }}
} && break || sleep "${{ inputs.wait-between-retries }}"
if [ "$attempt" = "${{ inputs.retries-on-failure}}" ]; then false; fi
done
echo "::endgroup::"
- name: CodeCov
@@ -216,9 +230,12 @@ runs:
ORG_GRADLE_PROJECT_npmToken: ${{ inputs.npm-token }}
run: |
echo "::group::Deploy"
COMMAND='${{ inputs.deploy-command }}'
for attempt in $(seq 1 "${{ inputs.retries-on-failure}}"); do
$(echo $COMMAND) && break || sleep "${{ inputs.wait-between-retries }}"
echo "Attempt $attempt/${{ inputs.retries-on-failure }}"
{
${{ inputs.deploy-command }}
} && break || sleep "${{ inputs.wait-between-retries }}"
if [ "$attempt" = "${{ inputs.retries-on-failure}}" ]; then false; fi
done
echo "::endgroup::"
- name: Cleanup

0 comments on commit 7ffe29c

Please sign in to comment.