Skip to content
Snippets Groups Projects
Commit 8b793bf1 authored by sandcha's avatar sandcha
Browse files

Merge branch 'publish' into 'main'

CI - Ajoute le build, le tag git et la publication sur PyPi

See merge request !6
parents 7d3a5677 d09bc6cf
Branches
Tags 0.1.3
1 merge request!6CI - Ajoute le build, le tag git et la publication sur PyPi
Pipeline #16268 passed
...@@ -6,6 +6,8 @@ variables: ...@@ -6,6 +6,8 @@ variables:
stages: stages:
- install - install
- test - test
- build
- deploy
# get a cache before each stage # get a cache before each stage
cache: cache:
...@@ -31,6 +33,7 @@ before_script: ...@@ -31,6 +33,7 @@ before_script:
install-repository: install-repository:
stage: install stage: install
script: script:
- poetry run pip install --upgrade pip
- poetry install - poetry install
check-style: check-style:
...@@ -43,4 +46,56 @@ test: ...@@ -43,4 +46,56 @@ test:
stage: test stage: test
needs: ["install-repository"] needs: ["install-repository"]
script: script:
# for now, runs the tests against source code (for more secure tests, update to run against built wheel)
- poetry run pytest --log-cli-level=DEBUG - poetry run pytest --log-cli-level=DEBUG
check-version:
stage: build
script:
# check for functional changes and version number
- .gitlab/ci/is-version-number-acceptable.sh
except:
- main
build-wheel:
stage: build
needs: ["test"]
script:
- rm -rf build dist
- find . -name '*.pyc' -exec rm \{\} \;
- poetry run pip install --upgrade wheel
- poetry build --format wheel
artifacts:
paths:
# non indexed wheel: dist/leximpact_dotations_back-x.y.z-py3-none-any.whl
- dist/*
# create release in order to create tag (to bypass 'git tag' access rights configuration)
release-and-tag:
stage: deploy
# use release-cli to get release name from variable
image: registry.gitlab.com/gitlab-org/release-cli:latest
rules:
- if: $CI_COMMIT_TAG
when: never # avoid running the pipeline twice: do not run this job when a tag is created
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
before_script:
# override default before_script made for 'python' image and get version with shell only
# (pip and poetry are not installed in 'release-cli' image)
- export TAG_NAME=`grep -oE 'version\s*=\s*"([^"]*)"' pyproject.toml | sed 's/version = "//' | tr -d '"'`
script:
- if ! .gitlab/ci/has-functional-changes.sh ; then exit 0 ; fi
- echo "Creating $TAG_NAME release (and tag)..." # creates the tag when it doesn't exist
- release-cli create --name "$TAG_NAME" --description "$CI_JOB_STARTED_AT release" --tag-name "$TAG_NAME" --ref "$CI_COMMIT_SHA" --assets-link "{\"url\":\"https://$CI_REGISTRY_IMAGE/$TAG_NAME\",\"name\":\"Container Image \"}"
deploy-wheel:
stage: deploy
script:
- if ! .gitlab/ci/has-functional-changes.sh ; then exit 0 ; fi
# publish the wheel knowing that artifacts from all previous stages are passed by default
# use leximpact-bot PyPi account and token defined in:
# https://git.leximpact.dev/admin/application_settings/ci_cd
- poetry run pip install --upgrade twine
- poetry run twine upload dist/* --username __token__ --password $PYPI_TOKEN
only:
- main
#! /usr/bin/env bash
IGNORE_DIFF_ON="README.md CONTRIBUTING.md .gitignore .gitlab-ci.yml .gitlab/*"
remote_tags_exist=`git ls-remote --tags origin`
if [[ $remote_tags_exist ]];
then
# get last tagged commit
commit_to_compare_to=`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
else
# get remote main branch last commit
commit_to_compare_to=`git rev-parse origin/main`
fi
if git diff-index --name-only --exit-code $commit_to_compare_to -- . `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
#! /usr/bin/env bash
if [[ $CI_COMMIT_BRANCH == main ]]
then
echo "No need for a version check on main."
exit 0
fi
if ! $(dirname "$BASH_SOURCE")/has-functional-changes.sh
then
echo "No need for a version update."
exit 0
fi
current_version=`poetry version --short`
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 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
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 main."
echo "Look at the CONTRIBUTING.md file to learn how to write the changelog."
exit 2
fi
# CHANGELOG # CHANGELOG
### 0.1.3 [!6](https://git.leximpact.dev/leximpact/simulateur-dotations-communes/leximpact-dotations-back/-/merge_requests/6)
* Amélioration technique.
* Détails :
* Complète la configuration de l'intégration continue dont le déploiement depuis la branche `main` et environnement `integration`
* Ajoute la création de [release GitLab](https://git.leximpact.dev/leximpact/simulateur-dotations-communes/leximpact-dotations-back/-/releases) pour permettre la création de [tag GIT](https://git.leximpact.dev/leximpact/simulateur-dotations-communes/leximpact-dotations-back/-/tags)
* Ajoute la [publication sur PyPi](https://pypi.org/project/leximpact-dotations-back/)
* Initie un fichier `CONTRIBUTING.md`
### 0.1.2 [!5](https://git.leximpact.dev/leximpact/simulateur-dotations-communes/leximpact-dotations-back/-/merge_requests/5) ### 0.1.2 [!5](https://git.leximpact.dev/leximpact/simulateur-dotations-communes/leximpact-dotations-back/-/merge_requests/5)
* Amélioration technique * Amélioration technique
...@@ -7,7 +16,7 @@ ...@@ -7,7 +16,7 @@
* Ajoute le texte de la LICENSE * Ajoute le texte de la LICENSE
* Met à jour la description de la librairie dans `pyproject.toml` (contact, licence, classification) * Met à jour la description de la librairie dans `pyproject.toml` (contact, licence, classification)
### 0.1.1 ### 0.1.1 [!4](https://git.leximpact.dev/leximpact/simulateur-dotations-communes/leximpact-dotations-back/-/merge_requests/4)
* Amélioration technique. * Amélioration technique.
* Détails : * Détails :
...@@ -19,7 +28,7 @@ ...@@ -19,7 +28,7 @@
* Corrige le style des fichiers Python * Corrige le style des fichiers Python
* Documente les commandes dans le `README` * Documente les commandes dans le `README`
## 0.1.0 ## 0.1.0 [!2](https://git.leximpact.dev/leximpact/simulateur-dotations-communes/leximpact-dotations-back/-/merge_requests/2)
* Ajout d'une fonctionnalité. * Ajout d'une fonctionnalité.
* Période : 2024 * Période : 2024
......
# Contribuer à leximpact-dotations-back
Avant tout, merci de votre volonté de contribuer au dépôt `leximpact-dotations-back` !
Afin de faciliter son utilisation et d'améliorer la qualité du code, les contributions suivent certaines règles décrites dans ce fichier.
## Format des versions et du CHANGELOG
Les évolutions de `leximpact-dotations-back` doivent pouvoir être comprises par des utilisateurs ne disposant pas du contexte complet de l'application. C'est pourquoi nous faisons le choix :
* D'un [versionnement sémantique](https://semver.org/lang/fr/) de l'application où l'évaluation des changements majeurs se fait au regard des évolutions de l'API web.
* De l'existence d'un [CHANGELOG.md](./CHANGELOG.md), rédigé en français, pour la description des évolutions. Celui-ci se doit être le plus explicite possible.
[tool.poetry] [tool.poetry]
name = "leximpact-dotations-back" name = "leximpact-dotations-back"
version = "0.1.2" version = "0.1.3"
description = "Simulating annual State grants to the French administrative divisions" description = "Simulating annual State grants to the French administrative divisions"
authors = ["LexImpact <leximpact@assemblee-nationale.fr>"] authors = ["LexImpact <leximpact@assemblee-nationale.fr>"]
license = "AGPL-3.0-or-later" license = "AGPL-3.0-or-later"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment