Skip to content

Commit

Permalink
feat: display the version number in the footer
Browse files Browse the repository at this point in the history
  • Loading branch information
azmeuk committed Oct 17, 2023
1 parent ba372c1 commit 9517773
Show file tree
Hide file tree
Showing 7 changed files with 115 additions and 4 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,18 @@ docker compose -f docker-compose.yml -f docker-compose.prod.yml up

Vous pouvez suivre la documentation dans [./CONTRIBUTING.md](./CONTRIBUTING.md) pour installer localement le projet et le tester.

## Publier une nouvelle version

- Mettre un tag sur le commit, portant le numéro de la version, avec `git tag vX.Y.Z`
- Pousser le commit ET le tag `git push origin main --tags`
- Se rendre sur [la page github de publication de version](https://github.com/numerique-gouv/b3desk/releases/new)
- Choisir le tag récemment ajouté, remplir les informations, publier la version.

Attention, pour que le numéro de version s'affiche correctement sur la version déployée,
il est nécessaire que le projet soit déployé avec git (c.à.d. qu'il y ait un dépôt git
qui soit déployé), et aussi que le commit qui soit déployé soit directement marqué par
un tag git. Dans les autres cas, c'est le numéro de commit qui sera affiché.

## Licence

Ce logiciel est mis à disposition sous la licence EUPL : https://commission.europa.eu/content/european-union-public-licence_fr
72 changes: 69 additions & 3 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ flask-pyoidc = "^3.14.2"
flask-sqlalchemy = "^3.0.3"
flask-uploads = "0.2.1"
flask-migrate = "3.1.0"
gitpython = "^3.1.38"
gunicorn = "20.1.0"
netaddr = "0.8.0"
sqlalchemy = "1.4.31"
Expand Down
5 changes: 5 additions & 0 deletions web/flaskr/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,18 @@ def setup_database(app):


def setup_jinja(app):
from flaskr.utils import get_git_tag, get_git_commit

version = get_git_commit() or get_git_tag() or None

@app.context_processor
def global_processor():
return {
"config": app.config,
"beta": app.config["BETA"],
"documentation_link": app.config["DOCUMENTATION_LINK"],
"is_rie": is_rie(),
"version": version,
"LANGUAGES": LANGUAGES,
**app.config["WORDINGS"],
}
Expand Down
1 change: 1 addition & 0 deletions web/flaskr/templates/footer.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<p class="fr-footer__content-desc">
{% trans %}Le code source est ouvert et les contributions sont bienvenues.{% endtrans %}
<a title="{% trans %}Voir le code source - nouvelle fenêtre{% endtrans %}" href="https://github.com/numerique-gouv/b3desk" target="_blank" rel="noopener">{% trans %}Voir le code source{% endtrans %}</a>
{% if version %}{{ version }}{% endif %}
</p>
<ul class="fr-footer__content-list">
<li class="fr-footer__content-item">
Expand Down
23 changes: 23 additions & 0 deletions web/flaskr/utils.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import git
from flask import current_app
from flask import request
from netaddr import IPAddress
Expand All @@ -21,3 +22,25 @@ def is_rie():
for network_ip in current_app.config.get("RIE_NETWORK_IPS", [])
if network_ip
)


def get_git_commit(): # pragma: no cover
try:
repo = git.Repo()
sha = repo.head.commit.hexsha
short_sha = repo.git.rev_parse(sha, short=4)
return short_sha

except git.exc.GitError:
return None


def get_git_tag(): # pragma: no cover
try:
repo = git.Repo()
tag = next((tag for tag in repo.tags if tag.commit == repo.head.commit), None)
if tag:
return tag.name

except git.exc.GitError:
return None
Loading

0 comments on commit 9517773

Please sign in to comment.