Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Publish to conda #124

Open
wants to merge 102 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
102 commits
Select commit Hold shift + click to select a range
9325949
Update references to setup.py in CI workflow
MattiSG Apr 24, 2024
fd46d00
Make errors in finding current version visible
MattiSG Apr 24, 2024
b4f3f5e
Support detecting changes without git tag
MattiSG Apr 24, 2024
30b6985
Check changes compared to last tagged version
MattiSG Apr 24, 2024
2c70fce
Update version number on initial setup
MattiSG Apr 24, 2024
664ac0d
Update references to `setup.py` (#142)
MattiSG Apr 26, 2024
25f6f85
Allow to bypass steps on CI with `CI` env variable
Ndpnt Apr 24, 2024
c29c903
Avoid modifying main workflow in bootstrap script
Ndpnt Apr 24, 2024
5f54fae
Perform bootstrapping when used as GitHub template
Ndpnt Apr 24, 2024
176574b
Use a less technical naming for better accessibility
Ndpnt Apr 24, 2024
668beab
Update documentation
Ndpnt Apr 24, 2024
00260ce
Unify commit message with first-time-setup script
Ndpnt Apr 26, 2024
4361f2a
Decompose monolithic workflow into specialized workflows
Ndpnt Apr 26, 2024
a6d1175
Remove obsolete dependency
Ndpnt Apr 26, 2024
24d6c03
Update job condition
Ndpnt Apr 26, 2024
721d53f
Add changelog entry
Ndpnt Apr 26, 2024
ee2baed
Update version
Ndpnt Apr 26, 2024
90a7d70
Improve documentation
Ndpnt Apr 26, 2024
6397718
Title case the jurisdiction name
Ndpnt Apr 26, 2024
7b3e90f
Allow to manually trigger first time setup workflow
Ndpnt Apr 26, 2024
de9206f
Improve documentation
Ndpnt Apr 26, 2024
e1924a8
Remove spaces
Ndpnt Apr 26, 2024
fd141ad
Fix typos and improve some phrasings
MattiSG Apr 29, 2024
2b23d6b
Use PyPi token for deployment
sandcha Apr 29, 2024
dadc4b0
Fix changelog hierarchy
MattiSG May 2, 2024
c906b86
Improve wording
Ndpnt May 3, 2024
5c65f27
Fix condition
Ndpnt May 3, 2024
dcec073
Unify syntax
Ndpnt May 3, 2024
fdeb428
Add comment
Ndpnt May 3, 2024
6b5f74d
Delete file via Git to ensure the removal will be committed
Ndpnt May 3, 2024
718255e
Merge remote-tracking branch 'openfisca/main'
Ndpnt May 3, 2024
93bb53e
Update stefanzweifel/git-auto-commit-action to v5
Ndpnt May 3, 2024
1238ffb
Remove obsolete IDs
Ndpnt May 3, 2024
faea0bc
Improve naming
Ndpnt May 3, 2024
01be175
Remove obsolete checkout option
Ndpnt May 3, 2024
0dcdbcf
Remove manual trigger on `build` and `validate` workflows
Ndpnt May 3, 2024
4130dfe
Update Ubuntu to `v22.04` on CI
Ndpnt May 3, 2024
7d13315
Update CI dependency `actions/setup-python` to `v5`
Ndpnt May 3, 2024
b3e4ebb
Update Python to `v3.9.12` on CI
Ndpnt May 3, 2024
71b05d3
Update CI dependency `actions/checkout` to `v4`
Ndpnt May 3, 2024
830be46
Update CI dependency `actions/cache` to `v4`
Ndpnt May 3, 2024
ce8f18d
Merge pull request #11 from Ndpnt/update-actions-dependencies
Ndpnt May 3, 2024
6df2cb8
Update changelog
Ndpnt May 3, 2024
3e01209
Improve copywriting
MattiSG May 3, 2024
5b43f1a
Fix step name
Ndpnt May 3, 2024
50b8408
Trigger deployment on any push to `main`
Ndpnt May 3, 2024
dd4f13b
Simplify code
Ndpnt May 3, 2024
3f35133
Use consistent line breaks across workflows
Ndpnt May 3, 2024
73ba03b
Reduce logs
Ndpnt May 3, 2024
e70eaf8
Improve job name
Ndpnt May 3, 2024
717800a
Automate template setup process via CI for GitHub users (#143)
Ndpnt May 3, 2024
fe5126e
Use version specifiers compatible with Conda
MattiSG May 7, 2024
1574614
Update Core dependency
MattiSG May 7, 2024
823869c
Bump version number and changelog
MattiSG May 7, 2024
f3204f4
Update minimal Core version
MattiSG May 7, 2024
2782d3a
Ensure scripts fail if finding the latest tagged commit fails
Ndpnt May 9, 2024
667a70f
Always return a result even with no reachable tags
Ndpnt May 9, 2024
7afe300
Skip deploy job if Pypi token is not defined
Ndpnt May 9, 2024
661329a
Update deprecated syntax
Ndpnt May 9, 2024
695050a
Rename PyPI token GitHub secret
Ndpnt May 9, 2024
9eb3c68
Update packaging section in README
Ndpnt May 9, 2024
2bf4777
Add changelog entry
Ndpnt May 9, 2024
42d4e9d
Update version
Ndpnt May 9, 2024
e751b8b
Improve wording
Ndpnt May 10, 2024
ff314a5
Remove redundant instructions
Ndpnt May 10, 2024
69286d8
Unify bash multiline
Ndpnt May 10, 2024
f90bf28
Add comment
Ndpnt May 10, 2024
cb310dc
Fallback to lint all files if there are no tags
Ndpnt May 10, 2024
269240f
Refactor duplication by creating a generic linting script
Ndpnt May 10, 2024
0af37a7
Remove whitespaces
Ndpnt May 10, 2024
496123a
Skip `deploy` workflow when PyPI token is not defined in GitHub secre…
Ndpnt May 10, 2024
e61a6d1
Update classifiers for supported versions of python in pyproject.toml
verbman May 19, 2024
26fc0c9
Update supported Python versions in pyproject.toml
MattiSG May 21, 2024
a4f6003
Update README.md python references, Reorder pyproject.toml
verbman May 24, 2024
beb3ba1
Update README.md python references, Reorder pyproject.toml (#153)
bonjourmauko Sep 26, 2024
93b17e9
chore(deps): bump core
bonjourmauko Sep 26, 2024
6fba5ee
chore: version bump
bonjourmauko Sep 26, 2024
db249b7
chore: update to core 42.0.0 (#154)
bonjourmauko Sep 30, 2024
b8131ff
build: normalize pyproject
bonjourmauko Oct 14, 2024
ea59d9c
chore: version bump
bonjourmauko Oct 14, 2024
69d065e
ci: remove duplicate lint check
bonjourmauko Oct 15, 2024
17f94ad
ci: fix yamllint
bonjourmauko Oct 15, 2024
3b3a980
build: normalize pyproject (#156)
bonjourmauko Oct 16, 2024
5fd4756
WIP Publish to conda
benoit-cty Feb 4, 2022
4a488b9
Fix style
benoit-cty Feb 4, 2022
adcb972
Update emeta.yaml
benoit-cty Feb 4, 2022
2722609
Fix style
benoit-cty Feb 4, 2022
2fe2905
Fix Style
benoit-cty Feb 4, 2022
389ff6a
Fix style
benoit-cty Feb 4, 2022
8e398b2
Fix LICENSE
benoit-cty Feb 7, 2022
3e5d3f4
Change package import
benoit-cty Feb 7, 2022
c31cb8c
bump
benoit-cty Feb 7, 2022
8a3f642
Update .conda/README.md
benoit-cty May 16, 2022
5c06516
Update .github/get_pypi_info.py
benoit-cty May 30, 2022
accd5b6
Update .conda/README.md
benoit-cty May 30, 2022
6ff0b1f
Conda use pyproject.toml
benoit-cty May 17, 2024
baa549f
Conda doc
benoit-cty May 17, 2024
4e5e3f5
Remove get_pypi_info.py not needed anymore.
benoit-cty May 17, 2024
15154a9
Exclude lint for .conda/meta.yaml
benoit-cty May 17, 2024
cfda102
Conda deploy and test in CI
Oct 18, 2024
f6219d0
[conda] Replace space in deps
Oct 18, 2024
5dc697d
doc
Oct 18, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions .conda/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# Publish to conda

benoit-cty marked this conversation as resolved.
Show resolved Hide resolved
There are two ways to publish to conda:

- A fully automatic in CI that publish to an "openfisca" channel. See below for more information.
- A more complex for Conda-Forge.

We use both for openfisca-core but only _openfisca channel_ for _country-template_.
benoit-cty marked this conversation as resolved.
Show resolved Hide resolved

benoit-cty marked this conversation as resolved.
Show resolved Hide resolved
## Automatic upload

The CI automaticaly upload the PyPi package, see the `.github/workflow.yml`, step `publish-to-conda`.
benoit-cty marked this conversation as resolved.
Show resolved Hide resolved

## Test with Docker

Docker could be used to test the build and the installation of the package.

To test the build:

```sh
docker run --volume $PWD:/openfisca -i -t continuumio/anaconda3 /bin/bash
cd /openfisca
# Check meta.yaml
conda-build --check .conda
# Build
conda install conda-verify
conda config --add channels defaults
conda build -c openfisca -c conda-forge .conda
```

benoit-cty marked this conversation as resolved.
Show resolved Hide resolved
To test the installation of the published package:

```sh
docker run --volume $PWD:/openfisca -i -t continuumio/anaconda3 /bin/bash
cd /openfisca
conda install -c openfisca -c conda-forge openfisca-country-template
openfisca test --country-package openfisca-country-template tests
```

To do the publication of the package, normaly not needed as it is done by the CI! :

```sh
docker run --volume $PWD:/openfisca -i -t continuumio/anaconda3 /bin/bash
cd /openfisca
# Build
conda build -c openfisca -c conda-forge .conda
anaconda login
anaconda upload openfisca-country-template-<VERSION>-py_0.tar.bz2
```

## Manual actions made to make it works the first time
benoit-cty marked this conversation as resolved.
Show resolved Hide resolved

- Create an account on https://anaconda.org.
- Create a token on https://anaconda.org/openfisca/settings/access with _Allow write access to the API site_. Warning, it expire on 2023/01/13.
- Put the token in a CI env variable ANACONDA_TOKEN.
benoit-cty marked this conversation as resolved.
Show resolved Hide resolved
53 changes: 53 additions & 0 deletions .conda/meta.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
###############################################################################
## Package description for Anaconda.org
## Warning : string PYPI_VERSION, PYPI_URL and PYPI_SHA256 are replaced by CI
## Keep them as is.
###############################################################################

{% set name = "OpenFisca-Country-Template" %}
{% set pyproject = load_file_data('pyproject.toml') %}
{% set version = pyproject.get('project').get('version') %}

package:
name: {{ name|lower }}
version: {{ version }}

source:
path: ..

build:
noarch: python
number: 0
script: "{{ PYTHON }} -m pip install . -vv"

requirements:
host:
- python
- pip
run:
{% for req in pyproject.get('project').get('dependencies') %}
- {{ req | replace(" ", "") }}
{% endfor %}

test:
imports:
- openfisca_country_template
requires:
- pip
commands:
- pip check

outputs:
- name: openfisca-country-template

about:
home: https://fr.openfisca.org/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As the country template is an international package, reference the international website?

Suggested change
home: https://fr.openfisca.org/
home: https://openfisca.org

license_family: AGPL
license: AGPL-3.0-only
license_file: LICENSE
summary: "OpenFisca tax and benefit system for Country-Template."
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use full package name? And, as the country template isn't a real country, change the usual description as follows?:

Suggested change
summary: "OpenFisca tax and benefit system for Country-Template."
summary: "OpenFisca-Country-Template tax and benefit system."

description: |
OpenFisca is a versatile microsimulation free software.
This repository contains the Country-Template module, to work with OpenFisca.
doc_url: https://fr.openfisca.org/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Likewise, use the package documentation or an international website? ^^ :

Suggested change
doc_url: https://fr.openfisca.org/
doc_url: https://github.com/openfisca/country-template#openfisca-country-template

Or, as the official documentation now uses the openfisca-country-template in it examples, we can use it here.

dev_url: https://github.com/openfisca/country-template/
20 changes: 0 additions & 20 deletions .flake8

This file was deleted.

2 changes: 1 addition & 1 deletion .github/has-functional-changes.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

IGNORE_DIFF_ON="README.md CONTRIBUTING.md Makefile .gitignore .github/*"

last_tagged_commit=$(git describe --tags --abbrev=0 --first-parent) # --first-parent ensures we don't follow tags not published in main through an unlikely intermediary merge commit
last_tagged_commit=`git describe --tags --abbrev=0 --first-parent` # --first-parent ensures we don't follow tags not published in main through an unlikely intermediary merge commit

if git diff-index --name-only --exit-code $last_tagged_commit -- . `echo " $IGNORE_DIFF_ON" | sed 's/ / :(exclude)/g'` # Check if any file that has not be listed in IGNORE_DIFF_ON has changed since the last tag was published.
then
Expand Down
12 changes: 9 additions & 3 deletions .github/is-version-number-acceptable.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,22 @@ then
exit 0
fi

current_version=$(python setup.py --version)
current_version=$(grep '^version =' pyproject.toml | cut -d '"' -f 2) # parsing with tomllib is complicated, see https://github.com/python-poetry/poetry/issues/273

if [[ ! $current_version ]]
then
echo "Error getting current version"
exit 1
fi

if git rev-parse --verify --quiet $current_version
then
echo "Version $current_version already exists in commit:"
git --no-pager log -1 $current_version
echo
echo "Update the version number in setup.py before merging this branch into main."
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."
exit 1
exit 2
fi

if ! $(dirname "$BASH_SOURCE")/has-functional-changes.sh | grep --quiet CHANGELOG.md
Expand Down
11 changes: 0 additions & 11 deletions .github/lint-changed-python-files.sh

This file was deleted.

11 changes: 0 additions & 11 deletions .github/lint-changed-yaml-tests.sh

This file was deleted.

3 changes: 2 additions & 1 deletion .github/publish-git-tag.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#! /usr/bin/env bash

git tag $(python setup.py --version)
current_version=$(grep '^version =' pyproject.toml | cut -d '"' -f 2) # parsing with tomllib is complicated, see https://github.com/python-poetry/poetry/issues/273
git tag $current_version
git push --tags # update the repository version
34 changes: 34 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Build

on:
workflow_call:

jobs:
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:
path: ${{ env.pythonLocation }}
key: build-${{ env.pythonLocation }}-${{ hashFiles('pyproject.toml') }}-${{ github.sha }} # Cache the entire build Python environment
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 }}
113 changes: 113 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
name: Deploy

on:
push:
branches: [ main ]

jobs:
validate:
uses: "./.github/workflows/validate.yml"

# GitHub Actions does not have a halt job option to stop from deploying if no functional changes were found.
# We thus execute a separate deployment job depending on the output of this job.
check-for-functional-changes:
runs-on: ubuntu-22.04
outputs:
status: ${{ steps.stop-early.outputs.status }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # Fetch all the tags
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: 3.9.12
- id: stop-early
run: |
if "${GITHUB_WORKSPACE}/.github/has-functional-changes.sh"
then
echo "status=success" >> $GITHUB_OUTPUT
fi

check-pypi-token: # Use intermediary job as secrets cannot be directly referenced in `if:` conditionals; see https://docs.github.com/en/actions/security-guides/using-secrets-in-github-actions#using-secrets-in-a-workflow
runs-on: ubuntu-22.04
outputs:
pypi_token_present: ${{ steps.check_token.outputs.pypi_token_present }}
steps:
- name: Check PyPI token is defined
id: check_token
run: |
if [[ -n "${{ secrets.PYPI_TOKEN }}" ]]
then
echo "pypi_token_present=true" >> $GITHUB_OUTPUT
else
echo "pypi_token_present=false" >> $GITHUB_OUTPUT
fi

deploy:
runs-on: ubuntu-22.04
needs: [ validate, check-for-functional-changes, check-pypi-token ]
if: needs.check-for-functional-changes.outputs.status == 'success' && needs.check-pypi-token.outputs.pypi_token_present == 'true'
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: 3.9.12
- name: Restore build
uses: actions/cache@v4
with:
path: ${{ env.pythonLocation }}
key: build-${{ env.pythonLocation }}-${{ hashFiles('pyproject.toml') }}-${{ github.sha }}
- name: Restore built package
uses: actions/cache@v4
with:
path: dist
key: release-${{ env.pythonLocation }}-${{ hashFiles('pyproject.toml') }}-${{ github.sha }}
- name: Upload a Python package to PyPi
run: twine upload dist/* --username __token__ --password ${{ secrets.PYPI_TOKEN }}
- name: Publish a git tag
run: "${GITHUB_WORKSPACE}/.github/publish-git-tag.sh"

publish-to-conda:
runs-on: "ubuntu-latest"
needs: [ deploy ]
strategy:
fail-fast: false
steps:
- uses: conda-incubator/setup-miniconda@v3
with:
auto-update-conda: true
python-version: "3.7.9"
# Add conda-forge for OpenFisca-Core
channels: conda-forge
activate-environment: true
- uses: actions/checkout@v4
- name: Update meta.yaml
run: |
python3 -m pip install requests argparse
python3 .github/get_pypi_info.py -p OpenFisca-Country-Template
- name: Conda Config
run: |
conda install conda-build anaconda-client
conda info
conda config --set anaconda_upload yes
- name: Conda build
run: conda build --token ${{ secrets.ANACONDA_TOKEN }} --user openfisca .conda

install-on-windows:
runs-on: "windows-latest"
needs: [ publish-to-conda ]
strategy:
fail-fast: false
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: Install with conda
run: conda install -c openfisca openfisca-country-template
36 changes: 36 additions & 0 deletions .github/workflows/first-time-setup.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: First time setup

on:
create:
workflow_dispatch:

permissions:
actions: write
checks: write
contents: write

jobs:
first-time-setup:
# Ensure this job does not run on the template repository or when the repository is forked
if: ${{ !github.event.repository.is_template && !github.event.repository.fork }}
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}

- name: Infer jurisdiction name from repository name
run: |
echo "TITLE_CASE_JURISDICTION_NAME=$(echo ${{ github.event.repository.name }} | sed 's/openfisca-//' | sed 's/[-|_]/ /g' | awk '{for (i=1; i<=NF; i++) $i=toupper(substr($i,1,1)) substr($i,2)} 1')" >> $GITHUB_ENV

- name: Execute the first-time-setup script
run: CI=true JURISDICTION_NAME="$TITLE_CASE_JURISDICTION_NAME" REPOSITORY_URL="${{ github.repositoryUrl }}" ./first-time-setup.sh

- name: Commit changes
uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: "Customise country-template through CI"
tagging_message: "0.0.1"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Loading