Skip to content

Commit

Permalink
Update conda build (#12)
Browse files Browse the repository at this point in the history
* Add multi-arch matrix strategy in conda build
* Add anaconda token as required secret in both build and upload steps
* Cache upload env
* Force the build workflow to be named
* Split out download args based on upload source
* Use different action for same-workflow download
* Add build version verifier
  • Loading branch information
brynpickering authored Sep 25, 2023
1 parent c75abb9 commit 86086c2
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 12 deletions.
55 changes: 48 additions & 7 deletions .github/workflows/conda-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,16 @@ on:
description: "Name of Python package name being built"
required: true
type: string
recipe_dir:
description: "Directory in which to find the recipe (i.e. config) for building the package"
required: false
type: string
default: "conda.recipe"
version:
description: "Version to be packaged and uploaded"
required: false
type: string
default: ${{ github.ref_name }}
secrets:
ANACONDA_TOKEN:
required: true
Expand All @@ -16,7 +26,23 @@ defaults:
shell: bash -l {0}

jobs:
conda-build:
n-builds:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.get-arch.outputs.matrix }}
steps:
- uses: actions/checkout@v3
- name: assert whether the build is noarch or not
id: get-arch
run: |
if grep -Fq "noarch:" ${{ inputs.recipe_dir }}/meta.yaml
then
echo "matrix={\"os\":[\"ubuntu-latest\"]}" >> $GITHUB_OUTPUT
else
echo "matrix={\"os\":[\"ubuntu-latest\", \"macos-latest\", \"windows-latest\"]}" >> $GITHUB_OUTPUT
fi
token-exists:
runs-on: ubuntu-latest
steps:
- name: check if ANACONDA_TOKEN exists
Expand All @@ -30,6 +56,12 @@ jobs:
echo "Please go to \"settings \> secrets \> actions\" to create it before trying to build the conda package."
exit 1
conda-build:
runs-on: ${{ matrix.os }}
needs: [n-builds, token-exists]
strategy:
matrix: ${{ fromJson(needs.n-builds.outputs.matrix) }}
steps:
- uses: actions/checkout@v3
- uses: mamba-org/setup-micromamba@v1
with:
Expand All @@ -40,21 +72,30 @@ jobs:
boa
conda-verify
post-cleanup: all
cache-environment: true

- name: Add conda channel
run: conda config --add channels city-modelling-lab

- name: Build conda package
run: conda mambabuild ${{ inputs.recipe_dir }}

- name: Get version without the v
run: |
conda mambabuild .
echo "conda_build_dir=$(conda build --output .)" >> "$GITHUB_ENV"
TAG=${{ inputs.version }}
echo "VERSION=${TAG#v}" >> $GITHUB_ENV
- name: Test installing built conda package
run: mamba install --use-local ${{ inputs.package_name }}
run: |
mamba install --use-local ${{ inputs.package_name }}
INSTALLED=$(mamba list ${{ inputs.package_name }})
echo $INSTALLED
echo "$INSTALLED" | grep "${{ env.VERSION }}" -Fq
- name: Upload built conda package ready for upload on release
uses: actions/upload-artifact@v3
with:
name: conda-build-${{ github.ref_name }}
path: "${{ env.conda_build_dir }}"
retention-days: 7
name: conda-build-${{ matrix.os }}-${{ inputs.package_name }}-${{ inputs.version }}
path: ${{ env.MAMBA_ROOT_PREFIX }}/envs/condabuild/conda-bld/
retention-days: 3
if-no-files-found: error
31 changes: 26 additions & 5 deletions .github/workflows/conda-upload.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,16 @@ on:
description: "Name of Python package name being uploaded"
required: true
type: string
version:
description: "Version to be packaged and uploaded"
required: false
type: string
default: ${{ github.ref_name }}
build_workflow:
description: "Name of workflow file used to build the package initially, if different from current workflow"
required: false
type: string
default: ""
secrets:
ANACONDA_TOKEN:
required: true
Expand All @@ -16,6 +26,8 @@ defaults:
jobs:
conda-publish:
runs-on: ubuntu-latest
env:
PACKAGENAME: "conda-build[a-zA-Z0-9-.]*-${{ inputs.package_name }}-${{ inputs.version }}"
steps:
- uses: actions/checkout@v3
- uses: mamba-org/setup-micromamba@v1
Expand All @@ -26,20 +38,29 @@ jobs:
python=3.11
anaconda-client
post-cleanup: all
cache-environment: True

- name: Download built conda package ready for upload on release
- name: Download built conda package from another workflow
if: inputs.build_workflow != ''
uses: dawidd6/action-download-artifact@v2
with:
name: conda-build-${{ github.ref_name }}
workflow: pre-release.yml
name: ${{ env.PACKAGENAME }}
name_is_regexp: true
workflow: ${{ inputs.build_workflow }}
path: ${{ runner.temp }}/conda_builds

- name: Download built conda package from same workflow
if: inputs.build_workflow == ''
uses: actions/download-artifact@v3
with:
path: ${{ runner.temp }}/conda_builds

- name: Get version without the v
run: |
TAG=${{ github.ref_name }}
TAG=${{ inputs.version }}
echo "VERSION=${TAG#v}" >> $GITHUB_ENV
- name: Upload to anaconda
env:
ANACONDA_API_TOKEN: ${{ secrets.ANACONDA_TOKEN }}
run: anaconda upload ${{ runner.temp }}/conda_builds/${{ inputs.package_name }}-${{ env.VERSION }}-*.tar.bz2
run: find ${{ runner.temp }}/conda_builds -path "**/${{ inputs.package_name }}-${{ env.VERSION }}-*.tar.bz2" -exec anaconda upload {} +

0 comments on commit 86086c2

Please sign in to comment.