Skip to content

Commit

Permalink
ci: use nick-invision/retry to automate retries for a step
Browse files Browse the repository at this point in the history
Configured GitHub Actions to use nick-invision/retry for repeating a step automatically. This replaces manual intervention with an automated tool, enhancing reliability and efficiency.
  • Loading branch information
uhobeike committed Jun 1, 2024
1 parent 9076e1a commit 1c9b3b4
Showing 1 changed file with 8 additions and 43 deletions.
51 changes: 8 additions & 43 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ on:
- '**.md'

env:
TIME-OUT-TEST-NUM: 2
RETRY-TEST-NUM: 10

jobs:
test:
runs-on: ubuntu-22.04
timeout-minutes: 5
container: osrf/ros:humble-desktop-full
steps:
- uses: actions/checkout@v2
Expand All @@ -43,46 +43,11 @@ jobs:
colcon build --symlink-install --cmake-args -DCMAKE_BUILD_TYPE=Release
shell: bash
- name: Exec
run: |
source /root/ros2_ws/install/setup.bash
ros2 run emcl2 test.bash
shell: bash

retry:
runs-on: ubuntu-22.04
needs: test
if: ${{ always() && needs.test.result == 'failure' }}
steps:
- uses: actions/github-script@v6
uses: nick-invision/retry@v3
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
async function run() {
const { owner, repo } = context.repo;
const workflow_id = 'rerun.yml';
const ref = ('${{ github.head_ref }}' === '' || '${{ github.head_ref }}' === 'main') ? 'main' : '${{ github.head_ref }}';
const run_id = context.runId;
try {
const workflow_run = await github.rest.actions.getWorkflowRun({
owner,
repo,
run_id
});
if (workflow_run.data.run_attempt < ${{ env.RETRY-TEST-NUM }}) {
console.log('Triggering workflow dispatch...');
await github.rest.actions.createWorkflowDispatch({
owner,
repo,
workflow_id,
ref
});
} else {
console.log('Conditions not met for re-dispatch.');
}
} catch (error) {
console.error('Failed to fetch workflow run or dispatch:', error);
}
}
run();
timeout_minutes: ${{ env.TIME-OUT-TEST-NUM }}
max_attempts: ${{ env.RETRY-TEST-NUM }}
command: |
source /root/ros2_ws/install/setup.bash
ros2 run emcl2 test.bash
shell: bash

0 comments on commit 1c9b3b4

Please sign in to comment.