Skip to content

Commit

Permalink
Restructure to use package_sync: no more setup/cleanup of coiled
Browse files Browse the repository at this point in the history
software environments, TEST_UPSTREAM and COILED_SOFTWARE_VERSION
environment variables are now gone, COILED_RUNTIME_VERSION is the only
controlling environment variable, which can take a version number,
"upstream", or "latest"
  • Loading branch information
Ian Rose committed Aug 10, 2022
1 parent 243c024 commit 148a4b1
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 191 deletions.
152 changes: 12 additions & 140 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,89 +22,6 @@ defaults:
shell: bash -l {0}

jobs:
software:
name: Setup
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ["3.8", "3.9", "3.10"]

steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0

- name: Set up environment
uses: conda-incubator/setup-miniconda@v2
with:
miniforge-variant: Mambaforge
use-mamba: true
condarc-file: ci/condarc
python-version: ${{ matrix.python-version }}
environment-file: ci/environment.yml

- name: Check upstream
run: |
if [[ ${{ github.event_name }} == "pull_request" ]]
then
export REF="HEAD^2"
else
export REF="HEAD"
fi
COMMIT="$(git log -n 1 --pretty=format:%s $REF)"
if [[ "$COMMIT" == *"test-upstream"* || ${{ github.event_name }} == "schedule" ]]
then
export TEST_UPSTREAM="true"
else
export TEST_UPSTREAM="false"
fi
# Put TEST_UPSTREAM into $GITHUB_ENV so it can be used in subsequent workflow steps
echo $TEST_UPSTREAM
echo TEST_UPSTREAM=$TEST_UPSTREAM >> $GITHUB_ENV
# Put TEST_UPSTREAM into a file so it can be downloaded in subsequent workflow jobs
echo $TEST_UPSTREAM > test_upstream.txt
- name: Build Coiled Software Environment
env:
DASK_COILED__TOKEN: ${{ secrets.COILED_BENCHMARK_BOT_TOKEN }}
run: |
export PYTHON_VERSION_FORMATTED=$(echo "${{ matrix.python-version }}" | sed 's/\.//g' )
export REF_NAME_FORMATTED=$(echo "$GITHUB_REF_NAME" | sed 's/\./-/g' )
export COILED_SOFTWARE_NAME_HEAD=dask-engineering/coiled-runtime-${{ github.event_name }}
export COILED_SOFTWARE_NAME_TAIL=$GITHUB_RUN_ID-py$PYTHON_VERSION_FORMATTED
if [[ ${{ github.event_name }} = 'pull_request' ]]
then
export COILED_SOFTWARE_NAME=$COILED_SOFTWARE_NAME_HEAD-${{ github.event.number }}-$COILED_SOFTWARE_NAME_TAIL
else
export COILED_SOFTWARE_NAME=$COILED_SOFTWARE_NAME_HEAD-$GITHUB_REF_TYPE-$REF_NAME_FORMATTED-$COILED_SOFTWARE_NAME_TAIL
fi
# Create conda environment.yaml file for the latest software environment
python ci/create_latest_runtime_meta.py
export ENV_FILE=latest.yaml
cat $ENV_FILE
mamba install coiled
echo "Creating Coiled software environment for $COILED_SOFTWARE_NAME"
coiled env create --name $COILED_SOFTWARE_NAME --conda $ENV_FILE
# Put COILED_SOFTWARE_NAME into a file so it can be downloaded in subsequent workflow jobs
echo $COILED_SOFTWARE_NAME > software_name.txt
- name: Upload environment file
uses: actions/upload-artifact@v3
with:
name: software-environment-py${{ matrix.python-version }}
path: |
latest.yaml
software_name.txt
test_upstream.txt
runtime:
name: Runtime - ${{ matrix.os }}, Python ${{ matrix.python-version }}, Runtime ${{ matrix.runtime-version }}
needs: software
Expand All @@ -115,7 +32,7 @@ jobs:
matrix:
os: ["ubuntu-latest"]
python-version: ["3.9"]
runtime-version: ["latest", "0.0.3", "0.0.4"]
runtime-version: ["upstream", "latest", "0.0.3", "0.0.4"]

steps:
- uses: actions/checkout@v2
Expand All @@ -135,16 +52,12 @@ jobs:
python-version: ${{ matrix.python-version }}
environment-file: ci/environment.yml

- name: Download software environment assets
if: matrix.runtime-version == 'latest'
uses: actions/download-artifact@v3
with:
name: software-environment-py${{ matrix.python-version }}

- name: Install coiled-runtime
env:
COILED_RUNTIME_VERSION: ${{ matrix.runtime-version }}
run: source ci/scripts/install_coiled_runtime.sh
run: |
python ci/create_runtime_meta.py
source ci/scripts/install_coiled_runtime.sh
- name: Run Coiled Runtime Tests
id: test
Expand Down Expand Up @@ -173,7 +86,7 @@ jobs:
matrix:
os: ["ubuntu-latest"]
python-version: ["3.9"]
runtime-version: ["latest", "0.0.3", "0.0.4"]
runtime-version: ["upstream", "latest", "0.0.3", "0.0.4"]

steps:
- uses: actions/checkout@v2
Expand All @@ -193,16 +106,12 @@ jobs:
python-version: ${{ matrix.python-version }}
environment-file: ci/environment.yml

- name: Download software environment assets
if: matrix.runtime-version == 'latest'
uses: actions/download-artifact@v3
with:
name: software-environment-py${{ matrix.python-version }}

- name: Install coiled-runtime
env:
COILED_RUNTIME_VERSION: ${{ matrix.runtime-version }}
run: source ci/scripts/install_coiled_runtime.sh
run: |
python ci/create_runtime_meta.py
source ci/scripts/install_coiled_runtime.sh
- name: Run benchmarking tests
id: benchmarking_tests
Expand Down Expand Up @@ -231,7 +140,7 @@ jobs:
matrix:
os: ["ubuntu-latest"]
python-version: ["3.8", "3.9", "3.10"]
runtime-version: ["latest", "0.0.3", "0.0.4"]
runtime-version: ["upstream", "latest", "0.0.3", "0.0.4"]
include:
- python-version: "3.9"
runtime-version: "latest"
Expand Down Expand Up @@ -266,16 +175,12 @@ jobs:
python-version: ${{ matrix.python-version }}
environment-file: ci/environment.yml

- name: Download software environment assets
if: matrix.runtime-version == 'latest'
uses: actions/download-artifact@v3
with:
name: software-environment-py${{ matrix.python-version }}

- name: Install coiled-runtime
env:
COILED_RUNTIME_VERSION: ${{ matrix.runtime-version }}
run: source ci/scripts/install_coiled_runtime.sh
run: |
python ci/create_runtime_meta.py
source ci/scripts/install_coiled_runtime.sh
- name: Run stability tests
id: stability_tests
Expand All @@ -301,39 +206,6 @@ jobs:
name: stability-${{ matrix.os }}-${{ matrix.runtime-version }}-py${{ matrix.python-version }}
path: stability-${{ matrix.os }}-${{ matrix.runtime-version }}-py${{ matrix.python-version }}.db

cleanup:
needs: [software, runtime, benchmarks, stability]
if: always()
name: Cleanup
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ["3.8", "3.9", "3.10"]
steps:
- uses: actions/checkout@v2

- name: Set up Python
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}

- name: Install coiled
run: python -m pip install coiled

- name: Download software environment assets
uses: actions/download-artifact@v3
with:
name: software-environment-py${{ matrix.python-version }}

- name: Remove Coiled software environment
env:
DASK_COILED__TOKEN: ${{ secrets.COILED_BENCHMARK_BOT_TOKEN }}
run: |
export SOFTWARE_NAME=$(cat software_name.txt)
echo "Deleting $SOFTWARE_NAME"
coiled env delete $SOFTWARE_NAME
report:
name: report
needs: [runtime, benchmarks, stability]
Expand Down
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,11 @@ The `coiled-runtime` test suite can be run locally with the following steps:
the Coiled Dask Engineering AWS S3 account.
2. Create a Python environment and install development dependencies as
specified in `ci/environment.yml`.
3. (Optional) If testing against an unreleased version of `coiled-runtime`,
create a Coiled software environment with the unreleased `coiled-runtime` installed
and set a local `COILED_SOFTWARE_NAME` environment variable to the name
of the software environment (e.g. `export COILED_SOFTWARE_NAME="account/software-name"`)
3. Install a coiled runtime environment. This might be from one of the environments
listed in ``environments/``, or it could be a development environment if you are
testing feature branches of dask or distributed. This test suite is configured
to run Coiled's ``package_sync`` feature, so your local environment should be copied
to the cluster.
4. Run tests with `python -m pytest tests`

Additionally, tests are automatically run on pull requests to this repository.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import shlex
import subprocess
import sys
from distutils.util import strtobool

import yaml
from jinja2 import Environment, FileSystemLoader, select_autoescape
Expand Down Expand Up @@ -40,8 +39,7 @@ def main():

# Optionally use the development version of `dask` and `distributed`
# from `dask/label/dev` conda channel
upstream = strtobool(os.environ.get("TEST_UPSTREAM", "false"))
if upstream:
if os.environ.get("COILED_RUNTIME_VERSION", "unknown") == "upstream":
upstream_packages = {"dask", "distributed"}
for idx, req in enumerate(requirements):
package_name = Requirement(req).name
Expand All @@ -53,7 +51,7 @@ def main():
"channels": ["conda-forge"],
"dependencies": requirements,
}
with open("latest.yaml", "w") as f:
with open("runtime.yaml", "w") as f:
yaml.dump(env, f)


Expand Down
8 changes: 4 additions & 4 deletions ci/scripts/install_coiled_runtime.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ set -o errexit
set -o nounset
set -o xtrace

if [[ "$COILED_RUNTIME_VERSION" = 'latest' ]]
if [[ "$COILED_RUNTIME_VERSION" = 'latest' || "$COILED_RUNTIME_VERSION" = 'upstream' ]]
then
cat latest.yaml
mamba env update --file latest.yaml
cat runtime.yaml
mamba env update --file runtime.yaml
else
mamba install -c conda-forge coiled-runtime=$COILED_RUNTIME_VERSION
fi

# For debugging
echo -e "--\n--Conda Environment (re-create this with \`conda env create --name <name> -f <output_file>\`)\n--"
mamba env export | grep -E -v '^prefix:.*$'
mamba env export | grep -E -v '^prefix:.*$'
5 changes: 1 addition & 4 deletions ci/scripts/run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,11 @@ set -o xtrace
BENCHMARK="${BENCHMARK:-false}"

# Ensure we run additional tests when testing the latest coiled-runtime
if [[ $COILED_RUNTIME_VERSION = 'latest' ]]
if [[ $COILED_RUNTIME_VERSION = 'latest' || $COILED_RUNTIME_VERSION = 'upstream' ]]
then
EXTRA_OPTIONS="--run-latest"
export COILED_SOFTWARE_NAME=$(cat software_name.txt)
export TEST_UPSTREAM=$(cat test_upstream.txt)
else
EXTRA_OPTIONS=""
unset COILED_SOFTWARE_NAME
fi
if [[ $BENCHMARK = 'true' ]]
then
Expand Down
34 changes: 4 additions & 30 deletions conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,6 @@ def pytest_collection_modifyitems(config, items):


def get_coiled_runtime_version():
if strtobool(os.environ.get("TEST_UPSTREAM", "false")):
return "upstream"
try:
return os.environ["COILED_RUNTIME_VERSION"]
except KeyError:
Expand All @@ -77,37 +75,13 @@ def get_coiled_runtime_version():
if runtime_info:
return runtime_info[0]["version"]
else:
return "latest"
return "unknown"


def get_coiled_software_name():
try:
return os.environ["COILED_SOFTWARE_NAME"]
except KeyError:
# Determine software environment from local `coiled-runtime` version (in installed)
out = subprocess.check_output(
shlex.split("conda list --json coiled-runtime"), text=True
).rstrip()
runtime_info = json.loads(out)
if runtime_info:
version = runtime_info[0]["version"].replace(".", "-")
py_version = f"{sys.version_info[0]}{sys.version_info[1]}"
return f"coiled/coiled-runtime-{version}-py{py_version}"
else:
raise RuntimeError(
"Must either specific `COILED_SOFTWARE_NAME` environment variable "
"or have `coiled-runtime` installed"
)


dask.config.set(
{
"coiled.account": "dask-engineering",
# "coiled.software": get_coiled_software_name(),
}
)
dask.config.set({"coiled.account": "dask-engineering"})

COILED_RUNTIME_VERSION = get_coiled_runtime_version()
COILED_SOFTWARE_NAME = "package_sync"


# ############################################### #
Expand Down Expand Up @@ -180,7 +154,7 @@ def test_run_benchmark(benchmark_db_session, request, testrun_uid):
dask_version=dask.__version__,
distributed_version=distributed.__version__,
coiled_runtime_version=COILED_RUNTIME_VERSION,
coiled_software_name=dask.config.get("coiled.software"),
coiled_software_name=COILED_SOFTWARE_NAME,
python_version=".".join(map(str, sys.version_info)),
platform=sys.platform,
ci_run_url=WORKFLOW_URL,
Expand Down
9 changes: 4 additions & 5 deletions tests/runtime/test_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@
import shlex
import subprocess
import sys
from distutils.util import strtobool

import coiled
import dask
import pytest
import yaml
from distributed import Client
Expand Down Expand Up @@ -74,8 +71,10 @@ def test_install_dist():
# Test that versions of packages installed are consistent with those
# specified in `meta.yaml`

if Version(dask.__version__).local or strtobool(
os.environ.get("TEST_UPSTREAM", "false")
if os.environ.get("COILED_RUNTIME_VERSION", "unknown") not in (
"upstream",
"latest",
"unknown",
):
pytest.skip("Not valid on upstream build")

Expand Down

0 comments on commit 148a4b1

Please sign in to comment.