Skip to content

Commit e192f60

Browse files
authored
Merge pull request #136 from bopen/use-cruft
Move to use cruft / conda cookiecutter template
2 parents 29adc2c + 00f133c commit e192f60

21 files changed

+849
-176
lines changed

.cruft.json

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"template": "https://github.com/ecmwf-projects/cookiecutter-conda-package",
3+
"commit": "d379e35af1aa17d816367bcb0942fcf3e238be9d",
4+
"checkout": null,
5+
"context": {
6+
"cookiecutter": {
7+
"project_name": "xarray-sentinel",
8+
"project_slug": "xarray_sentinel",
9+
"project_short_description": "Easily access and explore the SAR data products of the Copernicus Sentinel-1 satellite mission",
10+
"copyright_holder": "B-Open Solutions srl and the xarray-sentinel authors",
11+
"copyright_year": "2021",
12+
"mypy_strict": true,
13+
"integration_tests": true,
14+
"_template": "https://github.com/ecmwf-projects/cookiecutter-conda-package"
15+
}
16+
},
17+
"directory": null
18+
}

.github/workflows/on-push.yml

+161-61
Original file line numberDiff line numberDiff line change
@@ -14,65 +14,95 @@ concurrency:
1414
group: ${{ github.workflow }}-${{ github.ref }}
1515
cancel-in-progress: true
1616

17+
defaults:
18+
run:
19+
shell: bash -l {0}
20+
1721
jobs:
1822
pre-commit:
1923
runs-on: ubuntu-latest
2024
steps:
21-
- uses: actions/checkout@v3
22-
- uses: actions/setup-python@v4
25+
- uses: actions/checkout@v4
26+
- uses: actions/setup-python@v5
2327
with:
2428
python-version: 3.x
2529
- uses: pre-commit/[email protected]
2630

31+
combine-environments:
32+
runs-on: ubuntu-latest
33+
34+
steps:
35+
- uses: actions/checkout@v4
36+
- uses: actions/setup-python@v5
37+
with:
38+
python-version: 3.x
39+
- name: Install conda-merge
40+
run: |
41+
python -m pip install conda-merge
42+
- name: Combine environments
43+
run: |
44+
for SUFFIX in ci integration; do
45+
conda-merge ci/environment-$SUFFIX.yml environment.yml > ci/combined-environment-$SUFFIX.yml || exit
46+
done
47+
- uses: actions/upload-artifact@v4
48+
with:
49+
name: combined-environments
50+
path: ci/combined-environment-*.yml
51+
2752
unit-tests:
28-
name: unit-tests (3.11)
53+
name: unit-tests
54+
needs: combine-environments
2955
runs-on: ubuntu-latest
30-
defaults:
31-
run:
32-
shell: bash -l {0}
56+
strategy:
57+
matrix:
58+
python-version: ['3.11']
3359

3460
steps:
35-
- uses: actions/checkout@v3
36-
- name: Install Conda environment with Micromamba
37-
uses: mamba-org/provision-with-micromamba@v15
61+
- uses: actions/checkout@v4
62+
- uses: actions/download-artifact@v4
63+
with:
64+
name: combined-environments
65+
path: ci
66+
- name: Get current date
67+
id: date
68+
run: echo "date=$(date +%Y-%m-%d)" >> "${GITHUB_OUTPUT}"
69+
- uses: mamba-org/setup-micromamba@v1
3870
with:
39-
environment-file: environment.yml
71+
environment-file: ci/combined-environment-ci.yml
4072
environment-name: DEVELOP
41-
channels: conda-forge
42-
cache-env: true
43-
cache-env-key: ubuntu-latest-3.11
44-
extra-specs: |
45-
python=3.11
73+
cache-environment: true
74+
cache-environment-key: environment-${{ steps.date.outputs.date }}
75+
cache-downloads-key: downloads-${{ steps.date.outputs.date }}
76+
create-args: >-
77+
python=${{ matrix.python-version }}
4678
- name: Install package
4779
run: |
4880
python -m pip install --no-deps -e .
4981
- name: Run tests
5082
run: |
51-
make test COV_REPORT=xml
52-
- name: Run doc tests
53-
run: |
54-
make doc-test COV_REPORT=xml
55-
- name: Upload code coverage to Codecov
56-
uses: codecov/[email protected]
83+
make unit-tests COV_REPORT=xml
5784
5885
type-check:
59-
needs: [unit-tests]
86+
needs: [combine-environments, unit-tests]
6087
runs-on: ubuntu-latest
61-
defaults:
62-
run:
63-
shell: bash -l {0}
6488

6589
steps:
66-
- uses: actions/checkout@v3
67-
- name: Install Conda environment with Micromamba
68-
uses: mamba-org/provision-with-micromamba@v15
90+
- uses: actions/checkout@v4
91+
- uses: actions/download-artifact@v4
92+
with:
93+
name: combined-environments
94+
path: ci
95+
- name: Get current date
96+
id: date
97+
run: echo "date=$(date +%Y-%m-%d)" >> "${GITHUB_OUTPUT}"
98+
- uses: mamba-org/setup-micromamba@v1
6999
with:
70-
environment-file: environment.yml
100+
environment-file: ci/combined-environment-ci.yml
71101
environment-name: DEVELOP
72-
channels: conda-forge
73-
cache-env: true
74-
cache-env-key: ubuntu-latest-3.11
75-
extra-specs: |
102+
cache-environment: true
103+
cache-environment-key: environment-${{ steps.date.outputs.date }}
104+
cache-downloads-key: downloads-${{ steps.date.outputs.date }}
105+
create-args: >-
76106
python=3.11
77107
- name: Install package
78108
run: |
@@ -81,55 +111,125 @@ jobs:
81111
run: |
82112
make type-check
83113
114+
docs-build:
115+
needs: [combine-environments, unit-tests]
116+
runs-on: ubuntu-latest
117+
118+
steps:
119+
- uses: actions/checkout@v4
120+
- uses: actions/download-artifact@v4
121+
with:
122+
name: combined-environments
123+
path: ci
124+
- name: Get current date
125+
id: date
126+
run: echo "date=$(date +%Y-%m-%d)" >> "${GITHUB_OUTPUT}"
127+
- uses: mamba-org/setup-micromamba@v1
128+
with:
129+
environment-file: ci/combined-environment-ci.yml
130+
environment-name: DEVELOP
131+
cache-environment: true
132+
cache-environment-key: environment-${{ steps.date.outputs.date }}
133+
cache-downloads-key: downloads-${{ steps.date.outputs.date }}
134+
create-args: >-
135+
python=3.11
136+
- name: Install package
137+
run: |
138+
python -m pip install --no-deps -e .
139+
- name: Build documentation
140+
run: |
141+
make docs-build
142+
84143
integration-tests:
85-
needs: [unit-tests]
144+
needs: [combine-environments, unit-tests]
145+
if: |
146+
success() && true
86147
runs-on: ubuntu-latest
87-
defaults:
88-
run:
89-
shell: bash -l {0}
90148

91149
strategy:
92150
matrix:
93-
python-version: ['3.10', '3.9']
94-
extra: ['']
95151
include:
96152
- python-version: '3.9'
97-
extra: -minver
153+
extra: -integration
98154

99155
steps:
100-
- uses: actions/checkout@v3
101-
- name: Install Conda environment with Micromamba
102-
uses: mamba-org/provision-with-micromamba@v15
156+
- uses: actions/checkout@v4
157+
- uses: actions/download-artifact@v4
158+
with:
159+
name: combined-environments
160+
path: ci
161+
- name: Get current date
162+
id: date
163+
run: echo "date=$(date +%Y-%m-%d)" >> "${GITHUB_OUTPUT}"
164+
- uses: mamba-org/setup-micromamba@v1
103165
with:
104-
environment-file: environment${{ matrix.extra }}.yml
166+
environment-file: ci/combined-environment${{ matrix.extra }}.yml
105167
environment-name: DEVELOP${{ matrix.extra }}
106-
channels: conda-forge
107-
cache-env: true
108-
cache-env-key: ubuntu-latest-${{ matrix.python-version }}${{ matrix.extra }}.
109-
extra-specs: |
168+
cache-environment: true
169+
cache-environment-key: environment-${{ steps.date.outputs.date }}
170+
cache-downloads-key: downloads-${{ steps.date.outputs.date }}
171+
create-args: >-
110172
python=${{ matrix.python-version }}
111173
- name: Install package
112174
run: |
113175
python -m pip install --no-deps -e .
114176
- name: Run tests
115177
run: |
116-
make test COV_REPORT=xml
117-
- name: Upload code coverage to Codecov
118-
uses: codecov/[email protected]
178+
make unit-tests COV_REPORT=xml
119179
120180
distribution:
121181
runs-on: ubuntu-latest
122-
needs: [integration-tests, type-check]
182+
needs: [unit-tests, type-check, docs-build, integration-tests]
183+
if: |
184+
always() &&
185+
needs.unit-tests.result == 'success' &&
186+
needs.type-check.result == 'success' &&
187+
needs.docs-build.result == 'success' &&
188+
(needs.integration-tests.result == 'success' || needs.integration-tests.result == 'skipped')
123189
124190
steps:
125-
- uses: actions/checkout@v3
126-
- name: Build distributions
191+
- uses: actions/checkout@v4
192+
- uses: actions/setup-python@v5
193+
with:
194+
python-version: '3.11'
195+
- name: Install package
196+
run: |
197+
python -m pip install --upgrade pip
198+
python -m pip install build twine
199+
- name: Build distribution
127200
run: |
128-
$CONDA/bin/python -m pip install build
129-
$CONDA/bin/python -m build
130-
- name: Publish a Python distribution to PyPI
131-
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
132-
uses: pypa/gh-action-pypi-publish@release/v1
201+
python -m build
202+
- name: Check wheels
203+
run: |
204+
cd dist || exit
205+
python -m pip install xarray_sentinel*.whl || exit
206+
python -m twine check --strict * || exit
207+
python -c "import xarray_sentinel" || exit
208+
cd ..
209+
- uses: actions/upload-artifact@v4
210+
with:
211+
name: distribution
212+
path: dist
213+
214+
upload-to-pypi:
215+
runs-on: ubuntu-latest
216+
needs: distribution
217+
if: |
218+
always() &&
219+
needs.distribution.result == 'success' &&
220+
github.event_name == 'push' &&
221+
startsWith(github.ref, 'refs/tags')
222+
environment:
223+
name: pypi
224+
url: https://pypi.org/p/xarray-sentinel
225+
permissions:
226+
id-token: write # IMPORTANT: this permission is mandatory for trusted publish
227+
228+
steps:
229+
- uses: actions/download-artifact@v4
230+
with:
231+
name: distribution
232+
path: dist
233+
- uses: pypa/[email protected]
133234
with:
134-
user: __token__
135-
password: ${{ secrets.PYPI_API_TOKEN }}
235+
verbose: true

0 commit comments

Comments
 (0)