Skip to content

Commit 03f436f

Browse files
Add conda build. Add CI tests and a CD workflow to build and deploy Conda and PyPI packages.
1 parent d178fb9 commit 03f436f

File tree

5 files changed

+170
-1
lines changed

5 files changed

+170
-1
lines changed

.github/workflows/cd.yml

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
name: CD
2+
on:
3+
push:
4+
tags:
5+
- 'v*'
6+
7+
env:
8+
PY_VERSION: 3.12
9+
10+
jobs:
11+
pypi-build:
12+
name: Build package for PyPI
13+
if: github.repository == 'ACCESS-NRI/access-parsers' # exclude forks
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: actions/checkout@v4
17+
18+
- uses: actions/setup-python@v5
19+
with:
20+
python-version: ${{ env.PY_VERSION }}
21+
22+
- run: |
23+
python3 -m pip install --upgrade build && python3 -m build
24+
25+
- uses: actions/upload-artifact@v4
26+
with:
27+
name: release
28+
path: dist
29+
30+
pypi-publish:
31+
# Split build and publish to restrict trusted publishing to just this workflow
32+
needs: ['pypi-build']
33+
name: Publish to PyPI.org
34+
runs-on: ubuntu-latest
35+
permissions:
36+
# IMPORTANT: this permission is mandatory for trusted publishing
37+
id-token: write
38+
steps:
39+
- uses: actions/download-artifact@v4
40+
with:
41+
name: release
42+
path: dist
43+
44+
- name: Publish package distributions to PyPI
45+
uses: pypa/gh-action-pypi-publish@76f52bc884231f62b9a034ebfe128415bbaabdfc # v1.12.4
46+
47+
conda:
48+
name: Build with conda and upload
49+
if: github.repository == 'ACCESS-NRI/access-parsers' # exclude forks
50+
runs-on: ubuntu-latest
51+
steps:
52+
- name: Checkout source
53+
uses: actions/checkout@v4
54+
55+
- name: Setup conda environment
56+
uses: conda-incubator/setup-miniconda@835234971496cad1653abb28a638a281cf32541f # v3.2.0
57+
with:
58+
miniconda-version: "latest"
59+
python-version: ${{ env.PY_VERSION }}
60+
environment-file: conda/environment.yml
61+
auto-update-conda: false
62+
auto-activate-base: false
63+
show-channel-urls: true
64+
65+
- name: Build and upload conda package
66+
uses: ACCESS-NRI/[email protected]
67+
with:
68+
meta_yaml_dir: conda
69+
user: ${{ vars.ANACONDA_USER }}
70+
label: main
71+
token: ${{ secrets.ANACONDA_TOKEN }}
72+

.github/workflows/ci.yml

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# This workflow will install Python dependencies, run tests and lint with a single version of Python
22
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python
33

4-
name: access-parsers
4+
name: CI
55

66
on:
77
push:
@@ -12,6 +12,9 @@ on:
1212
permissions:
1313
contents: read
1414

15+
env:
16+
PY_VERSION_BUILD: 3.12
17+
1518
jobs:
1619
formatting:
1720
runs-on: ubuntu-latest
@@ -23,6 +26,43 @@ jobs:
2326
options: "--check --verbose --diff"
2427
src: "./src ./tests"
2528

29+
pypa-build:
30+
name: PyPA build
31+
runs-on: ubuntu-latest
32+
steps:
33+
- uses: actions/checkout@v4
34+
35+
- uses: actions/setup-python@v5
36+
with:
37+
python-version: ${{ env.PY_VERSION_BUILD }}
38+
cache: 'pip' # caching pip dependencies
39+
40+
- run: |
41+
python3 -m pip install --upgrade build && python3 -m build
42+
43+
conda-build:
44+
name: Conda Build
45+
runs-on: ubuntu-latest
46+
steps:
47+
- uses: actions/checkout@v4
48+
49+
- name: Setup conda environment
50+
uses: conda-incubator/setup-miniconda@835234971496cad1653abb28a638a281cf32541f # v3.2.0
51+
with:
52+
miniconda-version: "latest"
53+
python-version: ${{ env.PY_VERSION_BUILD }}
54+
environment-file: conda/environment.yml
55+
auto-update-conda: false
56+
auto-activate-base: false
57+
show-channel-urls: true
58+
59+
- name: Build conda package
60+
uses: ACCESS-NRI/[email protected]
61+
with:
62+
meta_yaml_dir: conda
63+
label: main
64+
upload: false
65+
2666
build:
2767
needs: formatting
2868
runs-on: ubuntu-latest

conda/environment.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
channels:
2+
- conda-forge
3+
- accessnri
4+
- default
5+
6+
dependencies:
7+
- anaconda-client
8+
- conda-build
9+
- conda-verify
10+
- setuptools_scm

conda/meta.yaml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
{% set data = load_setup_py_data(setup_file='../setup.py', from_recipe_dir=True) %}
2+
{% set version = data.get('version') %}
3+
{% set pyproj = load_file_data('../pyproject.toml', from_recipe_dir=True) %}
4+
{% set project = pyproj.get('project') %}
5+
6+
package:
7+
name: access-parsers
8+
version: "{{ version }}"
9+
10+
build:
11+
noarch: python
12+
number: 0
13+
script: "{{ PYTHON }} -m pip install . -vv"
14+
entry_points:
15+
{% for name, script in project.get('scripts', {}).items() %}
16+
- {{ name }} = {{ script }}
17+
{% endfor %}
18+
19+
source:
20+
path: ../
21+
22+
requirements:
23+
host:
24+
- python
25+
- pip
26+
- setuptools >=61.0.0
27+
- setuptools_scm
28+
run:
29+
- python >=3.10
30+
{% for dep in project.get('dependencies', []) %}
31+
- {{ dep }}
32+
{% endfor %}
33+
34+
test:
35+
imports:
36+
- access.parsers
37+
38+
about:
39+
home: https://github.com/ACCESS-NRI/access-parsers/
40+
license: Apache Software
41+
license_family: APACHE
42+
summary: "Various functions to read and write configuration files for the models developed at ACCESS-NRI."

setup.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# This file is only needed for the automatic versioning in the conda recipe
2+
from setuptools import setup
3+
import setuptools_scm
4+
5+
setup(version=setuptools_scm.get_version())

0 commit comments

Comments
 (0)