Skip to content

Context manager support for Services (#554) #1933

Context manager support for Services (#554)

Context manager support for Services (#554) #1933

Workflow file for this run

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 ]
merge_group:
types: [checks_requested]
schedule:
- cron: "1 0 * * *"
jobs:
DevContainer:
runs-on: ubuntu-latest
# 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: 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: ${{ steps.get-commit-messages.outputs.COMMIT_MESSAGES }}"
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 \
--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: 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: 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.
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
# 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
timeout-minutes: 3
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
- name: Deploy to GitHub pages
if: github.ref == 'refs/heads/main'
uses: JamesIves/github-pages-deploy-action@v4
with:
branch: gh-pages
folder: doc/build/html
clean: true
- 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'
uses: docker/login-action@v3
with:
registry: ${{ secrets.ACR_LOGINURL }}
username: ${{ secrets.ACR_USERNAME }}
password: ${{ secrets.ACR_PASSWORD }}
- name: Publish the container images
if: github.repository == 'microsoft/mlos' && github.ref == 'refs/heads/main'
timeout-minutes: 15
# We only push to the :latest tag, to avoid needing to cleanup the
# registry manually (there's currently no API for that).
run: |
set -x
docker tag devcontainer-cli:latest ${{ secrets.ACR_LOGINURL }}/devcontainer-cli:latest
docker push ${{ secrets.ACR_LOGINURL }}/devcontainer-cli:latest
docker tag mlos-devcontainer:latest ${{ secrets.ACR_LOGINURL }}/mlos-devcontainer:latest
docker push ${{ secrets.ACR_LOGINURL }}/mlos-devcontainer:latest