Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
O
OpenFisca-France-Reforms
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
leximpact
Simulateur socio-fiscal
Adaptations OpenFisca
OpenFisca-France-Reforms
Commits
33734676
Commit
33734676
authored
Oct 14, 2021
by
Emmanuel Raviart
Browse files
Options
Downloads
Plain Diff
Merge branch 'rework_ci' into 'master'
Rework CI See merge request openfisca/openfisca-france-reforms!2
parents
cda7306f
d69cfcfe
No related branches found
No related tags found
1 merge request
!2
Rework CI
Pipeline
#1059
failed
Oct 14, 2021
Stage: sync_with_openfisca_france
Changes
3
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
.gitlab-ci.yml
+41
-3
41 additions, 3 deletions
.gitlab-ci.yml
pyproject.toml
+1
-1
1 addition, 1 deletion
pyproject.toml
src/scripts/sync_with_openfisca_france.ts
+65
-49
65 additions, 49 deletions
src/scripts/sync_with_openfisca_france.ts
with
107 additions
and
53 deletions
.gitlab-ci.yml
+
41
−
3
View file @
33734676
...
...
@@ -9,11 +9,12 @@ default:
stages
:
-
build
-
sync_with_openfisca_france
-
trigger
build
:
stage
:
build
rules
:
-
if
:
'
$CI_PIPELINE_SOURCE
==
"
push
"'
-
if
:
'
$CI_PIPELINE_SOURCE
==
"
merge_request_event
"'
before_script
:
## Without apt update, apt install fails.
-
apt update --yes
...
...
@@ -26,10 +27,33 @@ build:
script
:
-
poetry run python -m openfisca_france_reforms.plf_2022.scripts.run_test
build_with_latest_dependencies
:
stage
:
build
rules
:
-
if
:
'
$CI_PIPELINE_SOURCE
==
"merge_request_event"'
before_script
:
## Without apt update, apt install fails.
-
apt update --yes
-
apt install --yes python-is-python3 python3-virtualenv
-
curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/install-poetry.py | python -
## Add Poetry to path:
-
export PATH="/root/.local/bin:$PATH"
-
poetry update
-
poetry install
script
:
-
poetry run python -m openfisca_france_reforms.plf_2022.scripts.run_test
sync_with_openfisca_france
:
stage
:
sync_with_openfisca_france
rules
:
-
if
:
'
$CI_PROJECT_URL
==
"https://git.leximpact.dev/openfisca/openfisca-france-reforms"
&&
$CI_COMMIT_BRANCH
==
"master"'
# This step is called
# - When a pipeline has been triggered (for example when OpenFisca-France has been updated).
# In this case a new version of OpenFisca-France-Reforms must be created if a dependency has changed.
-
if
:
'
($CI_PIPELINE_SOURCE
==
"api"
||
$CI_PIPELINE_SOURCE
==
"schedule"
||
$CI_PIPELINE_SOURCE
==
"trigger"
||
$CI_PIPELINE_SOURCE
==
"web")
&&
$CI_PROJECT_URL
==
"https://git.leximpact.dev/openfisca/openfisca-france-reforms"
&&
$CI_COMMIT_BRANCH
==
"master"'
# - When a merge request has been merged into master (ie content of OpenFisca-France-Reforms has been changed).
# In this case a new version of OpenFisca-France-Reforms must always be created.
-
if
:
'
$CI_PIPELINE_SOURCE
==
"push"
&&
$CI_PROJECT_URL
==
"https://git.leximpact.dev/openfisca/openfisca-france-reforms"
&&
$CI_COMMIT_BRANCH
==
"master"'
before_script
:
## Without apt update, apt install fails.
-
apt update --yes
...
...
@@ -67,4 +91,18 @@ sync_with_openfisca_france:
## Needed when Node version changes:
-
npm rebuild
script
:
-
npx babel-node --extensions ".ts" -- src/scripts/sync_with_openfisca_france.ts
-
|
if [ "$CI_PIPELINE_SOURCE" == "push" ]; then
npx babel-node --extensions ".ts" -- src/scripts/sync_with_openfisca_france.ts --force
else
npx babel-node --extensions ".ts" -- src/scripts/sync_with_openfisca_france.ts
fi
trigger_openfisca_json_model
:
stage
:
trigger
only
:
# OpenFisca-JSON-Model pipeline should only be called
# when a new version branch and version tag has been created.
# Here we assume that tags are only created for versions.
-
tags
trigger
:
openfisca/json-model
This diff is collapsed.
Click to expand it.
pyproject.toml
+
1
−
1
View file @
33734676
[tool.poetry]
name
=
"openfisca-france-reforms"
version
=
"0.
5.4
"
version
=
"0.
0.0
"
description
=
"Some reforms for French OpenFisca tax-benefit system"
authors
=
[
"Emmanuel Raviart <emmanuel@raviart.com>"
]
keywords
=
[
"benefit"
,
"france"
,
"microsimulation"
,
"reform"
,
"social"
,
"tax"
]
...
...
This diff is collapsed.
Click to expand it.
src/scripts/sync_with_openfisca_france.ts
+
65
−
49
View file @
33734676
import
toml
from
"
@ltd/j-toml
"
import
{
$
,
fs
}
from
"
zx
"
import
{
$
,
argv
,
fs
}
from
"
zx
"
interface
Package
{
name
:
string
version
:
string
}
interface
Project
{
tool
:
{
poetry
:
{
version
:
string
}
async
function
latestVersionObjectFromTags
()
{
return
(
await
$
`git tag --list`
).
stdout
.
split
(
"
\n
"
)
.
filter
((
line
)
=>
line
.
match
(
/^
\d
+
\.\d
+
\.\d
+$/
))
.
map
((
version
)
=>
{
const
match
=
version
.
match
(
/^
(\d
+
)\.(\d
+
)\.(\d
+
)
$/
)
as
string
[]
return
{
major
:
parseInt
(
match
[
1
]),
minor
:
parseInt
(
match
[
2
]),
patch
:
parseInt
(
match
[
3
]),
}
})
.
sort
((
groups1
,
groups2
)
=>
groups1
.
major
!==
groups2
.
major
?
groups2
.
major
-
groups1
.
major
:
groups1
.
minor
!==
groups2
.
minor
?
groups2
.
minor
-
groups1
.
minor
:
groups2
.
patch
-
groups1
.
patch
,
)[
0
]
}
/// Upgrade, test & push openfisca-france-reforms when openfisca-france or
...
...
@@ -19,23 +32,23 @@ interface Project {
async
function
main
()
{
await
$
`poetry update`
await
$
`poetry install`
await
$
`poetry run python -m openfisca_france_reforms.plf_2022.scripts.run_test`
if
(
!
argv
.
force
)
{
await
$
`git add .`
if
((
await
$
`git diff --quiet --staged`
.
exitCode
)
===
1
)
{
if
((
await
$
`git diff --quiet --staged`
.
exitCode
)
===
0
)
{
// Repository content has not changed.
// => Ensure that job is stopped and other pipelines are not triggered.
process
.
exit
(
1
)
}
}
// Dependencies of openfisca-france-reforms have changed.
const
projectTomlPath
=
"
pyproject.toml
"
let
projectToml
=
await
fs
.
readFile
(
projectTomlPath
,
"
utf-8
"
)
const
project
=
toml
.
parse
(
projectToml
,
"
\n
"
)
as
unknown
as
Project
const
version
=
project
.
tool
.
poetry
.
version
const
versionSplit
=
version
.
split
(
"
.
"
)
const
patch
=
parseInt
(
versionSplit
[
2
]
??
"
0
"
)
const
newVersion
=
[
versionSplit
[
0
],
versionSplit
[
1
],
(
patch
+
1
).
toString
(),
].
join
(
"
.
"
)
// Ensure that everything works.
await
$
`poetry run python -m openfisca_france_reforms.plf_2022.scripts.run_test`
// Retrieve current OpenFisca-France version
const
poetryLockToml
=
await
fs
.
readFile
(
"
poetry.lock
"
)
const
poetryLock
=
toml
.
parse
(
poetryLockToml
,
"
\n
"
)
const
openFiscaFrancePackage
=
(
poetryLock
.
package
as
Package
[]).
find
(
...
...
@@ -43,15 +56,18 @@ async function main() {
)
const
openFiscaFranceVersion
=
openFiscaFrancePackage
!
.
version
// Retrieve next version of OpenFisca-France-Reforms.
const
{
major
,
minor
,
patch
}
=
await
latestVersionObjectFromTags
()
const
nextVersion
=
`
${
major
}
.
${
minor
}
.
${
patch
+
1
}
`
// Update pyproject.toml with latest version of OpenFisca-France
// and next version of OpenFisca-France-Reforms.
const
projectTomlPath
=
"
pyproject.toml
"
let
projectToml
=
await
fs
.
readFile
(
projectTomlPath
,
"
utf-8
"
)
projectToml
=
projectToml
.
replace
(
/^version = "
(
.*
?)
"$/m
,
`version = "
${
ne
w
Version
}
"`
,
`version = "
${
ne
xt
Version
}
"`
,
)
await
fs
.
writeFile
(
projectTomlPath
,
projectToml
,
"
utf-8
"
)
await
$
`git add .`
await
$
`git commit -m "
${
newVersion
}
(openfisca-france@
${
openFiscaFranceVersion
}
)"`
await
$
`git push`
projectToml
=
projectToml
.
replace
(
/^openfisca-france = "
\*
"$/im
,
`openfisca-france = "^
${
openFiscaFranceVersion
}
"`
,
...
...
@@ -59,14 +75,14 @@ async function main() {
await
fs
.
writeFile
(
projectTomlPath
,
projectToml
,
"
utf-8
"
)
await
$
`git add .`
const
branch
=
newVersion
.
replace
(
/
\.
/g
,
"
_
"
)
// Commit updated pyproject.toml in a new branch tagged with version number.
const
branch
=
nextVersion
.
replace
(
/
\.
/g
,
"
_
"
)
await
$
`git switch -c
${
branch
}
`
await
$
`git commit -m "
Set
openfisca-france
version to
${
openFiscaFranceVersion
}
.
"`
await
$
`git tag -a "
${
ne
w
Version
}
" -m "
${
ne
w
Version
}
(openfisca-france@
${
openFiscaFranceVersion
}
)"`
await
$
`git commit -m "
${
nextVersion
}
(
openfisca-france
@
${
openFiscaFranceVersion
}
)
"`
await
$
`git tag -a "
${
ne
xt
Version
}
" -m "
${
ne
xt
Version
}
(openfisca-france@
${
openFiscaFranceVersion
}
)"`
await
$
`git push --set-upstream --tags origin
${
branch
}
`
await
$
`git switch master`
}
}
main
()
.
then
(()
=>
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment