Skip to content

Commit

Permalink
Migrate france action to tunisia
Browse files Browse the repository at this point in the history
  • Loading branch information
benjello committed Sep 27, 2024
1 parent 0940979 commit 069855c
Show file tree
Hide file tree
Showing 15 changed files with 572 additions and 12 deletions.
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)
12 changes: 12 additions & 0 deletions .github/has-functional-changes.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#! /usr/bin/env bash

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

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
echo "No functional changes detected."
exit 1
else echo "The functional files above were changed."
fi
33 changes: 33 additions & 0 deletions .github/is-version-number-acceptable.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#! /usr/bin/env bash

if [[ ${GITHUB_REF#refs/heads/} == master ]]
then
echo "No need for a version check on master."
exit 0
fi

if ! $(dirname "$BASH_SOURCE")/has-functional-changes.sh
then
echo "No need for a version update."
exit 0
fi

current_version=`python setup.py --version`

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 master."
echo "Look at the CONTRIBUTING.md file to learn how the version number should be updated."
exit 1
fi

if ! $(dirname "$BASH_SOURCE")/has-functional-changes.sh | grep --quiet CHANGELOG.md
then
echo "CHANGELOG.md has not been modified, while functional changes were made."
echo "Explain what you changed before merging this branch into master."
echo "Look at the CONTRIBUTING.md file to learn how to write the changelog."
exit 2
fi
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
4 changes: 4 additions & 0 deletions .github/publish-git-tag.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#! /usr/bin/env bash

git tag `python setup.py --version`
git push --tags # update the repository version
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 069855c

Please sign in to comment.