Skip to content

Commit 18c59cc

Browse files
authored
Update upstream dev CI (#404)
1 parent 84e7ba2 commit 18c59cc

File tree

1 file changed

+14
-133
lines changed

1 file changed

+14
-133
lines changed

.github/workflows/upstream-dev-ci.yaml

Lines changed: 14 additions & 133 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ on:
44
branches:
55
- main
66
pull_request:
7+
types: [opened, reopened, synchronize, labeled]
78
branches:
89
- main
910
schedule:
@@ -15,165 +16,45 @@ concurrency:
1516
cancel-in-progress: true
1617

1718
jobs:
18-
detect-ci-trigger:
19-
name: detect upstream-dev ci trigger
20-
runs-on: ubuntu-latest
21-
if: |
22-
github.repository == 'xarray-contrib/cf-xarray'
23-
&& (github.event_name == 'push' || github.event_name == 'pull_request')
24-
outputs:
25-
triggered: ${{ steps.detect-trigger.outputs.trigger-found }}
26-
steps:
27-
- uses: actions/checkout@v3
28-
with:
29-
fetch-depth: 2
30-
- uses: xarray-contrib/[email protected]
31-
id: detect-trigger
32-
with:
33-
keyword: "[test-upstream]"
34-
3519
upstream-dev:
3620
name: upstream-dev
3721
runs-on: ubuntu-latest
38-
needs: detect-ci-trigger
39-
if: |
40-
always()
41-
&& (
42-
(github.event_name == 'schedule' || github.event_name == 'workflow_dispatch')
43-
|| needs.detect-ci-trigger.outputs.triggered == 'true'
44-
)
22+
if: ${{ contains( github.event.pull_request.labels.*.name, 'test-upstream') && github.event_name == 'pull_request' || github.event_name == 'workflow_dispatch' }}
4523
defaults:
4624
run:
4725
shell: bash -l {0}
4826
strategy:
4927
fail-fast: false
5028
matrix:
5129
python-version: ["3.10"]
52-
outputs:
53-
artifacts_availability: ${{ steps.status.outputs.ARTIFACTS_AVAILABLE }}
5430
steps:
5531
- uses: actions/checkout@v3
5632
with:
5733
fetch-depth: 0 # Fetch all history for all branches and tags.
34+
- name: Set environment variables
35+
run: |
36+
echo "PYTHON_VERSION=${{ matrix.python-version }}" >> $GITHUB_ENV
5837
- name: Set up conda environment
59-
uses: mamba-org/provision-with-micromamba@f347426e5745fe3dfc13ec5baf20496990d0281f
38+
uses: mamba-org/provision-with-micromamba@v14
6039
with:
6140
environment-file: ci/upstream-dev-env.yml
6241
environment-name: cf_xarray_test
6342
extra-specs: |
64-
python=${{ matrix.python-version }}
43+
python="${{ matrix.python-version }}"
6544
pytest-reportlog
66-
- name: Install cf-xarray
45+
- name: Install cf_xarray
6746
run: |
6847
python -m pip install --no-deps -e .
69-
- name: Version info
70-
run: |
71-
conda info -a
72-
conda list
73-
- name: import cf_xarray
74-
run: |
75-
python -c 'import cf_xarray'
7648
- name: Run Tests
77-
if: success()
78-
id: status
7949
run: |
80-
python -m pytest -n 2 -rf \
81-
--report-log output-${{ matrix.python-version }}-log.jsonl \
82-
|| (
83-
echo '::set-output name=ARTIFACTS_AVAILABLE::true' && false
84-
)
85-
- name: Upload artifacts
50+
pytest -rf -n auto --cov=./ --cov-report=xml \
51+
--report-log output-${{ matrix.python-version }}-log.jsonl
52+
- name: Generate and publish the report
8653
if: |
8754
failure()
8855
&& steps.status.outcome == 'failure'
8956
&& github.event_name == 'schedule'
90-
&& github.repository == 'xarray-contrib/cf-xarray'
91-
uses: actions/upload-artifact@v3
92-
with:
93-
name: output-${{ matrix.python-version }}-log.jsonl
94-
path: output-${{ matrix.python-version }}-log.jsonl
95-
retention-days: 5
96-
97-
report:
98-
name: report
99-
needs: upstream-dev
100-
if: |
101-
failure()
102-
&& github.event_name == 'schedule'
103-
&& needs.upstream-dev.outputs.artifacts_availability == 'true'
104-
runs-on: ubuntu-latest
105-
defaults:
106-
run:
107-
shell: bash
108-
steps:
109-
- uses: actions/checkout@v3
110-
- uses: actions/setup-python@v4
111-
with:
112-
python-version: "3.x"
113-
- uses: actions/download-artifact@v3
114-
with:
115-
path: /tmp/workspace/logs
116-
- name: Move all log files into a single directory
117-
run: |
118-
rsync -a /tmp/workspace/logs/output-*/ ./logs
119-
ls -R ./logs
120-
- name: install dependencies
121-
run: |
122-
python -m pip install pytest
123-
- name: Parse logs
124-
run: |
125-
shopt -s globstar
126-
python .github/workflows/parse_logs.py logs/**/*-log*
127-
cat pytest-logs.txt
128-
- name: Report failures
129-
uses: actions/github-script@v6
57+
&& github.repository_owner == 'xarray-contrib'
58+
uses: xarray-contrib/issue-from-pytest-log@v1
13059
with:
131-
github-token: ${{ secrets.GITHUB_TOKEN }}
132-
script: |
133-
const fs = require('fs');
134-
const pytest_logs = fs.readFileSync('pytest-logs.txt', 'utf8');
135-
const title = "⚠️ Nightly upstream-dev CI failed ⚠️"
136-
const workflow_url = `https://github.com/${process.env.GITHUB_REPOSITORY}/actions/runs/${process.env.GITHUB_RUN_ID}`
137-
const issue_body = `[Workflow Run URL](${workflow_url})\n${pytest_logs}`
138-
139-
// Run GraphQL query against GitHub API to find the most recent open issue used for reporting failures
140-
const query = `query($owner:String!, $name:String!, $creator:String!, $label:String!){
141-
repository(owner: $owner, name: $name) {
142-
issues(first: 1, states: OPEN, filterBy: {createdBy: $creator, labels: [$label]}, orderBy: {field: CREATED_AT, direction: DESC}) {
143-
edges {
144-
node {
145-
body
146-
id
147-
number
148-
}
149-
}
150-
}
151-
}
152-
}`;
153-
154-
const variables = {
155-
owner: context.repo.owner,
156-
name: context.repo.repo,
157-
label: 'CI',
158-
creator: "github-actions[bot]"
159-
}
160-
const result = await github.graphql(query, variables)
161-
162-
// If no issue is open, create a new issue,
163-
// else update the body of the existing issue.
164-
if (result.repository.issues.edges.length === 0) {
165-
github.rest.issues.create({
166-
owner: variables.owner,
167-
repo: variables.name,
168-
body: issue_body,
169-
title: title,
170-
labels: [variables.label]
171-
})
172-
} else {
173-
github.rest.issues.update({
174-
owner: variables.owner,
175-
repo: variables.name,
176-
issue_number: result.repository.issues.edges[0].node.number,
177-
body: issue_body
178-
})
179-
}
60+
log-path: output-${{ matrix.python-version }}-log.jsonl

0 commit comments

Comments
 (0)