Skip to content

Commit

Permalink
Merge pull request #18 from mcvine/ci-conda-upload
Browse files Browse the repository at this point in the history
github action: add a step to build and upload conda pkg
  • Loading branch information
yxqd authored Feb 14, 2021
2 parents 72fc083 + 0fd63ab commit 191d692
Show file tree
Hide file tree
Showing 6 changed files with 111 additions and 0 deletions.
8 changes: 8 additions & 0 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,11 @@ jobs:
./builders/github-actions/build_and_test.sh
env:
PYTHON_VERSION: ${{ matrix.python-version }}

- name: conda build and upload
shell: pwsh
run: |
./builders/github-actions/conda_build_and_upload.sh
env:
PYTHON_VERSION: ${{ matrix.python-version }}
CONDA_UPLOAD_TOKEN: ${{ secrets.ANACONDA_TOKEN }}
1 change: 1 addition & 0 deletions builders/conda-recipe/bld.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
echo Windows build is not supported
28 changes: 28 additions & 0 deletions builders/conda-recipe/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/usr/bin/env bash

let CORES=`grep -c ^processor /proc/cpuinfo`
let CORES-=1
if ((CORES < 1)); then
CORES = 1;
fi

PYVER_MAJOR=`python -c "from __future__ import print_function; import sys; print(sys.version_info[0])"`
PYVER_MINOR=`python -c "from __future__ import print_function; import sys; print(sys.version_info[1])"`
PYVER=${PYVER_MAJOR}.${PYVER_MINOR}
echo $PYVER
echo $PREFIX
PY_INCLUDE_DIR=${PREFIX}/include/`ls ${PREFIX}/include/|grep python${PYVER}`
PY_SHAREDLIB=${PREFIX}/lib/`ls ${PREFIX}/lib/|grep libpython${PYVER}[a-z]*.so$`
echo $PY_INCLUDE_DIR
echo $PY_SHAREDLIB

mkdir build
cd build
cmake \
-DCONDA_BUILD=TRUE \
-DPYTHON_INCLUDE_DIR=${PY_INCLUDE_DIR} \
-DPYTHON_LIBRARY=${PY_SHAREDLIB} \
-DCMAKE_INSTALL_PREFIX=$PREFIX -DDEPLOYMENT_PREFIX=$PREFIX \
-DCMAKE_SYSTEM_LIBRARY_PATH=$PREFIX/lib \
.. \
&& make install
32 changes: 32 additions & 0 deletions builders/conda-recipe/create_conda_pkg.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/bin/bash

# prerequisites
# 1. in test conda environment
# 2. in conda-recipe directory with meta.yaml.template
# 3. defined env vars:
# - PYTHON_VERSION
# - _CONDA_PKG_NAME_
# - _CONDA_PKG_ARCH_
# - _CONDA_PKG_VER_
# - _GIT_REV_
# - CONDA_UPLOAD_TOKEN

set -e
set -x

conda install -n root conda-build
conda install anaconda-client
which anaconda
conda config --set anaconda_upload no

# build
cd $(realpath $(dirname $0))
pwd
sed -e "s|XXXVERSIONXXX|$_CONDA_PKG_VER_|g" meta.yaml.template | sed -e "s|XXXGIT_REVXXX|$_GIT_REV_|g" > meta.yaml
cat meta.yaml
conda build --python=$PYTHON_VERSION .

# upload
CONDA_ROOT_PREFIX=$(realpath $(dirname `which conda`)/..)
anaconda -t $CONDA_UPLOAD_TOKEN upload --force --label unstable \
$CONDA_ROOT_PREFIX/conda-bld/$_CONDA_PKG_ARCH_/$_CONDA_PKG_NAME_-$_CONDA_PKG_VER_-*.tar.bz2
31 changes: 31 additions & 0 deletions builders/conda-recipe/meta.yaml.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package:
name: mcvine.phonon
version: XXXVERSIONXXX

source:
git_rev: XXXGIT_REVXXX
git_url: https://github.com/mcvine/phonon.git

requirements:
build:
- {{ compiler('cxx') }} 7 # [linux]
- cmake

host:
- python

run:
- python
- mcvine-core >=1.4

build:
noarch: python

test:
imports:
- mcvine.phonon

about:
home:
license:
license_file:
11 changes: 11 additions & 0 deletions builders/github-actions/conda_build_and_upload.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash

export _GIT_REV_=`git describe --tags`
VERSION=`git describe --tags | cut -d '-' -f1 | cut -c2-`
VERSION_NEXT=`echo ${VERSION}| awk -F. -v OFS=. 'NF==1{print ++$NF}; NF>1{if(length($NF+1)>length($NF))$(NF-1)++; $NF=sprintf("%0*d", length($NF), ($NF+1)%(10^length($NF))); print}'`
echo ${VERSION} ${VERSION_NEXT}
export _CONDA_PKG_VER_=${VERSION_NEXT}.dev
export _CONDA_PKG_ARCH_=noarch
export _CONDA_PKG_NAME_=mcvine.phonon
echo building ${_CONDA_PKG_ARCH_} conda pkg ${_CONDA_PKG_NAME_} version:${_CONDA_PKG_VER_} git version:${_GIT_REV_}
./builders/conda-recipe/create_conda_pkg.sh

0 comments on commit 191d692

Please sign in to comment.