ci: Reinstantiate CI files #31
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Test PR | ||
on: | ||
pull_request: | ||
types: [opened, synchronize, reopened] | ||
push: | ||
branches: | ||
- develop | ||
schedule: | ||
- cron: "9 2 * * 0" # at 9:02 on sunday | ||
jobs: | ||
quality: | ||
uses: ecmwf-actions/reusable-workflows/.github/workflows/qa-precommit-run.yml@v2 | ||
with: | ||
skip-hooks: "no-commit-to-branch" | ||
checks: | ||
runs-on: ubuntu-latest | ||
timeout-minutes: 60 | ||
defaults: | ||
run: | ||
timeout-minutes: 15 | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
platform: ["ubuntu-latest", "macos-latest"] | ||
python-version: ["3.9", "3.10", "3.11"] | ||
steps: | ||
- uses: actions/checkout@v3 | ||
with: | ||
fetch-depth: 0 | ||
- name: Set up Python ${{ matrix.python-version }} | ||
uses: actions/setup-python@v4 | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
- name: Install basic dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
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 | ||
- name: Install packages | ||
if: steps.changed-packages.outputs.training_changed == 'true' || steps.changed-packages.outputs.graphs_changed == 'true' || steps.changed-packages.outputs.models_changed == 'true' | ||
run: | | ||
PACKAGES="" | ||
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 | ||
pip install $PACKAGES | ||
- name: Run pytest for changed training package | ||
if: 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 }})" | ||
custom-pytest: pytest ./training | ||
- name: Run pytest for changed graphs package | ||
if: 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 }})" | ||
custom-pytest: pytest ./graphs | ||
- name: Run pytest for changed models package | ||
if: 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 }})" | ||
custom-pytest: pytest ./models | ||
- name: Run integration tests | ||
if: success() && (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 }})" | ||
custom-pytest: pytest tests/ |