-
Notifications
You must be signed in to change notification settings - Fork 48
179 lines (174 loc) · 5.99 KB
/
upstream-dev-ci.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
name: CI Upstream
on:
push:
pull_request:
schedule:
- cron: "0 23 * * 0" # Sun 23:00 UTC
workflow_dispatch: # allows you to trigger the workflow run manually
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
detect-ci-trigger:
name: detect upstream-dev ci trigger
runs-on: ubuntu-latest
if: github.event_name == 'push' || github.event_name == 'pull_request'
outputs:
triggered: ${{ steps.detect-trigger.outputs.trigger-found }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 2
- uses: xarray-contrib/[email protected]
id: detect-trigger
with:
keyword: "[test-upstream]"
upstream-dev:
name: upstream-dev
runs-on: ubuntu-latest
needs: detect-ci-trigger
if: |
always()
&& github.repository == 'pangeo-data/climpred'
&& (
(github.event_name == 'schedule' || github.event_name == 'workflow_dispatch')
|| needs.detect-ci-trigger.outputs.triggered == 'true'
)
defaults:
run:
shell: bash -l {0}
strategy:
fail-fast: false
matrix:
python-version: ["3.10"]
outputs:
artifacts_availability: ${{ steps.status.outputs.ARTIFACTS_AVAILABLE }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # Fetch all history for all branches and tags.
- name: Set up conda (micromamba)
uses: mamba-org/setup-micromamba@v1
with:
environment-file: ci/requirements/climpred-dev.yml
environment-name: climpred-dev
cache-environment: true
create-args: >-
python=${{ matrix.python-version }}
pytest-reportlog
conda
- name: Set up conda environment
run: |
bash ci/install-upstream-wheels.sh
- name: Install climpred (no deps)
run: |
python -m pip install --no-deps -e .
- name: Conda info
run: conda info -a
- name: Conda list
run: conda list
- name: import climpred
run: |
python -c 'import climpred; climpred.show_versions()'
- name: Run Tests
if: success()
id: status
run: |
python -m pytest --timeout=60 -rf \
--report-log output-${{ matrix.python-version }}-log.jsonl \
|| (
echo '::set-output name=ARTIFACTS_AVAILABLE::true' && false
)
- name: Upload artifacts
if: |
failure()
&& github.event_name == 'schedule'
&& steps.status.outcome == 'failure'
&& github.repository == 'pangeo-data/climpred'
uses: actions/upload-artifact@v4
with:
name: output-${{ matrix.python-version }}-log.jsonl
path: output-${{ matrix.python-version }}-log.jsonl
retention-days: 5
report:
name: report
needs: upstream-dev
if: |
always()
&& github.event_name == 'schedule'
&& github.repository == 'pangeo-data/climpred'
&& needs.upstream-dev.outputs.artifacts_availability == 'true'
runs-on: ubuntu-latest
defaults:
run:
shell: bash
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.x"
- uses: actions/download-artifact@v4
with:
path: /tmp/workspace/logs
- name: Move all log files into a single directory
run: |
rsync -a /tmp/workspace/logs/output-*/ ./logs
ls -R ./logs
- name: Parse logs
run: |
shopt -s globstar
wget https://raw.githubusercontent.com/pydata/xarray/main/.github/workflows/parse_logs.py
python -m pip install pytest
ls logs/**/*-log*
ls
python parse_logs.py logs/**/*-log*
cat pytest-logs.txt
- name: Report failures
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const fs = require('fs');
const pytest_logs = fs.readFileSync('pytest-logs.txt', 'utf8');
const title = "⚠️ Nightly upstream-dev 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})\n${pytest_logs}`
// 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!, $label:String!){
repository(owner: $owner, name: $name) {
issues(first: 1, states: OPEN, filterBy: {createdBy: $creator, labels: [$label]}, orderBy: {field: CREATED_AT, direction: DESC}) {
edges {
node {
body
id
number
}
}
}
}
}`;
const variables = {
owner: context.repo.owner,
name: context.repo.repo,
label: 'CI',
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.rest.issues.create({
owner: variables.owner,
repo: variables.name,
body: issue_body,
title: title,
labels: [variables.label]
})
} else {
github.rest.issues.update({
owner: variables.owner,
repo: variables.name,
issue_number: result.repository.issues.edges[0].node.number,
body: issue_body
})
}