From c059c3d009eb33846ca588ba20e1d4a0d0191917 Mon Sep 17 00:00:00 2001 From: Mauko Quiroga Date: Tue, 15 Oct 2024 14:18:25 +0200 Subject: [PATCH 1/3] ci: build conda pkg --- .conda/recipe.yaml | 41 +++++++++++++++++++++++++ .conda/variants.yaml | 9 ++++++ .github/is-version-number-acceptable.sh | 21 ++++++++++--- .github/workflows/build.yml | 33 +++++++++++++++++--- pyproject.toml | 2 +- 5 files changed, 95 insertions(+), 11 deletions(-) create mode 100644 .conda/recipe.yaml create mode 100644 .conda/variants.yaml diff --git a/.conda/recipe.yaml b/.conda/recipe.yaml new file mode 100644 index 00000000..126c8220 --- /dev/null +++ b/.conda/recipe.yaml @@ -0,0 +1,41 @@ +schema_version: 1 + +context: + name: openfisca-country-template + version: 8.0.0 + +package: + name: ${{ name|lower }} + version: ${{ version }} + +source: + path: .. + +build: + noarch: python + script: pip install . -v + +requirements: + host: + - numpy + - pip + - python + - setuptools >=61.0 + run: + - numpy + - python + - openfisca-core-api >=43 + +tests: +- python: + imports: + - openfisca_country_template + +about: + summary: OpenFisca Rules as Code model for Country-Template. + license: AGPL-3.0 + license_file: LICENSE + +extra: + recipe-maintainers: + - bonjourmauko diff --git a/.conda/variants.yaml b/.conda/variants.yaml new file mode 100644 index 00000000..29677202 --- /dev/null +++ b/.conda/variants.yaml @@ -0,0 +1,9 @@ +numpy: +- "1.24" +- "1.25" +- "1.26" + +python: +- "3.9" +- "3.10" +- "3.11" diff --git a/.github/is-version-number-acceptable.sh b/.github/is-version-number-acceptable.sh index 0c86be5b..bacbd7df 100755 --- a/.github/is-version-number-acceptable.sh +++ b/.github/is-version-number-acceptable.sh @@ -12,18 +12,29 @@ then exit 0 fi -current_version=$(grep '^version =' pyproject.toml | cut -d '"' -f 2) # parsing with tomllib is complicated, see https://github.com/python-poetry/poetry/issues/273 +# parsing with tomllib is complicated, see +# https://github.com/python-poetry/poetry/issues/273 +python_version=$(grep '^version =' pyproject.toml | cut -d '"' -f 2) -if [[ ! $current_version ]] +# we do the same for conda +conda_version=$(grep '^ version: \d' .conda/recipe.yaml | cut -d ' ' -f 4) + +if [[ ! $python_version || ! $conda_version ]] then echo "Error getting current version" exit 1 fi -if git rev-parse --verify --quiet $current_version +if [[ "$python_version" != "$conda_version" ]] +then + echo "Python ($python_version) and Conda ($conda_version) versions do not match" + exit 1 +fi + +if git rev-parse --verify --quiet "$python_version" then - echo "Version $current_version already exists in commit:" - git --no-pager log -1 $current_version + echo "Version $python_version already exists in commit:" + git --no-pager log -1 "$python_version" echo echo "Update the version number in pyproject.toml before merging this branch into main." echo "Look at the CONTRIBUTING.md file to learn how the version number should be updated." diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index b38ed1a1..e012fae2 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -4,17 +4,17 @@ on: workflow_call: jobs: - build-and-cache: + python-build-and-cache: runs-on: ubuntu-22.04 steps: - name: Checkout uses: actions/checkout@v4 - + - name: Set up Python uses: actions/setup-python@v5 with: python-version: 3.9.12 # Patch version must be specified to avoid any cache confusion, since the cache key depends on the full Python version. Any difference in patches between jobs will lead to a cache not found error. - + - name: Cache build uses: actions/cache@v4 with: @@ -23,12 +23,35 @@ jobs: restore-keys: | build-${{ env.pythonLocation }}-${{ hashFiles('pyproject.toml') }} build-${{ env.pythonLocation }}- - + - name: Build package run: make build - + - name: Cache release uses: actions/cache@v4 with: path: dist key: release-${{ env.pythonLocation }}-${{ hashFiles('pyproject.toml') }}-${{ github.sha }} + + conda-build-and-cache: + runs-on: ubuntu-22.04 + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Cache build + 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- + + + - name: Build conda package + uses: prefix-dev/rattler-build-action@v0.2.16 + with: + build-args: --channel openfisca --channel conda-forge --output-dir /tmp/conda-bld + recipe-path: .conda/recipe.yaml + upload-artifact: true diff --git a/pyproject.toml b/pyproject.toml index 7aade143..6c7d90b4 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "openfisca-country_template" -version = "7.1.6" +version = "8.0.0" dependencies = [ "openfisca-core[web-api] >= 43", ] From 51f22e7476942f5e421b1b0f76f677048b0196ec Mon Sep 17 00:00:00 2001 From: Mauko Quiroga Date: Tue, 15 Oct 2024 14:35:09 +0200 Subject: [PATCH 2/3] ci: upload artifact --- .github/workflows/build.yml | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index e012fae2..a0fa00ce 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -39,19 +39,15 @@ jobs: - name: Checkout uses: actions/checkout@v4 - - name: Cache build - 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- - - - name: Build conda package uses: prefix-dev/rattler-build-action@v0.2.16 with: build-args: --channel openfisca --channel conda-forge --output-dir /tmp/conda-bld recipe-path: .conda/recipe.yaml - upload-artifact: true + upload-artifact: false + + - name: Upload artifact + uses: actions/upload-artifact@v4 + with: + name: openfisca_country_template + path: /tmp/conda-bld/**/*.conda From caba0500aa19835b0c5e517ed1908bad309b9477 Mon Sep 17 00:00:00 2001 From: Mauko Quiroga Date: Tue, 15 Oct 2024 14:49:26 +0200 Subject: [PATCH 3/3] ci: add test conda --- .conda/recipe.yaml | 5 +++++ .github/workflows/build.yml | 15 +++++++++------ .github/workflows/validate.yml | 28 ++++++++++++++++++++++++++++ 3 files changed, 42 insertions(+), 6 deletions(-) diff --git a/.conda/recipe.yaml b/.conda/recipe.yaml index 126c8220..83f8df66 100644 --- a/.conda/recipe.yaml +++ b/.conda/recipe.yaml @@ -14,6 +14,11 @@ source: build: noarch: python script: pip install . -v + files: + include: + - "**/*.py" + - "**/*.json" + - "**/*.yaml" requirements: host: diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index a0fa00ce..7542a928 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -39,15 +39,18 @@ jobs: - name: Checkout uses: actions/checkout@v4 + - name: Cache build + 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- + - name: Build conda package uses: prefix-dev/rattler-build-action@v0.2.16 with: build-args: --channel openfisca --channel conda-forge --output-dir /tmp/conda-bld recipe-path: .conda/recipe.yaml upload-artifact: false - - - name: Upload artifact - uses: actions/upload-artifact@v4 - with: - name: openfisca_country_template - path: /tmp/conda-bld/**/*.conda diff --git a/.github/workflows/validate.yml b/.github/workflows/validate.yml index 56087b87..9c4f189b 100644 --- a/.github/workflows/validate.yml +++ b/.github/workflows/validate.yml @@ -55,6 +55,34 @@ jobs: - run: make test + test-conda: + runs-on: ubuntu-22.04 + needs: [ build ] + steps: + - 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 }} + + - name: Install package + shell: bash -l {0} + run: mamba install --channel file:///tmp/conda-bld --channel openfisca openfisca-country-template + + - name: Test conda package + shell: bash -l {0} + run: openfisca test openfisca-country-template/tests + test-api: runs-on: ubuntu-22.04 needs: [ build ]