Skip to content

Commit cb9f462

Browse files
Initial commit
0 parents  commit cb9f462

61 files changed

Lines changed: 4105 additions & 0 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/ISSUE_TEMPLATE.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
Hi there!
2+
3+
I really enjoy OpenFisca, but I recently encountered an issue.
4+
5+
### Here is what I did:
6+
7+
8+
### Here is what I expected to happen:
9+
10+
11+
### Here is what actually happened:
12+
13+
14+
### Here is data (or links to it) that can help you reproduce this issue:
15+
16+
17+
18+
## Context
19+
20+
I identify more as a:
21+
22+
- Analyst _(I make macroscopic computations on real populations)_.
23+
- Business expert _(I create tests and model legislation)_.
24+
- Commenter _(I make data visualisations)_.
25+
- Developer _(I create tools that use the existing OpenFisca code)_.
26+
- Historian _(I accumulate data based on past legislation values)_.
27+
- Lobbyist _(I model reforms to make them exist)_.
28+
- Producer _(I make computations on individual situations)_.
29+
30+
(remove this line as well as all items in the list that don't fit your situation)

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
Thanks for contributing to OpenFisca ! Please remove this line, as well as, for each line below, the cases which are not relevant to your contribution :)
2+
3+
* Tax and benefit system evolution. | Technical improvement. | Crash fix. | Minor change.
4+
* Impacted periods: all. | until DD/MM/YYYY. | from DD/MM/YYYY.
5+
* Impacted areas: `path/to/file/containing/impacted/variables`
6+
* Details:
7+
- New feature or new behaviour description
8+
- Cases for which an error was noticed
9+
10+
- - - -
11+
12+
These changes _(remove lines which are not relevant to your contribution)_:
13+
14+
- Impact the OpenFisca-Country-Template public API (for instance renaming or removing a variable)
15+
- Add a new feature (for instance adding a variable)
16+
- Fix or improve an already existing calculation.
17+
- Change non-functional parts of this repository (for instance editing the README)

.github/has-functional-changes.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#! /usr/bin/env bash
2+
3+
IGNORE_DIFF_ON="README.md CONTRIBUTING.md Makefile .gitignore .github/*"
4+
5+
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
6+
7+
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.
8+
then
9+
echo "No functional changes detected."
10+
exit 1
11+
else echo "The functional files above were changed."
12+
fi
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#! /usr/bin/env bash
2+
3+
if [[ ${GITHUB_REF#refs/heads/} == main ]]
4+
then
5+
echo "No need for a version check on main."
6+
exit 0
7+
fi
8+
9+
if ! $(dirname "$BASH_SOURCE")/has-functional-changes.sh
10+
then
11+
echo "No need for a version update."
12+
exit 0
13+
fi
14+
15+
current_version=$(grep '^version =' pyproject.toml | cut -d '"' -f 2) # parsing with tomllib is complicated, see https://github.com/python-poetry/poetry/issues/273
16+
17+
if [[ ! $current_version ]]
18+
then
19+
echo "Error getting current version"
20+
exit 1
21+
fi
22+
23+
if git rev-parse --verify --quiet $current_version
24+
then
25+
echo "Version $current_version already exists in commit:"
26+
git --no-pager log -1 $current_version
27+
echo
28+
echo "Update the version number in pyproject.toml before merging this branch into main."
29+
echo "Look at the CONTRIBUTING.md file to learn how the version number should be updated."
30+
exit 2
31+
fi
32+
33+
if ! $(dirname "$BASH_SOURCE")/has-functional-changes.sh | grep --quiet CHANGELOG.md
34+
then
35+
echo "CHANGELOG.md has not been modified, while functional changes were made."
36+
echo "Explain what you changed before merging this branch into main."
37+
echo "Look at the CONTRIBUTING.md file to learn how to write the changelog."
38+
exit 2
39+
fi

.github/publish-git-tag.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#! /usr/bin/env bash
2+
3+
current_version=$(grep '^version =' pyproject.toml | cut -d '"' -f 2) # parsing with tomllib is complicated, see https://github.com/python-poetry/poetry/issues/273
4+
git tag $current_version
5+
git push --tags # update the repository version

.github/test-api.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#! /usr/bin/env bash
2+
3+
PORT=5000
4+
ENDPOINT=spec
5+
6+
openfisca serve --country-package openfisca_country_template --port $PORT &
7+
server_pid=$!
8+
9+
curl --retry-connrefused --retry 10 --retry-delay 5 --fail http://127.0.0.1:$PORT/$ENDPOINT | python -m json.tool > /dev/null
10+
result=$?
11+
12+
kill $server_pid
13+
14+
exit $?

.github/workflows/build.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: Build
2+
3+
on:
4+
workflow_call:
5+
6+
jobs:
7+
build-and-cache:
8+
runs-on: ubuntu-22.04
9+
steps:
10+
- name: Checkout
11+
uses: actions/checkout@v4
12+
13+
- name: Set up Python
14+
uses: actions/setup-python@v5
15+
with:
16+
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.
17+
18+
- name: Cache build
19+
uses: actions/cache@v4
20+
with:
21+
path: ${{ env.pythonLocation }}
22+
key: build-${{ env.pythonLocation }}-${{ hashFiles('pyproject.toml') }}-${{ github.sha }} # Cache the entire build Python environment
23+
restore-keys: |
24+
build-${{ env.pythonLocation }}-${{ hashFiles('pyproject.toml') }}
25+
build-${{ env.pythonLocation }}-
26+
27+
- name: Build package
28+
run: make build
29+
30+
- name: Cache release
31+
uses: actions/cache@v4
32+
with:
33+
path: dist
34+
key: release-${{ env.pythonLocation }}-${{ hashFiles('pyproject.toml') }}-${{ github.sha }}

.github/workflows/deploy.yml

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
name: Deploy
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
7+
jobs:
8+
validate:
9+
uses: "./.github/workflows/validate.yml"
10+
11+
# GitHub Actions does not have a halt job option to stop from deploying if no functional changes were found.
12+
# We thus execute a separate deployment job depending on the output of this job.
13+
check-for-functional-changes:
14+
runs-on: ubuntu-22.04
15+
outputs:
16+
status: ${{ steps.stop-early.outputs.status }}
17+
steps:
18+
- uses: actions/checkout@v4
19+
with:
20+
fetch-depth: 0 # Fetch all the tags
21+
- name: Set up Python
22+
uses: actions/setup-python@v5
23+
with:
24+
python-version: 3.9.12
25+
- id: stop-early
26+
run: |
27+
if "${GITHUB_WORKSPACE}/.github/has-functional-changes.sh"
28+
then
29+
echo "status=success" >> $GITHUB_OUTPUT
30+
fi
31+
32+
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
33+
runs-on: ubuntu-22.04
34+
outputs:
35+
pypi_token_present: ${{ steps.check_token.outputs.pypi_token_present }}
36+
steps:
37+
- name: Check PyPI token is defined
38+
id: check_token
39+
run: |
40+
if [[ -n "${{ secrets.PYPI_TOKEN }}" ]]
41+
then
42+
echo "pypi_token_present=true" >> $GITHUB_OUTPUT
43+
else
44+
echo "pypi_token_present=false" >> $GITHUB_OUTPUT
45+
fi
46+
47+
deploy:
48+
runs-on: ubuntu-22.04
49+
needs: [ validate, check-for-functional-changes, check-pypi-token ]
50+
if: needs.check-for-functional-changes.outputs.status == 'success' && needs.check-pypi-token.outputs.pypi_token_present == 'true'
51+
steps:
52+
- uses: actions/checkout@v4
53+
- name: Set up Python
54+
uses: actions/setup-python@v5
55+
with:
56+
python-version: 3.9.12
57+
- name: Restore build
58+
uses: actions/cache@v4
59+
with:
60+
path: ${{ env.pythonLocation }}
61+
key: build-${{ env.pythonLocation }}-${{ hashFiles('pyproject.toml') }}-${{ github.sha }}
62+
- name: Restore built package
63+
uses: actions/cache@v4
64+
with:
65+
path: dist
66+
key: release-${{ env.pythonLocation }}-${{ hashFiles('pyproject.toml') }}-${{ github.sha }}
67+
- name: Upload a Python package to PyPi
68+
run: twine upload dist/* --username __token__ --password ${{ secrets.PYPI_TOKEN }}
69+
- name: Publish a git tag
70+
run: "${GITHUB_WORKSPACE}/.github/publish-git-tag.sh"
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: First time setup
2+
3+
on:
4+
create:
5+
workflow_dispatch:
6+
7+
permissions:
8+
actions: write
9+
checks: write
10+
contents: write
11+
12+
jobs:
13+
first-time-setup:
14+
# Ensure this job does not run on the template repository or when the repository is forked
15+
if: ${{ !github.event.repository.is_template && !github.event.repository.fork }}
16+
runs-on: ubuntu-latest
17+
steps:
18+
- name: Checkout
19+
uses: actions/checkout@v4
20+
with:
21+
repo-token: ${{ secrets.GITHUB_TOKEN }}
22+
23+
- name: Infer jurisdiction name from repository name
24+
run: |
25+
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
26+
27+
- name: Execute the first-time-setup script
28+
run: CI=true JURISDICTION_NAME="$TITLE_CASE_JURISDICTION_NAME" REPOSITORY_URL="${{ github.repositoryUrl }}" ./first-time-setup.sh
29+
30+
- name: Commit changes
31+
uses: stefanzweifel/git-auto-commit-action@v5
32+
with:
33+
commit_message: "Customise country-template through CI"
34+
tagging_message: "0.0.1"
35+
env:
36+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/validate.yml

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
name: Validate
2+
3+
on:
4+
pull_request:
5+
types: [ assigned, opened, reopened, synchronize, ready_for_review ]
6+
workflow_call:
7+
8+
jobs:
9+
build:
10+
uses: "./.github/workflows/build.yml"
11+
12+
lint-files:
13+
runs-on: ubuntu-22.04
14+
needs: [ build ]
15+
steps:
16+
- uses: actions/checkout@v4
17+
18+
- name: Install Tox
19+
run: pipx install tox
20+
21+
- name: Set up Python
22+
uses: actions/setup-python@v5
23+
with:
24+
python-version: 3.9.12
25+
26+
- name: Lint files
27+
run: tox -r -e lint
28+
29+
test-yaml:
30+
runs-on: ubuntu-22.04
31+
needs: [ build ]
32+
steps:
33+
- uses: actions/checkout@v4
34+
35+
- name: Install Tox
36+
run: pipx install tox
37+
38+
- name: Set up Python
39+
uses: actions/setup-python@v5
40+
with:
41+
python-version: 3.9.12
42+
43+
- name: Test files
44+
run: tox -r -e py39
45+
46+
test-dist:
47+
runs-on: ubuntu-22.04
48+
needs: [ build ]
49+
steps:
50+
- uses: actions/checkout@v4
51+
52+
- name: Set up Python
53+
uses: actions/setup-python@v5
54+
with:
55+
python-version: 3.9.12
56+
57+
- name: Restore built package
58+
uses: actions/cache@v4
59+
with:
60+
path: dist
61+
key: release-${{ env.pythonLocation }}-${{ hashFiles('pyproject.toml') }}-${{ github.sha }}
62+
63+
- name: Test the built package
64+
run: |
65+
pip install twine
66+
twine check dist/*
67+
68+
test-api:
69+
runs-on: ubuntu-22.04
70+
needs: [ build ]
71+
steps:
72+
- uses: actions/checkout@v4
73+
74+
- name: Set up Python
75+
uses: actions/setup-python@v5
76+
with:
77+
python-version: 3.9.12
78+
79+
- name: Restore build
80+
uses: actions/cache@v4
81+
with:
82+
path: ${{ env.pythonLocation }}
83+
key: build-${{ env.pythonLocation }}-${{ hashFiles('pyproject.toml') }}-${{ github.sha }}
84+
85+
- name: Test the Web API
86+
run: "${GITHUB_WORKSPACE}/.github/test-api.sh"
87+
88+
check-version-and-changelog:
89+
runs-on: ubuntu-22.04
90+
steps:
91+
- uses: actions/checkout@v4
92+
with:
93+
fetch-depth: 0 # Fetch all the tags
94+
95+
- name: Set up Python
96+
uses: actions/setup-python@v5
97+
with:
98+
python-version: 3.9.12
99+
100+
- name: Check version number has been properly updated
101+
run: "${GITHUB_WORKSPACE}/.github/is-version-number-acceptable.sh"

0 commit comments

Comments
 (0)