Skip to content

Commit b4035ec

Browse files
committed
misc: Address review comments
1 parent e722b59 commit b4035ec

8 files changed

Lines changed: 175 additions & 224 deletions

File tree

.github/actions/docker-run/action.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ runs:
4343
done <<< "$ENV_INPUT"
4444
# Remove the leading space from the first concatenation
4545
ENV_STRING="${ENV_STRING# }"
46-
echo "env=$ENV_STRING" >> "$GITHUB_OUTPUT"
46+
echo "docker_environment_args=$ENV_STRING" >> "$GITHUB_OUTPUT"
4747
4848
- id: dockerrun
4949
name: "Run command ${{ inputs.command }} in ${{ inputs.tag }} docker container"
@@ -56,6 +56,6 @@ runs:
5656
${{ inputs.args }} \
5757
--name "ci-${NAME:-${{ inputs.tag }}}-${{ inputs.uid }}" \
5858
--env-file=docker/coverage.env \
59-
${{ steps.processenv.outputs.env }} \
59+
${{ steps.processenv.outputs.docker_environment_args }} \
6060
"${{ inputs.tag }}_${{ inputs.uid }}" \
6161
${{ inputs.command }}

.github/actions/readme.md

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
# Devito Actions
2+
3+
The Devito actions can either be used from the Github interface:
4+
```yaml
5+
uses: devitocodes/devito/.github/actions/docker-build@main
6+
```
7+
8+
Or internally from within the repository:
9+
```yaml
10+
uses: ./.github/actions/docker-run
11+
```
12+
13+
## `docker-build`
14+
15+
Inputs:
16+
17+
- `file`: Dockerfile containing build instructions (default: `Dockerfile`)
18+
- `tag`: Tag to add to the built image
19+
- `base`: Base docker image to build on top of
20+
- `args`: Arguments to pass to `docker build`
21+
22+
Outputs:
23+
24+
- `unique`: Unique identifier for the CI run (ie: `${{ steps.build.outputs.unique }}`)
25+
26+
Example:
27+
28+
```yaml
29+
jobs:
30+
test:
31+
steps:
32+
- id: build
33+
name: Build docker image for Devito
34+
uses: ./.github/actions/docker-build
35+
with:
36+
file: docker/Dockerfile.devito
37+
tag: tag-related-to-test-config
38+
base: base-image-to-build-from
39+
args: "--more-docker-build-args"
40+
```
41+
42+
## `docker-run`
43+
44+
Inputs:
45+
46+
- `uid`: Unique identifier output from docker-build action
47+
- `tag`: Tag of the built image to use
48+
- `name`: Name substring for docker to use when running the command (optional)
49+
- `args`: Arguments to pass to `docker run`, `--init -t --rm` are always added
50+
- `env`: Environment variables to set inside the docker container, one environment variable per line
51+
-command: Command to execute inside of the docker container
52+
53+
### Notes
54+
55+
- The UID must be unique, easily obtained from build action
56+
- The tag must match built image, easily obtained from build action
57+
- If you provide a custom name `foo` the container name will be `ci-foo-UUUUUUUUUU` where UUUUUUUUUU is the UID
58+
- The default args `--init -t --rm` are _always_ added
59+
- Environment variables must be passed a single environment variable per line, best achieved with the (`|`) syntax in yaml
60+
- Only a single command is executed, not a list of commands. Using `;` or `&&` will result in subsequent commands being executed outside of the docker environment
61+
62+
Example:
63+
64+
```yaml
65+
jobs:
66+
test:
67+
steps:
68+
- name: Run a command in a previously built Docker container
69+
uses: ./.github/actions/docker-run
70+
with:
71+
uid: ${{ steps.build.outputs.unique }}
72+
tag: tag-related-to-test-config
73+
name: completely-optional-name
74+
args: "--more-docker-run-args"
75+
env: |
76+
FOO=value1
77+
BAR=value2
78+
command: |
79+
mpiexec -n 4 \
80+
python \
81+
my_complicated_script.py --arg1 -v
82+
```
83+
84+
## `docker-clean`
85+
86+
Inputs:
87+
88+
- `uid`: Unique identifier output from docker-build action
89+
- `tag`: Tag of the built image to use
90+
91+
### Notes
92+
93+
- UID must be unique, easily obtained from build action
94+
- Tag must match built image, easily obtained from build action
95+
- Use `if: always()` to always clean up the image, even if the workflow fails
96+
97+
Example:
98+
99+
```yaml
100+
jobs:
101+
test:
102+
steps:
103+
- name: Cleanup Docker image
104+
if: always()
105+
uses: ./.github/actions/docker-clean
106+
with:
107+
uid: ${{ steps.build.outputs.unique }}
108+
tag: tag-related-to-test-config
109+
```

.github/workflows/docker-devito.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ jobs:
178178
run: |
179179
docker run ${{ matrix.flag }} --rm -t --name "${CONTAINER_NAME}" \
180180
devitocodes/devito:${{ matrix.tag }}-dev \
181-
pytest ${{ matrix.test }}
181+
pytest -v ${{ matrix.test }}
182182
183183
deploy-devito-manifest:
184184
needs: deploy-devito
@@ -292,4 +292,4 @@ jobs:
292292
run: |
293293
docker run ${{ matrix.flag }} --rm -t --name "${CONTAINER_NAME}" \
294294
devitocodes/devito:${{ matrix.tag }}-dev \
295-
pytest ${{ matrix.test }}
295+
pytest -v ${{ matrix.test }}

.github/workflows/examples-mpi.yaml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,15 +71,17 @@ jobs:
7171
ipcluster start --profile=mpi --engines=mpi -n 4 --daemonize
7272
# A few seconds to ensure workers are ready
7373
sleep 10
74-
py.test --nbval examples/mpi
74+
pytest -v --nbval examples/mpi
7575
ipcluster stop --profile=mpi
7676
7777
- name: Test seismic examples
7878
run: |
79-
mpirun ${{ matrix.mpiarg }} pytest examples/seismic/tti/tti_example.py
80-
mpirun ${{ matrix.mpiarg }} pytest examples/seismic/elastic/elastic_example.py
81-
mpirun ${{ matrix.mpiarg }} pytest examples/seismic/viscoacoustic/viscoacoustic_example.py
82-
mpirun ${{ matrix.mpiarg }} pytest examples/seismic/viscoelastic/viscoelastic_example.py
79+
mpirun ${{ matrix.mpiarg }} \
80+
pytest -v \
81+
examples/seismic/tti/tti_example.py \
82+
examples/seismic/elastic/elastic_example.py \
83+
examples/seismic/viscoacoustic/viscoacoustic_example.py \
84+
examples/seismic/viscoelastic/viscoelastic_example.py
8385
8486
- name: Test fwi examples with mpi
8587
run: |

.github/workflows/pytest-core-mpi.yaml

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,22 @@ jobs:
4747
- name: Test with pytest
4848
run: |
4949
python3 scripts/clear_devito_cache.py
50-
python3 -m pytest --cov --cov-config=.coveragerc --cov-report=xml -m parallel tests/
50+
python3 -m pytest \
51+
-v \
52+
--cov \
53+
--cov-config=.coveragerc \
54+
--cov-report=xml \
55+
-m parallel \
56+
tests/
5157
5258
- name: Test examples with MPI
5359
run: |
5460
python3 scripts/clear_devito_cache.py
55-
DEVITO_MPI=1 mpirun -n 2 python3 -m pytest examples/seismic/acoustic
56-
DEVITO_MPI=1 mpirun -n 2 python3 -m pytest examples/seismic/tti
61+
DEVITO_MPI=1 mpirun -n 2 \
62+
python3 -m pytest \
63+
-v \
64+
examples/seismic/acoustic \
65+
examples/seismic/tti
5766
5867
- name: Upload coverage to Codecov
5968
uses: codecov/codecov-action@v5
@@ -104,27 +113,28 @@ jobs:
104113
env: |
105114
CODECOV_TOKEN=${{ secrets.CODECOV_TOKEN }}
106115
OMP_NUM_THREADS=1
107-
command: "pytest tests/test_mpi.py"
108-
109-
- name: Test acoustic example with MPI
110-
uses: ./.github/actions/docker-run
111-
with:
112-
uid: ${{ steps.build.outputs.unique }}
113-
tag: ${{ matrix.name }}
114-
env: |
115-
DEVITO_MPI=1
116-
OMP_NUM_THREADS=1
117-
command: "mpiexec -n 2 pytest examples/seismic/acoustic"
118-
119-
- name: Test tti example with MPI
116+
command: |
117+
pytest \
118+
-v \
119+
--cov \
120+
--cov-config=.coveragerc \
121+
--cov-report=xml \
122+
tests/test_mpi.py
123+
124+
- name: Test acoustic and TTI examples with MPI
120125
uses: ./.github/actions/docker-run
121126
with:
122127
uid: ${{ steps.build.outputs.unique }}
123128
tag: ${{ matrix.name }}
124129
env: |
125130
DEVITO_MPI=1
126131
OMP_NUM_THREADS=1
127-
command: "mpiexec -n 2 pytest examples/seismic/tti"
132+
command: |
133+
mpiexec -n 2 \
134+
pytest \
135+
-v \
136+
examples/seismic/acoustic \
137+
examples/seismic/tti
128138
129139
- name: Cleanup docker image
130140
if: always()

.github/workflows/pytest-core-nompi.yaml

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ jobs:
161161
- name: Test with pytest
162162
run: |
163163
pytest \
164+
-v \
164165
-k "${{ matrix.test-set }}" \
165166
-m "not parallel" \
166167
--cov \
@@ -235,25 +236,6 @@ jobs:
235236
tag: ${{ matrix.name }}
236237
base: devitocodes/bases:cpu-${{ matrix.arch }}
237238

238-
- name: Get the Docker image Python version
239-
uses: ./.github/actions/docker-run
240-
with:
241-
uid: ${{ steps.build.outputs.unique }}
242-
tag: ${{ matrix.name }}
243-
command: >
244-
python3 --version | grep "Python " | cut -d' ' -f2 | cut -d'.' -f1,2 > dockerpythonversion.txt
245-
246-
- name: Check Docker image Python version
247-
run: |
248-
declared_pyver="${{ matrix.python-version }}"
249-
actual_pyver=$(cat dockerpythonversion.txt)
250-
echo "Declared Python version: $declared_pyver"
251-
echo "Actual Python version: $actual_pyver"
252-
if [ "$declared_pyver" != "$actual_pyver" ]; then
253-
echo "Python version mismatch: declared $declared_pyver, image has $actual_pyver"
254-
exit 1
255-
fi
256-
257239
- name: Test with pytest
258240
uses: ./.github/actions/docker-run
259241
with:
@@ -263,6 +245,7 @@ jobs:
263245
CODECOV_TOKEN=${{ secrets.CODECOV_TOKEN }}
264246
command: |
265247
pytest \
248+
-v \
266249
-k "${{ matrix.test-set }}" \
267250
-m "not parallel" \
268251
--cov \

.github/workflows/pytest-gpu.yaml

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,10 @@ jobs:
115115
uid: ${{ steps.build.outputs.unique }}
116116
tag: ${{ matrix.name }}
117117
args: ${{ matrix.dockerflags }}
118-
env: |
119-
command: pytest ${{ matrix.test_examples }}
118+
command: |
119+
pytest \
120+
-v \
121+
${{ matrix.test_examples }}
120122
121123
- name: Test examples with MPI
122124
uses: ./.github/actions/docker-run
@@ -125,9 +127,14 @@ jobs:
125127
tag: ${{ matrix.name }}
126128
args: ${{ matrix.dockerflags }}
127129
env: |
130+
CI=true
128131
DEVITO_LOGGING=DEBUG
129132
DEVITO_MPI=1
130-
command: mpiexec -n 2 pytest ${{ matrix.test_examples }}
133+
command: |
134+
mpiexec -n 2 \
135+
pytest \
136+
-v \
137+
${{ matrix.test_examples }}
131138
132139
- name: Cleanup docker image
133140
if: always()

0 commit comments

Comments
 (0)