-
Notifications
You must be signed in to change notification settings - Fork 17
204 lines (187 loc) · 7.92 KB
/
tests.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
name: Tests
on:
push:
branches:
- main
tags:
- '*'
pull_request:
# When this workflow is queued, automatically cancel any previous running
# or pending jobs from the same branch
concurrency:
group: ${{ github.ref }}
cancel-in-progress: true
jobs:
tests:
name: ${{ matrix.os }}, Python ${{ matrix.python-version }}, Runtime ${{ matrix.runtime-version }}
runs-on: ${{ matrix.os }}
timeout-minutes: 120
# Required shell entrypoint to have properly activated conda environments
defaults:
run:
shell: bash -l {0}
strategy:
fail-fast: false
matrix:
os: ["ubuntu-latest"]
python-version: ["3.7", "3.8", "3.9"]
runtime-version: ["latest", "0.0.3"]
include:
- python-version: "3.9"
runtime-version: "latest"
os: "windows-latest"
- python-version: "3.9"
runtime-version: "latest"
os: "macos-latest"
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
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: mamba install boa conda-verify jinja2 packaging pytest
- name: Check upstream
if: github.event_name == 'pull_request' && matrix.runtime-version == 'latest'
run: |
COMMIT="$(git log -n 1 --pretty=format:%s HEAD^2)"
if [[ "$COMMIT" == *"test-upstream"* ]]
then
export TEST_UPSTREAM="true"
# Put TEST_UPSTREAM into $GITHUB_ENV so it can be used in subsequent workflow steps
echo TEST_UPSTREAM=$TEST_UPSTREAM >> $GITHUB_ENV
echo "Using development version of dask and distributed"
fi
- name: Install coiled-runtime
run: |
# If testing the latest `coiled-runtime` then install packages defined in `recipe/meta.yaml`
# Otherwise, just install directly from the coiled / conda-forge channel
if [[ ${{ matrix.runtime-version }} = 'latest' ]]
then
python ci/create_latest_runtime_meta.py
mamba env update --file latest.yaml
else
mamba install -c conda-forge coiled-runtime=${{ matrix.runtime-version }}
fi
- name: Export environment
run: |
# For debugging
echo -e "--\n--Conda Environment (re-create this with \`conda env create --name <name> -f <output_file>\`)\n--"
# FIXME: mamba env export returns empty on CI
conda env export | grep -E -v '^prefix:.*$'
- name: Build Coiled software environment
if: ${{ matrix.runtime-version == 'latest' }}
env:
DASK_COILED__TOKEN: ${{ secrets.COILED_BENCHMARK_BOT_TOKEN }}
run: |
# If testing the latest `coiled-runtime`, we need to build a Coiled software environment
# that can be used when running tests
# Coiled software environment names can't contain "." or uppercase characters
export PYTHON_VERSION_FORMATTED=$(echo "${{ matrix.python-version }}" | sed 's/\.//g' )
export OS_FORMATTED=$(python -c "import os; print(os.environ['RUNNER_OS'].lower())")
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-$OS_FORMATTED-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
echo "Creating Coiled software environment for $COILED_SOFTWARE_NAME"
# Put COILED_SOFTWARE_NAME into $GITHUB_ENV so it can be used in subsequent workflow steps
echo COILED_SOFTWARE_NAME=$COILED_SOFTWARE_NAME >> $GITHUB_ENV
coiled env create --name $COILED_SOFTWARE_NAME --conda latest.yaml
- name: Run tests
# Want to delete software environment in next step even if tests fail
continue-on-error: ${{ matrix.runtime-version == 'latest' }}
id: tests
env:
DASK_COILED__TOKEN: ${{ secrets.COILED_BENCHMARK_BOT_TOKEN }}
AWS_ACCESS_KEY_ID: ${{ secrets.RUNTIME_CI_BOT_AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.RUNTIME_CI_BOT_AWS_SECRET_ACCESS_KEY }}
run: |
# Ensure we run additional tests when testing the latest coiled-runtime
if [[ ${{ matrix.runtime-version }} = 'latest' ]]
then
export EXTRA_OPTIONS="--run-latest"
export COILED_SOFTWARE_NAME=${{ env.COILED_SOFTWARE_NAME }}
else
export EXTRA_OPTIONS=" "
fi
python -m pytest $EXTRA_OPTIONS tests
- name: Remove Coiled software environment
if: ${{ matrix.runtime-version == 'latest' }}
env:
DASK_COILED__TOKEN: ${{ secrets.COILED_BENCHMARK_BOT_TOKEN }}
run: |
# Clean up an Coiled software environments we created just for this CI build
export COILED_SOFTWARE_NAME=${{ env.COILED_SOFTWARE_NAME }}
coiled env delete $COILED_SOFTWARE_NAME
if [[ ${{ steps.tests.outcome }} != 'success' ]]
then
python -c "raise Exception('Tests failed. Please see the output from the previous step for more details.')"
fi
report:
name: report
needs: tests
if: |
always()
&& github.event_name != 'pull_request'
&& github.repository == 'coiled/coiled-runtime'
&& needs.tests.result == 'failure'
runs-on: ubuntu-latest
defaults:
run:
shell: bash
steps:
- uses: actions/checkout@v2
- name: Report failures
uses: actions/github-script@v3
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const title = "⚠️ CI failed ⚠️"
const workflow_url = `https://github.com/${process.env.GITHUB_REPOSITORY}/actions/runs/${process.env.GITHUB_RUN_ID}`
const issue_body = `[Workflow Run URL](${workflow_url})`
// Run GraphQL query against GitHub API to find the most recent open issue used for reporting failures
const query = `query($owner:String!, $name:String!, $creator:String!){
repository(owner: $owner, name: $name) {
issues(first: 1, states: OPEN, filterBy: {createdBy: $creator}, orderBy: {field: CREATED_AT, direction: DESC}) {
edges {
node {
body
id
number
}
}
}
}
}`;
const variables = {
owner: context.repo.owner,
name: context.repo.repo,
creator: "github-actions[bot]"
}
const result = await github.graphql(query, variables)
// If no issue is open, create a new issue,
// else update the body of the existing issue.
if (result.repository.issues.edges.length === 0) {
github.issues.create({
owner: variables.owner,
repo: variables.name,
body: issue_body,
title: title,
})
} else {
github.issues.update({
owner: variables.owner,
repo: variables.name,
issue_number: result.repository.issues.edges[0].node.number,
body: issue_body
})
}