Skip to content

Commit

Permalink
Merge pull request #132 from openfisca/github_actions
Browse files Browse the repository at this point in the history
Migrate france action to tunisia
  • Loading branch information
benjello authored Oct 8, 2024
2 parents 0940979 + d29865a commit 2082456
Show file tree
Hide file tree
Showing 56 changed files with 1,090 additions and 568 deletions.
93 changes: 0 additions & 93 deletions .circleci/config.yml

This file was deleted.

4 changes: 0 additions & 4 deletions .circleci/publish-python-package.sh

This file was deleted.

68 changes: 68 additions & 0 deletions .conda/meta.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
###############################################################################
## File for Anaconda.org
## It use Jinja2 templating code to retreive information from setup.py
###############################################################################

{% set name = "OpenFisca-Tunisia" %}
{% set data = load_setup_py_data() %}
{% set version = data.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 data.get('install_requires', []) %}
- {{ req }}
{% endfor %}
# - python >=3.9,<4.0
# - OpenFisca-Core >=40,<41


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

outputs:
- name: openfisca-tunisia

- name: openfisca-tunisia-dev
build:
noarch: python
requirements:
host:
- python
run:
- python >=3.9,<4.0
{% for req in data.get('dev_requirements', []) %}
- {{ req }}
{% endfor %}
- {{ pin_subpackage('openfisca-tunisia', exact=True) }}

about:
home: https://fr.openfisca.org/
license_family: AGPL
license: AGPL-3.0-only
license_file: LICENSE.AGPL.txt
summary: "Tunisian tax and benefit system for OpenFisca"
description: |
OpenFisca is a versatile microsimulation free software.
This repository contains the OpenFisca model of the Tunisia tax and benefit system.
doc_url: https://fr.openfisca.org/
dev_url: https://github.com/openfisca/openfisca-tunisia/
25 changes: 25 additions & 0 deletions .github/ISSUE_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
Hello hello !

Je suis le fan numéro un d'OpenFisca, mais je viens de rencontrer un problème.

### Qu'ai-je fait ?


### À quoi m'attendais-je ?


### Que s'est-il passé en réalité ?


### Voici des informations qui peuvent aider à reproduire le problème :


### Contexte

Je m'identifie plus en tant que :

- [ ] Contributeur·e : je contribue à OpenFisca Tunisia.
- [ ] Développeur·e : je crée des outils qui utilisent OpenFisca Tunisia.
- [ ] Économiste : je réalise des simulations avec des données.
- [ ] Mainteneur·e : j'intègre les contributions à OpenFisca Tunisia.
- [ ] Autre : _(ajoutez une description du contexte dans lequel vous utilisez OpenFisca)_.
31 changes: 31 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
Merci de contribuer à OpenFisca ! Effacez cette ligne ainsi que, pour chaque ligne ci-dessous, les cas ne correspondant pas à votre contribution :)

* Évolution du système socio-fiscal. | Amélioration technique. | Correction d'un crash. | Changement mineur.
* Périodes concernées : toutes. | jusqu'au JJ/MM/AAAA. | à partir du JJ/MM/AAAA.
* Zones impactées : `chemin/vers/le/fichier/contenant/les/variables/impactées`.
* Détails :
- Description de la fonctionnalité ajoutée ou du nouveau comportement adopté.
- Cas dans lesquels une erreur était constatée.

- - - -

Ces changements (effacez les lignes ne correspondant pas à votre cas) :

- Modifient l'API publique d'OpenFisca Tunisia (par exemple renommage ou suppression de variables).
- Ajoutent une fonctionnalité (par exemple ajout d'une variable).
- Corrigent ou améliorent un calcul déjà existant.
- Modifient des éléments non fonctionnels de ce dépôt (par exemple modification du README).

- - - -

Quelques conseils à prendre en compte :

- [ ] Jetez un coup d'œil au [guide de contribution](https://github.com/openfisca/openfisca-tunisia/blob/master/CONTRIBUTING.md).
- [ ] Regardez s'il n'y a pas une [proposition introduisant ces mêmes changements](https://github.com/openfisca/openfisca-tunisia/pulls).
- [ ] Documentez votre contribution avec des références législatives.
- [ ] Mettez à jour ou ajoutez des tests correspondant à votre contribution.
- [ ] Augmentez le [numéro de version](https://speakerdeck.com/mattisg/git-session-2-strategies?slide=81) dans [`setup.py`](https://github.com/openfisca/openfisca-tunisia/blob/master/setup.py).
- [ ] Mettez à jour le [`CHANGELOG.md`](https://github.com/openfisca/openfisca-tunisia/blob/master/CHANGELOG.md).
- [ ] Assurez-vous de bien décrire votre contribution, comme indiqué ci-dessus

Et surtout, n'hésitez pas à demander de l'aide ! :)
9 changes: 3 additions & 6 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@ updates:
- package-ecosystem: pip
directory: "/"
schedule:
interval: daily
time: "00:00"
timezone: Europe/Paris
interval: weekly
labels:
- kind:dependencies
open-pull-requests-limit: 2
reviewers:
- sandcha
- benjello
9 changes: 9 additions & 0 deletions .github/get_minimal_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import re

# This script fetches and prints the minimal versions of Openfisca-Core and Openfisca-Tunisia
# dependencies in order to ensure their compatibility during CI testing
with open('./setup.py') as file:
for line in file:
version = re.search(r'(Core|Tunisia)\s*>=\s*([\d\.]*)', line)
if version:
print(f'Openfisca-{version[1]}=={version[2]}') # noqa: T201 <- This is to avoid flake8 print detection.
51 changes: 51 additions & 0 deletions .github/get_pypi_info.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import argparse
import requests
import logging


logging.basicConfig(level=logging.INFO)


def get_info(package_name: str = '') -> dict:
'''
Get minimal informations needed by .conda/meta.yaml from PyPi JSON API.
::package_name:: Name of package to get infos from.
::return:: A dict with last_version, url and sha256
'''
if package_name == '':
raise ValueError('Package name not provided.')
resp = requests.get(f'https://pypi.org/pypi/{package_name}/json').json()
version = resp['info']['version']
for v in resp['releases'][version]:
if v['packagetype'] == 'sdist': # for .tag.gz
return {
'last_version': version,
'url': v['url'],
'sha256': v['digests']['sha256']
}


def replace_in_file(filepath: str, info: dict):
'''
::filepath:: Path to meta.yaml, with filename
::info:: Dict with information to populate
'''
with open(filepath, 'rt') as fin:
meta = fin.read()
# Replace with info from PyPi
meta = meta.replace('PYPI_VERSION', info['last_version'])
meta = meta.replace('PYPI_URL', info['url'])
meta = meta.replace('PYPI_SHA256', info['sha256'])
with open(filepath, 'wt') as fout:
fout.write(meta)
logging.info(f'File {filepath} has been updated with informations from PyPi.')


if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('-p', '--package', type=str, default='', required=True, help='The name of the package')
parser.add_argument('-f', '--filename', type=str, default='.conda/meta.yaml', help='Path to meta.yaml, with filename')
args = parser.parse_args()
info = get_info(args.package)
logging.info(f'Information of the last published PyPi package : {info}')
replace_in_file(args.filename, info)
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#! /usr/bin/env bash

IGNORE_DIFF_ON="README.md CONTRIBUTING.md Makefile .gitignore .circleci/* .github/*"
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 master through an unlikely intermediary merge commit

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#! /usr/bin/env bash

if [[ $CIRCLE_BRANCH == master ]]
if [[ ${GITHUB_REF#refs/heads/} == master ]]
then
echo "No need for a version check on master."
exit 0
Expand Down
11 changes: 11 additions & 0 deletions .github/lint-changed-python-files.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#! /usr/bin/env bash

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

if ! changes=$(git diff-index --name-only --diff-filter=ACMR --exit-code $last_tagged_commit -- "*.py")
then
echo "Linting the following Python files:"
echo $changes
flake8 $changes
else echo "No changed Python files to lint"
fi
11 changes: 11 additions & 0 deletions .github/lint-changed-yaml-tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#! /usr/bin/env bash

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

if ! changes=$(git diff-index --name-only --diff-filter=ACMR --exit-code $last_tagged_commit -- "tests/*.yaml")
then
echo "Linting the following changed YAML tests:"
echo $changes
yamllint $changes
else echo "No changed YAML tests to lint"
fi
File renamed without changes.
22 changes: 22 additions & 0 deletions .github/split_tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import sys
from glob import glob


def split_tests(number_of_files, CI_NODE_TOTAL, CI_NODE_INDEX, test_files_list):
test_files_sublist = []

for file_index in range(number_of_files):
file_number = file_index % CI_NODE_TOTAL
if file_number == CI_NODE_INDEX:
test_files_sublist.append(test_files_list[file_index])

tests_to_run_string = ' '.join(test_files_sublist)

return tests_to_run_string


if __name__ == '__main__':
CI_NODE_TOTAL, CI_NODE_INDEX = int(sys.argv[1]), int(sys.argv[2])
test_files_list = glob('tests/**/*.yaml', recursive=True) + glob('tests/**/*.yml', recursive=True)
number_of_files = len(test_files_list)
sys.stdout.write(split_tests(number_of_files, CI_NODE_TOTAL, CI_NODE_INDEX, test_files_list))
14 changes: 14 additions & 0 deletions .github/test-api.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#! /usr/bin/env bash

PORT=5000
ENDPOINT=spec

openfisca serve --country-package openfisca_tunisia --port $PORT --workers 1 &
server_pid=$!

curl --retry-connrefused --retry 10 --retry-delay 5 --fail http://127.0.0.1:$PORT/$ENDPOINT | python -m json.tool > /dev/null
result=$?

kill $server_pid

exit $?
15 changes: 15 additions & 0 deletions .github/workflows/validate_yaml.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: Validate YAML

on:
push:
workflow_dispatch:
pull_request:
types: [opened, reopened]

jobs:
validate_yaml:
uses: tax-benefit/actions/.github/workflows/validate_yaml.yml@v1
with:
parameters_path: "openfisca_tunisia/parameters"
secrets:
token: ${{ secrets.CONTROL_CENTER_TOKEN }}
Loading

0 comments on commit 2082456

Please sign in to comment.