-
Notifications
You must be signed in to change notification settings - Fork 68
301 lines (261 loc) · 11.1 KB
/
devcontainer.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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
name: MLOS DevContainer
on:
workflow_dispatch:
inputs:
tags:
description: Manual MLOS DevContainer run aux info tags
NO_CACHE:
type: boolean
description: Disable caching?
default: false
required: false
push:
branches: [ main ]
pull_request:
branches: [ main ]
release:
types: [ published ]
merge_group:
types: [checks_requested]
schedule:
- cron: "1 0 * * *"
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}-${{ github.event_name }}
cancel-in-progress: true
jobs:
DevContainerLintBuildTestPublish:
name: DevContainer Lint/Build/Test/Publish
runs-on: ubuntu-latest
permissions:
contents: read
# Here we only test a single (latest) version of python.
env:
DOCKER_BUILDKIT: 1
BUILDKIT_INLINE_CACHE: 1
steps:
- uses: actions/checkout@v4
- name: Get commit messages
id: get-commit-messages
if: github.event_name == 'pull_request'
run: |
# Only look at the last 10 commits, to avoid getting too much data.
# If the message wasn't in there (e.g. because the push was a merge and too large), then we just ignore it.
git fetch --deepen=10
# Handle multiline output:
{
echo 'COMMIT_MESSAGES<<COMMIT_MESSAGES_EOF'
git log --format="%B" -10 ${{ github.event.before }}..${{ github.event.after }} | tee /tmp/commit_messages.txt
echo COMMIT_MESSAGES_EOF
} >> $GITHUB_OUTPUT
- name: Validate tag
if: github.ref_type == 'tag'
# Note: May need to update this for release branches in the future too.
run: |
set -x
git fetch --deepen=100
if ! git branch -a --contains ${{ github.ref_name }} | grep origin/main; then
echo "ERROR: tag ${{ github.ref_name }} doesn't appear to be included in the main branch." >&2
exit 1
fi
if ! echo "${{ github.ref_name }}" | egrep -q '^v([0-9]+\.){2,3}[0-9]+$'; then
echo "ERROR: tag ${{ github.ref_name }} doesn't appear to be a valid version tag." >&2
exit 1
fi
- name: Set NO_CACHE variable based on commit messages and for nightly builds
if: github.event_name == 'schedule' || contains(steps.get-commit-messages.outputs.COMMIT_MESSAGES, 'NO_CACHE=true') || github.event.inputs.NO_CACHE == 'true'
run: |
echo "NO_CACHE=true" >> $GITHUB_ENV
- name: Run pytest with debug logging enabled for nightly runs
if: github.event_name == 'schedule'
run: |
echo "PYTEST_EXTRA_OPTIONS=--log-level=DEBUG" >> $GITHUB_ENV
- name: Log some environment variables for debugging
run: |
set -x
printenv
echo "NO_CACHE: ${NO_CACHE:-}"
echo "EVENT_NAME: ${{ github.event_name }}"
echo "BEFORE: ${{ github.event.before }}"
echo "AFTER: ${{ github.event.after }}"
# echo "COMMIT_MESSAGES: `cat /tmp/commit_messages.txt`"
echo "COMMIT_SHA: ${{ github.sha }}"
echo "git log -1 ${{ github.sha }}: $(git log -1 ${{ github.sha }})"
echo "Manual Trigger Input Tags: ${{ github.event.inputs.tags }}"
echo "Manual Trigger Input NO_CACHE: ${{ github.event.inputs.NO_CACHE }}"
# Output the full event json for debugging.
# cat ${{ github.event_path }}
- name: Build the devcontainer image
timeout-minutes: 15
run: |
set -x
make CONDA_INFO_LEVEL=-v devcontainer
- name: Start the devcontainer in the background
timeout-minutes: 3
run: |
set -x
docker run -d --rm --user root \
--volume /var/run/docker.sock:/var/run/docker.sock \
--env DOCKER_BUILDKIT=$DOCKER_BUILDKIT \
--volume $(pwd):/workspaces/MLOS \
--env CONTAINER_WORKSPACE_FOLDER=/workspaces/MLOS \
--env LOCAL_WORKSPACE_FOLDER=$(pwd) \
--env PYTEST_EXTRA_OPTIONS=$PYTEST_EXTRA_OPTIONS \
--workdir /workspaces/MLOS \
--add-host host.docker.internal:host-gateway \
--name mlos-devcontainer mlos-devcontainer sleep 1800
- name: Fixup vscode uid/gid in the running container
timeout-minutes: 3
run: |
set -x
docker exec --user root mlos-devcontainer groupmod --non-unique -g `id -g` vscode
docker exec --user root mlos-devcontainer usermod --non-unique -u `id -u` -g `id -g` vscode
docker exec --user root mlos-devcontainer chown -R vscode:vscode /home/vscode
- name: Print some debug info from inside the container
run: |
docker exec --user vscode --env USER=vscode mlos-devcontainer printenv
- name: Check that github.com is in the ssh known_hosts file
run: |
docker exec --user vscode --env USER=vscode mlos-devcontainer grep ^github.com /home/vscode/.ssh/known_hosts
- name: Update the conda env in the devcontainer
timeout-minutes: 10
run: |
set -x
docker exec --user vscode --env USER=vscode mlos-devcontainer make CONDA_INFO_LEVEL=-v conda-env
- name: Verify expected version of python in conda env
timeout-minutes: 2
run: |
set -x
docker exec --user vscode --env USER=vscode mlos-devcontainer \
conda run -n mlos python -c \
'from sys import version_info as vers; assert (vers.major, vers.minor) == (3, 13), f"Unexpected python version: {vers}"'
- name: Check for missing licenseheaders
timeout-minutes: 3
run: |
set -x
docker exec --user vscode --env USER=vscode mlos-devcontainer make CONDA_INFO_LEVEL=-v licenseheaders
# licenseheaders changes the contents of the files, so make this check fail if there are any changes detected
git --no-pager diff --exit-code
- name: Run lint checks
timeout-minutes: 5
run: |
set -x
docker exec --user vscode --env USER=vscode --env MAKEFLAGS=-Oline mlos-devcontainer make CONDA_INFO_LEVEL=-v check
- name: Run tests
timeout-minutes: 10
run: |
set -x
# Simulate test collection in vscode.
test_count=$(docker exec --user vscode --env USER=vscode mlos-devcontainer \
conda run -n mlos python -m pytest -svxl -n auto --collect-only --rootdir /workspaces/MLOS -s --cache-clear \
| grep -c '<Function ')
if [ "${test_count:-0}" -lt 725 ]; then echo "Expected at least 725 tests, got '$test_count'" >&2; exit 1; fi
# Now actually run the tests.
docker exec --user vscode --env USER=vscode mlos-devcontainer make CONDA_INFO_LEVEL=-v test
- name: Generate and test binary distribution files
timeout-minutes: 10
run: |
set -x
docker exec --user vscode --env USER=vscode mlos-devcontainer make CONDA_INFO_LEVEL=-v dist dist-test
- name: Test rebuilding the devcontainer in the devcontainer
# FIXME:
# timeout-minutes: 3
timeout-minutes: 10
run: |
set -x
git --no-pager diff --exit-code
docker exec --user vscode --env USER=vscode mlos-devcontainer make CONDA_INFO_LEVEL=-v devcontainer
- name: Generate docs and test check them
run: |
set -x
docker exec --user vscode --env USER=vscode --env MAKEFLAGS=-Oline mlos-devcontainer make CONDA_INFO_LEVEL=-v doc
# Make sure we can publish the coverage report.
rm -f doc/build/html/htmlcov/.gitignore
- uses: actions/upload-artifact@v4
with:
name: docs
path: doc/build/html
- name: Publish package to Test PyPi
if: github.event_name == 'release' && github.ref_type == 'tag'
run: |
if [ -n "${{ secrets.PYPI_TEST_USERNAME }}" ]; then
docker exec --user vscode --env USER=vscode --env MAKEFLAGS=-Oline \
--env TWINE_USERNAME=${{ secrets.PYPI_TEST_USERNAME }} --env TWINE_PASSWORD=${{ secrets.PYPI_TEST_PASSWORD }} \
mlos-devcontainer make CONDA_INFO_LEVEL=-v publish-test-pypi
fi
- name: Publish package to PyPi
if: github.repository == 'microsoft/mlos' && github.event_name == 'release' && github.ref_type == 'tag'
run: |
if [ -n "${{ secrets.PYPI_USERNAME }}" ]; then
docker exec --user vscode --env USER=vscode --env MAKEFLAGS=-Oline \
--env TWINE_USERNAME=${{ secrets.PYPI_USERNAME }} --env TWINE_PASSWORD=${{ secrets.PYPI_PASSWORD }} \
mlos-devcontainer make CONDA_INFO_LEVEL=-v publish-pypi
fi
- name: Cleanup the devcontainer
run: |
set -x
docker stop -t 1 mlos-devcontainer || true
docker rm --force mlos-devcontainer || true
- name: Container Registry Login
if: (github.repository == 'microsoft/mlos') && (github.ref == 'refs/heads/main' || github.ref_type == 'tag')
uses: docker/login-action@v3
with:
# This is the URL of the container registry, which is configured in Github
# Settings and currently corresponds to the mlos-core ACR.
registry: ${{ secrets.ACR_LOGINURL }}
username: ${{ secrets.ACR_USERNAME }}
# This secret is configured in Github Settings.
# It can also be obtained in a keyvault in the Azure portal alongside the
# other resources used.
password: ${{ secrets.ACR_PASSWORD }}
- name: Publish the container images
# TODO: add cleanup step to remove old images
if: (github.repository == 'microsoft/mlos') && (github.ref == 'refs/heads/main' || github.ref_type == 'tag')
timeout-minutes: 15
run: |
set -x
image_tag=''
if [ "${{ github.ref_type }}" == 'tag' ]; then
image_tag="${{ github.ref_name }}"
elif [ "${{ github.ref }}" == 'refs/heads/main' ]; then
image_tag='latest'
fi
if [ -z "$image_tag" ]; then
echo "ERROR: Unhandled event condition or ref: event=${{ github.event}}, ref=${{ github.ref }}, ref_type=${{ github.ref_type }}"
exit 1
fi
docker tag devcontainer-cli:latest ${{ secrets.ACR_LOGINURL }}/devcontainer-cli:$image_tag
docker push ${{ secrets.ACR_LOGINURL }}/devcontainer-cli:$image_tag
docker tag mlos-devcontainer:latest ${{ secrets.ACR_LOGINURL }}/mlos-devcontainer:$image_tag
docker push ${{ secrets.ACR_LOGINURL }}/mlos-devcontainer:$image_tag
PublishDocs:
name: Publish Documentation
if: github.ref == 'refs/heads/main'
needs: DevContainerLintBuildTestPublish
runs-on: ubuntu-latest
# Required for github-pages-deploy-action to push to the gh-pages branch.
permissions:
contents: write
steps:
- uses: actions/checkout@v4
- uses: actions/download-artifact@v4
with:
name: docs
path: doc/build/html
- name: Check docs
run: |
set -x
# Check that the docs are not empty.
if [ ! -d doc/build/html ]; then
echo "ERROR: No docs found in doc/build/html" >&2
exit 1
fi
if [ ! -f doc/build/html/index.html ]; then
echo "ERROR: No index.html found in doc/build/html" >&2
exit 1
fi
- name: Deploy to GitHub pages
uses: JamesIves/github-pages-deploy-action@v4
with:
branch: gh-pages
folder: doc/build/html
clean: true