A Github Action to build your software package and publish to an Anaconda repository.
This action has been developed for the needs of OpenAlea
project. It is mostly inspired by existing projects such as build-and-upload-conda-packages or Publish Conda package to Anaconda.org and uses Setup Miniconda.
In details, this action:
- Check if
meta.yml
exists in a directory provided in input - Sets-up a basic conda environment with a python version specified in input (python 3 only). You can also specify a list of conda channels you migh need during the building process
- Installs necessary packages for building and publishing (namely
conda-build
andanaconda-client
) - Compiles the package with
conda build
using themeta.yml
file rules. If your package uses thenumpy
library as a dependency, please be aware that library versions are tied to python version at build time if expressed explicitely in themeta.yml
file (so far, existing options arepython3.7
:numpy1.11
,python3.8
:numpy1.16
,python3.9
:numpy1.19
). Otherwise,numpy
minor version used at build time can be expressed explicitely in input (cf. bellow). - Uploads the package on anaconda.org with
anaconda upload
using a token to access your repository or the one of your organization (cf. procedure here)
The only mandatory input is the anaconda token to access your anaconda repository.
This action is designed to be very generic and the workflow will work even for non pure-python packages.
This example builds your application on multiple plateforms, with multiple python versions. This is a template for your .github/workflow/build_publish_anaconda.yml
in the example project structure.
name: build_publish_anaconda
on:
push:
tags:
- 'v*'
branches:
- '**'
pull_request:
branches:
- '**'
workflow_dispatch: # allows you to trigger manually
jobs:
build-and-publish:
name: ${{ matrix.os }}, Python 3.${{ matrix.python-minor-version }} for conda deployment
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
max-parallel: 6
matrix:
os: [ ubuntu-latest , macos-latest , windows-latest]
python-minor-version: [8, 9, 10, 11, 12]
isMaster:
- ${{ github.ref == 'refs/heads/master' || github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v') }}
exclude:
- isMaster: false
python-minor-version: 7
- isMaster: false
python-minor-version: 8
- isMaster: false
python-minor-version: 9
- isMaster: false
python-minor-version: 11
- isMaster: false
python-minor-version: 12
- isMaster: false
os: macos-latest
python-minor-version: 10
- isMaster: false
os: windows-latest
python-minor-version: 10
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Determine publish
uses: haya14busa/action-cond@v1
id: publish
with:
cond: ${{ startsWith(github.ref, 'refs/tags/v') }}
if_true: 'true'
if_false: 'false'
- name: Build and Publish
uses: openalea/[email protected]
with:
conda: conda
mamba: true
python: ${{ matrix.python-minor-version }}
numpy: '22'
channels: openalea3, conda-forge
token: ${{ secrets.ANACONDA_TOKEN }}
publish: ${{ steps.publish.outputs.value }}
label: main
.
├── LICENSE
├── README.md
├── myproject
│ ├── __init__.py
│ └── myproject.py
├── conda
| ├── bld.bat
│ ├── build.sh
│ └── meta.yaml
├── .github
│ └── workflows
│ └── build_publish_anaconda.yml
├── .gitignore
This token's purpose is to let your github project access your anaconda repository to publish your package on your channel once it has been successfully built.
- Get an Anaconda token (don't forget to specify the read and write API access) at
anaconda.org/USERNAME/settings/access
and copy it. - Let the github repository of your project access to this token: Add it to the Secrets (
Settings
->Secrets
->Actions
->New repository secret
) of the Github repository asANACONDA_TOKEN
The following inputs are available for this action:
Name | Description | Required | Default value |
---|---|---|---|
conda |
Directory with conda recipe (i.e. meta.yml file) |
No | . |
python |
Python3 minor version used for building | No | 9 |
numpy |
Numpy minor version used for building | No | '' (fixed by python version) |
mamba |
Use mamba to setup miniconda and install in a faster way or not. Uses the latest available version. | No | false |
token |
Anaconda access Token (cf. use process described above) | Yes | |
channels |
Optional Extra anaconda channels to use. Coma-separated syntax | No | conda-forge |
publish |
Wether we publish the package build on anaconda cloud or not | No | true |
labels |
Label of conda package published | No | main |