I'm trying to use GitHub Actions for CI testing, so far I have my test workflow as follows:
name: test
on: [push]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions/setup-node@v1
with:
node-version: 12
- run: npm install
- name: test
run: |
npm run lint
npm test
env:
CI: true
.github/workflows/test.yml
It is working fine, except I want to retry the test
step (or the whole job) once if the tests fails.
Basically, the same behavior you get with travis-retry
:
script:
- npm run lint
- travis_retry npm test
or with Gitlab CI:
test:
stage: test
retry: 1
script:
- npm run lint
- npm test
Not sure if there is a way for this or a reasonably simple workaround
If you have failing jobs in a workflow run, you'll now see a new drop-down menu where you can choose “Re-run failed jobs” in addition to the existing “Re-run all jobs”. For a completed run, each job listed in the sidebar has a re-run icon when you hover over it. Jobs can also be re-run directly from the logs view.
Click on the pull request number, to the right of the pull request branch name. To re-run failed checks, click Re-run and select Re-run Failed Checks. To re-run individual checks, hover over the individual check you want to re-run and select the icon to re-run the check.
Job execution time - Each job in a workflow can run for up to 6 hours of execution time. If a job reaches this limit, the job is terminated and fails to complete.
Each job runs in a runner environment specified by runs-on . You can run an unlimited number of jobs as long as you are within the workflow usage limits. For more information, see "Usage limits and billing" for GitHub-hosted runners and "About self-hosted runners" for self-hosted runner usage limits.
For your particular use case, just do:
npm test || npm test
Action Retry seems to work well in my testing
https://github.com/nick-invision/retry/
I was able to use it with multi-part commands as long as they were single line (for example do-this && do-that
)
I would say that you need to manage the retry logic on code level. Meaning, implement/integrate such mechanic to handle and execute again only the failed tests. I'm afraid simply
want to retry the test step (or the whole job) once if the tests fails.
will execute all your tests, may even overwrite outputs, like reports and logs from the first run.
In my experience, I have used a wrapper (shell) script. Here is how it could be achieved:
#!/usr/bin/env bash
{ # try
# your npm test command here, that saves as output - failed tests
} || { # catch
# retry failed tests
if [ -f ./rerun-failed-file ]; then
echo "============= [WARN] Rerun file found! =============="
echo "============= [WARN] Rerunning FAILED tests mode. =============="
# run npm test command that picks up the failed tests & aggregate test artifacts
fi
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With