-
Notifications
You must be signed in to change notification settings - Fork 62
184 lines (161 loc) · 6.44 KB
/
build-and-test-callable.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
# build-and-test-callable.yml
#
# - Builds PyMFEM in three stages:
# - MFEM dependencies + MFEM
# - SWIG bindings
# - PyMFEM
# - Runs tests under `run_examples.py`
# - If there is a failure, uploads test outputs as an artifact
name: Build and Test
on:
workflow_call:
inputs:
os:
description: 'Operating system'
type: string
default: 'ubuntu-latest'
python-version:
description: 'Python version'
type: string
default: '3.9'
mfem-branch:
description: 'MFEM branch to checkout'
type: string
default: 'default' # 'default' uses a specific commit hash defined in setup.py:repos_sha
parallel:
description: 'Build parallel version'
type: boolean
default: false
cuda:
description: 'Build with CUDA'
type: boolean
default: false
cuda-toolkit-version:
type: string
default: '12.6.0'
cuda-driver-version:
type: string
default: '560.28.03'
libceed:
description: 'Build with libCEED'
type: boolean
default: false
gslib:
description: 'Build with GSlib'
type: boolean
default: false
phases:
description: 'When true, run each build step individually (mfem, swig, pymfem)'
type: boolean
default: true
jobs:
build-and-test:
runs-on: ${{ inputs.os }}
# Reference for $${{ x && y || z }} syntax: https://7tonshark.com/posts/github-actions-ternary-operator/
name: >-
${{ inputs.os }} |
${{ inputs.mfem-branch }} |
${{ inputs.python-version }} |
${{ inputs.parallel && 'parallel' || 'serial' }}
${{ inputs.cuda && '| cuda' || '' }}${{ inputs.libceed && '| libceed' || '' }}${{ inputs.gslib && '| gslib' || '' }}
env:
CUDA_HOME: '/usr/local/cuda'
# These are all passed to setup.py as one concatenated string
build-flags: >-
${{ inputs.parallel && '--with-parallel' || '' }}
${{ inputs.cuda && '--with-cuda' || '' }}
${{ inputs.libceed && '--with-libceed' || '' }}
${{ inputs.gslib && '--with-gslib' || '' }}
${{ (!(inputs.mfem-branch == 'default') && format('--mfem-branch=''{0}''', inputs.mfem-branch)) || '' }}
# -------------------------------------------------------------------------------------------------
# Begin workflow
# -------------------------------------------------------------------------------------------------
steps:
- name: Checkout repo
uses: actions/checkout@v4
- name: Set up Python ${{ inputs.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ inputs.python-version }}
# -------------------------------------------------------------------------------------------------
# Download/install dependencies
# -------------------------------------------------------------------------------------------------
- name: Install core dependencies via requirements.txt
run: pip install -r requirements.txt --verbose
- name: Install MPI
if: inputs.parallel
run: |
sudo apt-get install mpich libmpich-dev
pip install mpi4py
- name: Purge PIP chach
run: pip cache purge
- name: Cache CUDA
if: inputs.cuda
id: cache-cuda
uses: actions/cache@v4
with:
path: ~/cache
key: cuda-installer-${{ inputs.cuda-toolkit-version }}-${{ inputs.cuda-driver-version }}
- name: Download CUDA
if: inputs.cuda && steps.cache-cuda.outputs.cache-hit == false
run: |
CUDA_URL="https://developer.download.nvidia.com/compute/cuda/${{ inputs.cuda-toolkit-version }}/local_installers/cuda_${{ inputs.cuda-toolkit-version }}_${{ inputs.cuda-driver-version }}_linux.run"
curl -o ~/cache/cuda.run --create-dirs $CUDA_URL
- name: Install CUDA
if: inputs.cuda
run: |
# The --silent flag is necessary to bypass user-input, e.g. accepting the EULA
sudo sh ~/cache/cuda.run --silent --toolkit
echo "/usr/local/cuda/bin" >> $GITHUB_PATH
- name: Print dependency information
run: |
pip list
printf "\n\n---------- MPI ----------\n"
mpiexec --version || printf "MPI not installed"
printf "\n\n---------- CUDA ----------\n"
nvcc --version || printf "CUDA not installed"
# -------------------------------------------------------------------------------------------------
# Build MFEM + SWIG Bindings + PyMFEM
# -------------------------------------------------------------------------------------------------
- name: Build MFEM (step 1)
if: inputs.phases
run: python setup.py install --ext-only --vv ${{ env.build-flags }}
- name: Build SWIG wrappers (step 2)
if: inputs.phases
run: python setup.py install --swig --vv ${{ env.build-flags }}
- name: Build PyMFEM (step 3)
if: inputs.phases
run: python setup.py install --skip-ext --skip-swig --vv ${{ env.build-flags }}
- name: Build all (steps 1-3)
if: inputs.phases == false
run: python setup.py install --vv ${{ env.build-flags }}
# -------------------------------------------------------------------------------------------------
# Run tests
# -------------------------------------------------------------------------------------------------
- name: Run tests (serial)
if: inputs.parallel == false
run: |
cd test
python run_examples.py -serial -verbose
- name: Run tests (parallel)
if: inputs.parallel
run: |
cd test
python run_examples.py -parallel -verbose -np 2
# -------------------------------------------------------------------------------------------------
# Generate an artifact (output of tests) on failure
# -------------------------------------------------------------------------------------------------
- name: Generate test results artifact
id: generate-artifact
run: |
tar -cvzf sandbox.tar.gz test/sandbox
# generate a name for the artifact
txt=$(python -c "import datetime;print(datetime.datetime.now().strftime('%H_%M_%S_%f'))")
echo name="test_results_"${txt}"_"${{ github.run_id }}".tar.gz" >> $GITHUB_OUTPUT
- name: Upload Artifact
uses: actions/upload-artifact@v4
if: failure()
with:
name: ${{ steps.generate-artifact.outputs.name }}
path: sandbox.tar.gz
retention-days: 1