Skip to content

Commit 725ab24

Browse files
authored
Merge pull request #68 from csiro-coasts/split-ci-workflows
Split CI workflows
2 parents c2fe28e + eb79f4e commit 725ab24

File tree

5 files changed

+175
-69
lines changed

5 files changed

+175
-69
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: Build emsarray Python package
2+
description: Build the emsarray Python package in both tarball and wheel formats.
3+
inputs:
4+
python-version:
5+
description: Python version to use.
6+
required: true
7+
artifact-name:
8+
description: Name of the uploaded artifact
9+
required: false
10+
default: "Python package"
11+
12+
outputs:
13+
artifact-name:
14+
description: Name of the uploaded artifact
15+
value: ${{ inputs.artifact-name }}
16+
17+
runs:
18+
using: composite
19+
20+
steps:
21+
- uses: actions/checkout@v3
22+
- uses: actions/setup-python@v4
23+
with:
24+
python-version: ${{ inputs.python-version }}
25+
cache: 'pip'
26+
27+
- name: Build python package
28+
shell: bash -l {0}
29+
run: |
30+
pip install build
31+
python3 -m build
32+
33+
- uses: actions/upload-artifact@v3
34+
with:
35+
name: ${{ inputs.artifact-name }}
36+
path: "dist/"

.github/actions/environment/action.yaml

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ inputs:
44
python-version:
55
description: Python version to install. Used as a Conda version constraint.
66
required: true
7+
package-artifact-name:
8+
description: Name of the emsarray Python package artifact
9+
required: false
10+
default: "Python package"
711

812
runs:
913
using: composite
@@ -13,26 +17,36 @@ runs:
1317
- uses: actions/setup-python@v4
1418
with:
1519
cache: 'pip'
20+
cache-dependency-path: |
21+
continuous-integration/requirements.txt
22+
continuous-integration/environment.yaml
23+
setup.cfg
1624
python-version: ${{ inputs.python-version }}
1725

18-
- name: Fetch Python package
26+
- name: Fetch built emsarray package
1927
uses: actions/download-artifact@v3
2028
with:
21-
name: "Python package"
29+
name: ${{ inputs.package-artifact-name }}
2230
path: "dist/"
2331

32+
- name: Cache conda packages
33+
uses: actions/cache@v2
34+
with:
35+
path: ~/conda_pkgs_dir
36+
key:
37+
${{ runner.os }}-conda-${{
38+
hashFiles('continuous-integration/environment.yaml') }}
39+
2440
- name: Install base Conda environment
25-
uses: mamba-org/provision-with-micromamba@main
41+
uses: conda-incubator/setup-miniconda@v2
2642
with:
27-
cache-downloads: true
28-
cache-env: false
29-
channels: conda-forge
3043
environment-file: continuous-integration/environment.yaml
31-
environment-name: continuous-integration
32-
extra-specs: |
33-
python=${{ inputs.python-version }}
34-
wheel
35-
pip
44+
python-version: ${{ inputs.python-version }}
45+
channels: conda-forge
46+
- shell: bash -l {0}
47+
run: |
48+
conda install -c conda-forge wheel
49+
3650
3751
- name: Install Python packages
3852
shell: bash -l {0}

.github/workflows/ci.yaml

Lines changed: 14 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -11,29 +11,20 @@ on:
1111

1212
workflow_dispatch:
1313

14+
env:
15+
python-version: "3.11"
16+
1417
jobs:
1518
build:
1619
runs-on: ubuntu-latest
17-
env:
18-
python_version: "3.11"
20+
outputs:
21+
artifact-name: ${{ steps.build.outputs.artifact-name }}
1922
steps:
2023
- uses: actions/checkout@v3
21-
22-
- uses: actions/setup-python@v4
24+
- uses: ./.github/actions/build-python-package
25+
id: build
2326
with:
24-
python-version: ${{ env.python_version }}
25-
cache: 'pip'
26-
27-
- name: Build python package
28-
shell: bash -l {0}
29-
run: |
30-
pip install build
31-
python3 -m build
32-
33-
- uses: actions/upload-artifact@v3
34-
with:
35-
name: "Python package"
36-
path: dist
27+
python-version: ${{ env.python-version }}
3728

3829
test:
3930
runs-on: ubuntu-latest
@@ -50,6 +41,7 @@ jobs:
5041
- uses: ./.github/actions/environment
5142
with:
5243
python-version: ${{ matrix.python-version }}
44+
package-artifact-name: ${{ needs.build.outputs.artifact-name }}
5345

5446
- name: Run tests
5547
shell: bash -l {0}
@@ -80,20 +72,18 @@ jobs:
8072
run:
8173
shell: bash -l {0}
8274

83-
env:
84-
python_version: "3.11"
85-
8675
steps:
8776
- uses: actions/checkout@v3
8877
- uses: ./.github/actions/environment
8978
with:
90-
python-version: ${{ env.python_version }}
79+
python-version: ${{ env.python-version }}
80+
package-artifact-name: ${{ needs.build.outputs.artifact-name }}
9181

9282
- name: 'mypy cache'
9383
uses: actions/cache@v3
9484
with:
9585
path: '.mypy_cache'
96-
key: mypy-${{ runner.os }}-py${{ env.python_version }}-${{ hashFiles('requirements.txt') }}
86+
key: mypy-${{ runner.os }}-py${{ env.python-version }}-${{ hashFiles('requirements.txt') }}
9787

9888
- run: flake8 src/ tests/
9989
- run: isort --diff --check-only src/ tests/
@@ -112,7 +102,8 @@ jobs:
112102
- uses: actions/checkout@v3
113103
- uses: ./.github/actions/environment
114104
with:
115-
python-version: "3.11"
105+
python-version: ${{ env.python-version }}
106+
package-artifact-name: ${{ needs.build.outputs.artifact-name }}
116107

117108
- run: |
118109
cd docs/
@@ -122,38 +113,3 @@ jobs:
122113
with:
123114
name: Docs
124115
path: docs/_build/dirhtml
125-
126-
publish:
127-
runs-on: ubuntu-latest
128-
timeout-minutes: 5
129-
needs: ['test', 'lint', 'docs']
130-
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
131-
132-
steps:
133-
- name: Fetch Python package
134-
uses: actions/download-artifact@v3
135-
with:
136-
name: "Python package"
137-
path: "dist"
138-
139-
- name: "Check tag matches version"
140-
shell: bash -l {0}
141-
run: |
142-
VERSION="$( echo "${{ github.ref }}" | sed 's!refs/tags/v!!' )"
143-
echo "Looking for packages with version $VERSION"
144-
ls -l dist/*
145-
packages=(
146-
"dist/emsarray-$VERSION.tar.gz"
147-
"dist/emsarray-$VERSION-*.whl"
148-
)
149-
for package in "${packages[@]}" ; do
150-
if ! test -e $package ; then
151-
echo "Could not find $package"
152-
exit 1
153-
fi
154-
done
155-
156-
- name: "Publish Python package"
157-
uses: pypa/gh-action-pypi-publish@release/v1
158-
with:
159-
password: ${{ secrets.PYPI_API_TOKEN }}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
name: Prerelease checks
2+
on:
3+
pull_request:
4+
branches:
5+
- "release-*"
6+
7+
workflow_dispatch:
8+
9+
env:
10+
python-version: "3.11"
11+
12+
jobs:
13+
build:
14+
runs-on: ubuntu-latest
15+
outputs:
16+
artifact-name: ${{ steps.build.outputs.artifact-name }}
17+
steps:
18+
- uses: actions/checkout@v3
19+
- uses: ./.github/actions/build-python-package
20+
id: build
21+
with:
22+
python-version: ${{ env.python-version }}
23+
24+
build_conda:
25+
runs-on: ubuntu-latest
26+
timeout-minutes: 15
27+
needs: ['build']
28+
continue-on-error: true
29+
30+
steps:
31+
- uses: actions/checkout@v3
32+
- uses: actions/checkout@v3
33+
with:
34+
repository: conda-forge/emsarray-feedstock
35+
path: emsarray-feedstock
36+
37+
- uses: ./.github/actions/environment
38+
with:
39+
python-version: ${{ env.python-version }}
40+
package-artifact-name: ${{ needs.build.outputs.artifact-name }}
41+
42+
- run: |
43+
conda install conda-build
44+
./scripts/build-local-conda-package.sh
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
name: Publish a new version to PyPI
2+
on:
3+
push:
4+
tags:
5+
- "v[0-9]+.*"
6+
7+
workflow_dispatch:
8+
9+
env:
10+
python-version: "3.11"
11+
12+
jobs:
13+
build:
14+
runs-on: ubuntu-latest
15+
outputs:
16+
artifact-name: ${{ steps.build.outputs.artifact-name }}
17+
steps:
18+
- uses: actions/checkout@v3
19+
- uses: ./.github/actions/build-python-package
20+
id: build
21+
with:
22+
python-version: ${{ env.python-version }}
23+
24+
publish:
25+
runs-on: ubuntu-latest
26+
timeout-minutes: 5
27+
needs: ['build']
28+
29+
steps:
30+
- name: Fetch Python package
31+
uses: actions/download-artifact@v3
32+
with:
33+
name: ${{ needs.build.outputs.artifact-name }}
34+
path: "dist"
35+
36+
- name: "Check tag matches version"
37+
shell: bash -l {0}
38+
run: |
39+
VERSION="$( echo "${{ github.ref }}" | sed 's!refs/tags/v!!' )"
40+
echo "Looking for packages with version $VERSION"
41+
ls -l dist/*
42+
packages=(
43+
"dist/emsarray-$VERSION.tar.gz"
44+
"dist/emsarray-$VERSION-*.whl"
45+
)
46+
for package in "${packages[@]}" ; do
47+
if ! test -e $package ; then
48+
echo "Could not find $package"
49+
exit 1
50+
fi
51+
done
52+
53+
- name: "Publish Python package"
54+
uses: pypa/gh-action-pypi-publish@release/v1
55+
with:
56+
password: ${{ secrets.PYPI_API_TOKEN }}

0 commit comments

Comments
 (0)