-
Notifications
You must be signed in to change notification settings - Fork 3
130 lines (109 loc) · 5.41 KB
/
python-pull-request.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
name: Test PR
on:
pull_request:
types: [opened, synchronize, reopened]
push:
branches:
- develop
schedule:
- cron: "9 2 * * 0" # at 9:02 on sunday
workflow_dispatch:
env:
UV_SYSTEM_PYTHON: 1
jobs:
quality:
uses: ecmwf-actions/reusable-workflows/.github/workflows/qa-precommit-run.yml@v2
with:
skip-hooks: "no-commit-to-branch"
checks:
strategy:
fail-fast: false
matrix:
platform: ["ubuntu-latest", "macos-latest"]
python-version: ["3.9", "3.10", "3.11"]
install-mode: ${{ (github.event_name == 'schedule' || github.event_name == 'workflow_dispatch') && fromJSON('["all"]') || fromJSON('["local-changes", "all"]') }}
runs-on: ${{ matrix.platform }}
timeout-minutes: 60
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Set up Python ${{ matrix.python-version }}
uses: astral-sh/setup-uv@v5
with:
python-version: ${{ matrix.python-version }}
enable-cache: true
- name: Install test dependencies
run: |
uv pip install pytest pytest-md pytest-emoji
- name: Detect changed packages
id: changed-packages
run: |
if [ "${{ github.event_name }}" == "pull_request" ]; then
# For pull requests, compare with the PR base
MERGE_BASE=$(git merge-base origin/${{ github.event.pull_request.base.ref }} ${{ github.event.pull_request.head.sha }})
CHANGED_FILES=$(git diff --name-only $MERGE_BASE...${{ github.event.pull_request.head.sha }})
elif [ "${{ github.event_name }}" == "push" ]; then
# For pushes, compare with the previous commit
CHANGED_FILES=$(git diff --name-only HEAD^ HEAD)
else
# For scheduled runs, check all files
CHANGED_FILES=$(git ls-files '*.py')
fi
echo "Changed files:"
echo "$CHANGED_FILES"
echo "training_changed=$(echo "$CHANGED_FILES" | grep -q '^training/' && echo 'true' || echo 'false')" >> $GITHUB_OUTPUT
echo "graphs_changed=$(echo "$CHANGED_FILES" | grep -q '^graphs/' && echo 'true' || echo 'false')" >> $GITHUB_OUTPUT
echo "models_changed=$(echo "$CHANGED_FILES" | grep -q '^models/' && echo 'true' || echo 'false')" >> $GITHUB_OUTPUT
echo "integration_changed=$(echo "$CHANGED_FILES" | grep -q '^tests/' && echo 'true' || echo 'false')" >> $GITHUB_OUTPUT
- name: Install packages
if: (steps.changed-packages.outputs.integration_changed == 'true' || steps.changed-packages.outputs.training_changed == 'true' || steps.changed-packages.outputs.graphs_changed == 'true' || steps.changed-packages.outputs.models_changed == 'true')
run: |
PACKAGES=""
if [[ ${{ matrix.install-mode }} == 'local-changes' ]]; then
# Install from local if changed, otherwise from PyPI
if [[ ${{ steps.changed-packages.outputs.training_changed }} == 'true' ]]; then
PACKAGES="$PACKAGES -e ./training[all,tests]"
else
PACKAGES="$PACKAGES anemoi-training[all,tests]"
fi
if [[ ${{ steps.changed-packages.outputs.graphs_changed }} == 'true' ]]; then
PACKAGES="$PACKAGES -e ./graphs[all,tests]"
else
PACKAGES="$PACKAGES anemoi-graphs[all,tests]"
fi
if [[ ${{ steps.changed-packages.outputs.models_changed }} == 'true' ]]; then
PACKAGES="$PACKAGES -e ./models[all,tests]"
else
PACKAGES="$PACKAGES anemoi-models[all,tests]"
fi
else
# Install all packages from local
PACKAGES="-e ./training[all,tests] -e ./graphs[all,tests] -e ./models[all,tests]"
fi
uv pip install $PACKAGES
- name: Run pytest for training package
if: matrix.install-mode == 'all' || steps.changed-packages.outputs.training_changed == 'true'
uses: pavelzw/pytest-action@v2
with:
report-title: "Test report Anemoi Training (python ${{ matrix.python-version }} on ${{ matrix.platform }}, ${{ matrix.install-mode }} mode)"
custom-pytest: uv run --frozen pytest ./training
- name: Run pytest for graphs package
if: matrix.install-mode == 'all' || steps.changed-packages.outputs.graphs_changed == 'true'
uses: pavelzw/pytest-action@v2
with:
report-title: "Test report Anemoi Graphs (python ${{ matrix.python-version }} on ${{ matrix.platform }}, ${{ matrix.install-mode }} mode)"
custom-pytest: uv run --frozen pytest ./graphs
- name: Run pytest for models package
if: matrix.install-mode == 'all' || steps.changed-packages.outputs.models_changed == 'true'
uses: pavelzw/pytest-action@v2
with:
report-title: "Test report Anemoi Models (python ${{ matrix.python-version }} on ${{ matrix.platform }}, ${{ matrix.install-mode }} mode)"
custom-pytest: uv run --frozen pytest ./models
- name: Run integration tests
if: success() && (steps.changed-packages.outputs.integration_changed == 'true' || steps.changed-packages.outputs.training_changed == 'true' || steps.changed-packages.outputs.graphs_changed == 'true' || steps.changed-packages.outputs.models_changed == 'true')
uses: pavelzw/pytest-action@v2
timeout-minutes: 30
with:
report-title: "Test report Anemoi Core Integration (python ${{ matrix.python-version }} on ${{ matrix.platform }}, ${{ matrix.install-mode }} mode)"
custom-pytest: uv run --frozen pytest tests/