Skip to content

Commit a772880

Browse files
committed
Add workflow
1 parent 361b226 commit a772880

File tree

2 files changed

+107
-0
lines changed

2 files changed

+107
-0
lines changed

.github/workflows/hypothesis.yaml

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
name: Slow Hypothesis CI
2+
on:
3+
push:
4+
branches:
5+
- "main"
6+
pull_request:
7+
branches:
8+
- "main"
9+
types: [opened, reopened, synchronize, labeled]
10+
schedule:
11+
- cron: "0 0 * * *" # Daily “At 00:00” UTC
12+
workflow_dispatch: # allows you to trigger manually
13+
14+
env:
15+
FORCE_COLOR: 3
16+
17+
jobs:
18+
detect-ci-trigger:
19+
name: detect ci trigger
20+
runs-on: ubuntu-latest
21+
if: |
22+
github.repository == 'zarr-developers/zarr=python'
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@v4
28+
with:
29+
fetch-depth: 2
30+
- uses: xarray-contrib/ci-trigger@v1
31+
id: detect-trigger
32+
with:
33+
keyword: "[skip-ci]"
34+
35+
hypothesis:
36+
name: Slow Hypothesis Tests
37+
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+
|| contains( github.event.pull_request.labels.*.name, 'run-slow-hypothesis')
45+
)
46+
defaults:
47+
run:
48+
shell: bash -l {0}
49+
50+
strategy:
51+
matrix:
52+
python-version: ['3.11']
53+
numpy-version: ['1.26']
54+
dependency-set: ["optional"]
55+
56+
steps:
57+
- uses: actions/checkout@v4
58+
- name: Set up Python
59+
uses: actions/setup-python@v5
60+
with:
61+
python-version: $PYTHON_VERSION
62+
cache: 'pip'
63+
- name: Install Hatch
64+
run: |
65+
python -m pip install --upgrade pip
66+
pip install hatch
67+
- name: Set Up Hatch Env
68+
run: |
69+
hatch env create test.py${{ matrix.python-version }}-${{ matrix.numpy-version }}-${{ matrix.dependency-set }}
70+
hatch env run -e test.py${{ matrix.python-version }}-${{ matrix.numpy-version }}-${{ matrix.dependency-set }} list-env
71+
# https://github.com/actions/cache/blob/main/tips-and-workarounds.md#update-a-cache
72+
- name: Restore cached hypothesis directory
73+
id: restore-hypothesis-cache
74+
uses: actions/cache/restore@v4
75+
with:
76+
path: .hypothesis/
77+
key: cache-hypothesis-${{ runner.os }}-${{ github.run_id }}
78+
restore-keys: |
79+
cache-hypothesis-
80+
81+
- name: Run slow Hypothesis tests
82+
if: success()
83+
id: status
84+
run: |
85+
hatch env run --env test.py${{ matrix.python-version }}-${{ matrix.numpy-version }}-${{ matrix.dependency-set }} run-hypothesis
86+
87+
# explicitly save the cache so it gets updated, also do this even if it fails.
88+
- name: Save cached hypothesis directory
89+
id: save-hypothesis-cache
90+
if: always() && steps.status.outcome != 'skipped'
91+
uses: actions/cache/save@v4
92+
with:
93+
path: .hypothesis/
94+
key: cache-hypothesis-${{ runner.os }}-${{ github.run_id }}
95+
96+
- name: Generate and publish the report
97+
if: |
98+
failure()
99+
&& steps.status.outcome == 'failure'
100+
&& github.event_name == 'schedule'
101+
&& github.repository_owner == 'zarr-developers'
102+
uses: xarray-contrib/issue-from-pytest-log@v1
103+
with:
104+
log-path: output-${{ matrix.python-version }}-log.jsonl
105+
issue-title: "Nightly Hypothesis tests failed"
106+
issue-label: "topic-hypothesis"

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ run-coverage = "pytest --cov-config=pyproject.toml --cov=pkg --cov=tests"
131131
run = "run-coverage --no-cov"
132132
run-verbose = "run-coverage --verbose"
133133
run-mypy = "mypy src"
134+
run-hypothesis = "pytest --hypothesis-show-statistics tests/test_properties.py"
134135
list-env = "pip list"
135136

136137
[tool.hatch.envs.docs]

0 commit comments

Comments
 (0)