Skip to content

Commit

Permalink
Continuous integration (#98)
Browse files Browse the repository at this point in the history
* exclude bots from the release page

* configure CI

* don't pin `python`

* add `pytest-cov` to the environment

* configure `coverage`
  • Loading branch information
keewis authored Nov 7, 2024
1 parent 464fc90 commit f32f151
Show file tree
Hide file tree
Showing 5 changed files with 198 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .github/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
changelog:
exclude:
authors:
- dependabot
- pre-commit-ci
84 changes: 84 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
name: CI

on:
push:
branches: [main]
pull_request:
branches: [main]
workflow_dispatch:

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
detect-skip-ci-trigger:
name: "Detect CI Trigger: [skip-ci]"
if: |
github.repository == 'umr-lops/xarray-safe-rcm'
&& github.event_name == 'push'
|| github.event_name == 'pull_request'
runs-on: ubuntu-latest
outputs:
triggered: ${{ steps.detect-trigger.outputs.trigger-found }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 2
- uses: xarray-contrib/ci-trigger@v1
id: detect-trigger
with:
keyword: "[skip-ci]"

ci:
name: ${{ matrix.os }} py${{ matrix.python-version }}
runs-on: ${{ matrix.os }}
needs: detect-skip-ci-trigger

if: needs.detect-skip-ci-trigger.outputs.triggered == 'false'

defaults:
run:
shell: bash -l {0}

strategy:
fail-fast: false
matrix:
python-version: ["3.10", "3.11", "3.12"]
os: ["ubuntu-latest", "macos-latest", "windows-latest"]

steps:
- name: Checkout the repository
uses: actions/checkout@v4
with:
# need to fetch all tags to get a correct version
fetch-depth: 0 # fetch all branches and tags

- name: Setup environment variables
run: |
echo "TODAY=$(date +'%Y-%m-%d')" >> $GITHUB_ENV
echo "CONDA_ENV_FILE=ci/requirements/environment.yaml" >> $GITHUB_ENV
- name: Setup micromamba
uses: mamba-org/setup-micromamba@v2
with:
environment-file: ${{ env.CONDA_ENV_FILE }}
environment-name: xarray-safe-rcm-tests
cache-environment: true
cache-environment-key: "${{runner.os}}-${{runner.arch}}-py${{matrix.python-version}}-${{env.TODAY}}-${{hashFiles(env.CONDA_ENV_FILE)}}"
create-args: >-
python=${{matrix.python-version}}
conda
- name: Install xarray-safe-rcm
run: |
python -m pip install --no-deps -e .
- name: Import xarray-safe-rcm
run: |
python -c "import safe_rcm"
- name: Run tests
run: |
python -m pytest --cov=safe_rcm
99 changes: 99 additions & 0 deletions .github/workflows/upstream-dev.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
name: upstream-dev CI

on:
push:
branches: [main]
pull_request:
branches: [main]
schedule:
- cron: "0 18 * * 0" # Weekly "On Sundays at 18:00" UTC
workflow_dispatch:

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
detect-test-upstream-trigger:
name: "Detect CI Trigger: [test-upstream]"
if: github.event_name == 'push' || github.event_name == 'pull_request'
runs-on: ubuntu-latest
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-test-upstream-trigger

if: |
always()
&& github.repository == 'umr-lops/xarray-safe-rcm'
&& (
github.event_name == 'schedule'
|| github.event_name == 'workflow_dispatch'
|| needs.detect-test-upstream-trigger.outputs.triggered == 'true'
|| contains(github.event.pull_request.labels.*.name, 'run-upstream')
)
defaults:
run:
shell: bash -l {0}

strategy:
fail-fast: false
matrix:
python-version: ["3.12"]

steps:
- name: checkout the repository
uses: actions/checkout@v4
with:
# need to fetch all tags to get a correct version
fetch-depth: 0 # fetch all branches and tags

- name: set up conda environment
uses: mamba-org/setup-micromamba@v2
with:
environment-file: ci/requirements/environment.yaml
environment-name: tests
create-args: >-
python=${{ matrix.python-version }}
pytest-reportlog
conda
- name: install upstream-dev dependencies
run: bash ci/install-upstream-dev.sh

- name: install the package
run: python -m pip install --no-deps -e .

- name: show versions
run: python -m pip list

- name: import
run: |
python -c 'import safe_rcm'
- name: run tests
if: success()
id: status
run: |
python -m pytest -rf --report-log=pytest-log.jsonl
- name: report failures
if: |
failure()
&& steps.tests.outcome == 'failure'
&& github.event_name == 'schedule'
uses: xarray-contrib/issue-from-pytest-log@v1
with:
log-path: pytest-log.jsonl
3 changes: 2 additions & 1 deletion ci/requirements/environment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: xarray-safe-rcm-tests
channels:
- conda-forge
dependencies:
- python=3.10
- python
# development
- ipython
- pre-commit
Expand All @@ -14,6 +14,7 @@ dependencies:
# testing
- pytest
- pytest-reportlog
- pytest-cov
- hypothesis
- coverage
# I/O
Expand Down
8 changes: 8 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,11 @@ known-third-party = ["xarray", "tlz"]
[tool.ruff.lint.flake8-tidy-imports]
# Disallow all relative imports.
ban-relative-imports = "all"

[tool.coverage.run]
source = ["safe_rcm"]
branch = true

[tool.coverage.report]
show_missing = true
exclude_lines = ["pragma: no cover", "if TYPE_CHECKING"]

0 comments on commit f32f151

Please sign in to comment.