-
Notifications
You must be signed in to change notification settings - Fork 35
202 lines (173 loc) · 6.37 KB
/
docker.yml
File metadata and controls
202 lines (173 loc) · 6.37 KB
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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
# =============================================================================
# Docker Build, Test, and Publish
# =============================================================================
# Builds the CPU Docker image, runs the full test suite inside it,
# and publishes to GHCR on pushes to main/dev (i.e., after PR merge).
#
# Publish trigger logic:
# - PRs → build + test only (no publish)
# - Push to dev/main → build + test + publish
# When a PR is merged, GitHub fires a 'push' event on the target branch,
# which naturally triggers the publish path.
# =============================================================================
name: Docker Build, Test, and Publish
on:
push:
branches: [dev, main]
pull_request:
branches: [dev, main]
env:
REGISTRY: ghcr.io
IMAGE_NAME: mcdc-project/mcdc
jobs:
# ---------------------------------------------------------------------------
# Stage 1: Build the image
# ---------------------------------------------------------------------------
build:
name: Build Docker image
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Determine image tag
run: |
if [ "${{ github.event_name }}" == "pull_request" ]; then
echo "IMAGE_TAG=${{ github.base_ref }}" >> $GITHUB_ENV
else
echo "IMAGE_TAG=${{ github.ref_name }}" >> $GITHUB_ENV
fi
- name: Build Docker image
run: |
docker build -f containers/Dockerfile -t mcdc:${{ env.IMAGE_TAG }} .
- name: Save image as artifact
run: |
docker save mcdc:${{ env.IMAGE_TAG }} -o /tmp/mcdc-image.tar
- name: Upload image artifact
uses: actions/upload-artifact@v4
with:
name: mcdc-image
path: /tmp/mcdc-image.tar
retention-days: 1
# ---------------------------------------------------------------------------
# Stage 2: Test suite (runs in parallel after build)
# ---------------------------------------------------------------------------
unit-test:
name: Unit tests (Docker)
needs: build
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Determine image tag
run: |
if [ "${{ github.event_name }}" == "pull_request" ]; then
echo "IMAGE_TAG=${{ github.base_ref }}" >> $GITHUB_ENV
else
echo "IMAGE_TAG=${{ github.ref_name }}" >> $GITHUB_ENV
fi
- name: Download image artifact
uses: actions/download-artifact@v4
with:
name: mcdc-image
path: /tmp
- name: Load Docker image
run: docker load -i /tmp/mcdc-image.tar
- name: Verify MC/DC import
run: |
docker run --rm mcdc:${{ env.IMAGE_TAG }} python -c "import mcdc; print('MC/DC import OK')"
- name: Run unit tests
run: |
docker run --rm \
-v ${{ github.workspace }}:/opt/mcdc \
-w /opt/mcdc/test/unit \
mcdc:${{ env.IMAGE_TAG }} python run.py
regression-test:
name: Regression – ${{ matrix.mode }}
needs: build
runs-on: ubuntu-latest
timeout-minutes: ${{ matrix.timeout }}
strategy:
fail-fast: false
matrix:
mode:
- Python-Serial
- Python-MPI
- Numba-Serial
- Numba-MPI
include:
- mode: Python-Serial
run_cmd: "python run.py"
timeout: 10
- mode: Python-MPI
run_cmd: |
python run.py --mpiexec=4
python run.py --mpiexec=16 --name=slab_reed_dd_3d
timeout: 20
- mode: Numba-Serial
run_cmd: "python run.py --mode numba"
timeout: 120
- mode: Numba-MPI
run_cmd: |
python run.py --mode numba --mpiexec=4
python run.py --mode numba --mpiexec=16 --name=slab_reed_dd_3d
timeout: 120
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Determine image tag
run: |
if [ "${{ github.event_name }}" == "pull_request" ]; then
echo "IMAGE_TAG=${{ github.base_ref }}" >> $GITHUB_ENV
else
echo "IMAGE_TAG=${{ github.ref_name }}" >> $GITHUB_ENV
fi
- name: Download image artifact
uses: actions/download-artifact@v4
with:
name: mcdc-image
path: /tmp
- name: Load Docker image
run: docker load -i /tmp/mcdc-image.tar
- name: Run regression tests (${{ matrix.mode }})
run: |
docker run --rm \
-v ${{ github.workspace }}:/opt/mcdc \
-w /opt/mcdc/test/regression \
mcdc:${{ env.IMAGE_TAG }} bash -c '${{ matrix.run_cmd }}'
# ---------------------------------------------------------------------------
# Stage 3: Publish (only on push to dev/main, after all tests pass)
# ---------------------------------------------------------------------------
publish:
name: Publish to GHCR
needs: [unit-test, regression-test]
if: github.event_name == 'push'
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Download image artifact
uses: actions/download-artifact@v4
with:
name: mcdc-image
path: /tmp
- name: Load Docker image
run: docker load -i /tmp/mcdc-image.tar
- name: Login to GitHub Container Registry
if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/dev')
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Push to registry
if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/dev')
run: |
BRANCH=${{ github.ref_name }}
DATE=$(date +%Y-%m-%d)
FULL_IMAGE=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
docker tag mcdc:${BRANCH} ${FULL_IMAGE}:${BRANCH}
docker tag mcdc:${BRANCH} ${FULL_IMAGE}:${BRANCH}-${DATE}
docker push ${FULL_IMAGE}:${BRANCH}
docker push ${FULL_IMAGE}:${BRANCH}-${DATE}
echo "Pushed: ${{ env.BRANCH_NAME }} and ${{ env.BRANCH_NAME }}-${DATE}"