Skip to content

Commit

Permalink
better conda workflow
Browse files Browse the repository at this point in the history
Checkout needed to get github.sha

ci : use-mamba

ci : use-mamba

wip: try to understand why cache key changes

use only github.sha

enableCrossOsArchive

remove ${{ hashFiles('.conda/recipe.yaml')

Add mamba to publish

Fix conda publish
  • Loading branch information
benoit-cty authored and benoit-cty committed Oct 31, 2024
1 parent 95e6133 commit fec7979
Showing 1 changed file with 43 additions and 63 deletions.
106 changes: 43 additions & 63 deletions .github/workflows/workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,7 @@ jobs:
uses: actions/cache@v4
with:
path: /tmp/conda-bld
key: build-conda-${{ hashFiles('.conda/recipe.yaml') }}-${{ github.sha }}
restore-keys: |
build-conda-${{ hashFiles('.conda/recipe.yaml') }}
build-conda-
key: build-conda-${{ github.sha }}
- name: set version
run: |
python3 .github/pyproject_version.py --replace True
Expand All @@ -65,37 +62,29 @@ jobs:
build-args: --channel openfisca --channel conda-forge --output-dir /tmp/conda-bld
recipe-path: .conda/recipe.yaml
upload-artifact: false
- name: Upload Conda build
uses: actions/upload-artifact@v4
with:
name: conda-build-${{ env.PACKAGE_VERSION }}-${{ github.sha }}
path: /tmp/conda-bld
retention-days: 30

test-conda:
runs-on: ubuntu-22.04
needs: [ build-conda ]
steps:
# Checkout needed to get github.sha
- uses: actions/checkout@v4

- name: Setup conda
uses: conda-incubator/setup-miniconda@v3
with:
activate-environment: openfisca
miniforge-version: latest
python-version: 3.9.12
use-mamba: true

- name: Restore build
uses: actions/cache@v4
with:
path: /tmp/conda-bld
key: build-conda-${{ hashFiles('.conda/recipe.yaml') }}-${{ github.sha }}

key: build-conda-${{ github.sha }}
fail-on-cache-miss: true
- name: Install package
shell: bash -l {0}
run: mamba install --channel file:///tmp/conda-bld --channel openfisca openfisca-france

- name: Test conda package
shell: bash -l {0}
run: openfisca test tests/formulas/irpp.yaml
Expand Down Expand Up @@ -224,34 +213,32 @@ jobs:

test-on-windows:
runs-on: "windows-latest"
# if: github.ref == 'refs/heads/master' # Only triggered for the `master` branch
needs: [ build-conda ]
if: github.ref == 'refs/heads/master' # Only triggered for the `master` branch
needs: [ test-conda ]
steps:
# Checkout needed to get github.sha
- uses: actions/checkout@v4
- uses: conda-incubator/setup-miniconda@v3
with:
auto-update-conda: true
python-version: "3.9.9"
# Add conda-forge for OpenFisca-Core
channels: openfisca,conda-forge
activate-environment: true
- uses: actions/checkout@v4
activate-environment: openfisca
miniforge-version: latest
python-version: 3.9.12
use-mamba: true
- name: Restore build
uses: actions/cache@v4
with:
path: /tmp/conda-bld
key: build-conda-${{ github.sha }}
fail-on-cache-miss: true
enableCrossOsArchive: true # To allow restore on windows
- name: Test max path length
run: "python3 openfisca_france/scripts/check_path_length.py"
- name: Get version
run: |
# chcp 65001 #set code page to utf-8
echo ("PACKAGE_VERSION=" + (python3 .github/pyproject_version.py --only_package_version True) ) >> $env:GITHUB_ENV
echo "Version setup.py: ${{ env.PACKAGE_VERSION }}"
- name: Download conda build
uses: actions/download-artifact@v3
with:
name: conda-build-${{ env.PACKAGE_VERSION }}-${{ github.sha }}
path: conda-build-tmp
- name: Install with conda
run: |
conda install -c ./conda-build-tmp/noarch/openfisca-france-${{ env.PACKAGE_VERSION }}-py_0.tar.bz2 openfisca-france
- name: openfisca test
run: openfisca test --country-package openfisca_france tests
- name: Install package
shell: bash -l {0}
run: mamba install --channel file:///tmp/conda-bld --channel openfisca openfisca-france
- name: Test conda package
shell: bash -l {0}
run: openfisca test tests/formulas/irpp.yaml

check-version-and-changelog:
runs-on: ubuntu-20.04
Expand Down Expand Up @@ -326,35 +313,28 @@ jobs:
runs-on: "ubuntu-20.04"
needs: [ deploy, test-on-windows ]
steps:
- uses: conda-incubator/setup-miniconda@v3
with:
auto-update-conda: true
python-version: "3.9.9"
# Add conda-forge for OpenFisca-Core
channels: conda-forge
activate-environment: true
- uses: actions/checkout@v4
- name: Get version
run: |
# chcp 65001 #set code page to utf-8
echo ("PACKAGE_VERSION=" + (python3 .github/pyproject_version.py --only_package_version True) ) >> $env:GITHUB_ENV
echo "Version setup.py: ${{ env.PACKAGE_VERSION }}"
- name: Download conda build
uses: actions/download-artifact@v3
- name: Restore build
uses: actions/cache@v4
with:
name: conda-build-${{ env.PACKAGE_VERSION }}-${{ github.sha }}
path: conda-build-tmp
- name: Install with conda
- uses: actions/github-script@v6
id: last_pr_commit
path: /tmp/conda-bld
key: build-conda-${{ github.sha }}
fail-on-cache-miss: true
- uses: conda-incubator/setup-miniconda@v3
with:
script: |
const commits = ${{ toJSON(github.event.commits) }}
return commits.at(-2).id;
result-encoding: string
- name: Conda build and upload
activate-environment: openfisca
miniforge-version: latest
python-version: 3.9.12
use-mamba: true
- name: Install package
shell: bash -l {0}
run: mamba install --channel file:///tmp/conda-bld --channel openfisca openfisca-france
- name: Test conda package
shell: bash -l {0}
run: openfisca test tests/formulas/irpp.yaml
- name: Conda upload already build package
# This shell is made necessary by https://github.com/conda-incubator/setup-miniconda/issues/128
shell: bash -l {0}
run: |
conda install --yes anaconda-client
anaconda -t ${{ secrets.ANACONDA_TOKEN }} upload --user openfisca ./conda-build-tmp/noarch/openfisca-france-${{ env.PACKAGE_VERSION }}-py_0.tar.bz2
anaconda -t ${{ secrets.ANACONDA_TOKEN }} upload --user openfisca /tmp/conda-bld/noarch/openfisca-france-*

0 comments on commit fec7979

Please sign in to comment.