Skip to content

Commit 8c7074d

Browse files
authored
[feature] Added retry-command GitHub action
Improved also the chromedriver options for selenium tests.
1 parent 3957466 commit 8c7074d

File tree

4 files changed

+103
-4
lines changed

4 files changed

+103
-4
lines changed
+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: "Retry Command"
2+
3+
description: "Retries a shell command if it fails"
4+
5+
inputs:
6+
command:
7+
description: "The shell command to run"
8+
required: true
9+
max_attempts:
10+
description: "Number of retry attempts"
11+
required: false
12+
default: "3"
13+
delay_seconds:
14+
description: "Delay between retries in seconds"
15+
required: false
16+
default: "5"
17+
18+
runs:
19+
using: "composite"
20+
steps:
21+
- name: Retry Command
22+
shell: bash
23+
run: |
24+
attempts=0
25+
until [ $attempts -ge ${{ inputs.max_attempts }} ]
26+
do
27+
echo "Attempt $((attempts+1)) of ${{ inputs.max_attempts }}..."
28+
eval "${{ inputs.command }}" && break
29+
attempts=$((attempts+1))
30+
if [ $attempts -lt ${{ inputs.max_attempts }} ]; then
31+
echo "Command failed. Waiting ${{ inputs.delay_seconds }}s before retry..."
32+
sleep ${{ inputs.delay_seconds }}
33+
else
34+
echo "Command failed after $attempts attempts."
35+
exit 1
36+
fi
37+
done

docs/developer/index.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Developer Docs
1616
./admin-utilities.rst
1717
./test-utilities.rst
1818
./other-utilities.rst
19-
./reusable-workflows.rst
19+
./reusable-github-utils.rst
2020

2121
Other useful resources:
2222

docs/developer/reusable-workflows.rst renamed to docs/developer/reusable-github-utils.rst

+61-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,66 @@
1-
Re-usable GitHub Workflows
2-
==========================
1+
Re-usable GitHub Actions and Workflows
2+
======================================
3+
4+
GitHub Actions
5+
--------------
6+
7+
Retry Command
8+
~~~~~~~~~~~~~
9+
10+
This GitHub Action retries a shell command if it fails. It is useful for
11+
handling flaky tests in CI/CD pipelines.
12+
13+
**Inputs**
14+
15+
- ``command`` (required): The shell command to run.
16+
- ``max_attempts`` (optional): The number of retry attempts. Defaults to
17+
``3``.
18+
- ``delay_seconds`` (optional): The delay between retries in seconds.
19+
Defaults to ``5``.
20+
21+
**Usage Example**
22+
23+
You can use this action in your workflow as follows:
24+
25+
.. code-block:: yaml
26+
27+
name: Retry Example
28+
29+
on:
30+
push:
31+
branches:
32+
- main
33+
34+
jobs:
35+
retry-command-example:
36+
runs-on: ubuntu-latest
37+
steps:
38+
- name: Checkout code
39+
uses: actions/checkout@v3
40+
41+
- name: Test
42+
uses: openwisp/openwisp-utils/.github/actions/retry-command@master
43+
with:
44+
delay_seconds: 30
45+
max_attempts: 5
46+
command: ./runtests.py --parallel
47+
env:
48+
SELENIUM_HEADLESS: 1
49+
50+
This example retries the ``./runtests.py --parallel`` command up to 5
51+
times with a 30 second delay between attempts.
52+
53+
.. note::
54+
55+
If the command continues to fail after the specified number of
56+
attempts, the action will exit with a non-zero status, causing the
57+
workflow to fail.
58+
59+
GitHub Workflows
60+
----------------
361

462
Replicate Commits to Version Branch
5-
-----------------------------------
63+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
664

765
This re-usable workflow replicates commits from the ``master`` branch to a
866
version branch. The version branch name is derived from the version of the

openwisp_utils/tests/selenium.py

+4
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,10 @@ def get_chrome_webdriver(cls):
8888
options.binary_location = CHROME_BIN
8989
options.add_argument('--window-size=1366,768')
9090
options.add_argument('--ignore-certificate-errors')
91+
options.add_argument('--no-sandbox')
92+
options.add_argument('--disable-gpu')
93+
options.add_argument('--disable-dev-shm-usage')
94+
options.add_argument('--disable-features=VizDisplayCompositor')
9195
# When running Selenium tests with the "--parallel" flag,
9296
# each TestCase class requires its own browser instance.
9397
# If the same "remote-debugging-port" is used for all

0 commit comments

Comments
 (0)