Skip to content

Commit

Permalink
✨(version) convey version information to the /config endpoint and footer
Browse files Browse the repository at this point in the history
We add the machinery to get version information and display it discreetly.
  • Loading branch information
Laurent Bossavit authored and Laurent Bossavit committed Nov 17, 2024
1 parent 7e4a820 commit f94b192
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/backend/core/api/viewsets.py
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ def get(self, request):
GET /api/v1.0/config/
Return a dictionary of public settings.
"""
array_settings = ["LANGUAGES", "FEATURES", "RELEASE"]
array_settings = ["LANGUAGES", "FEATURES", "RELEASE", "COMMIT"]
dict_settings = {}
for setting in array_settings:
dict_settings[setting] = getattr(settings, setting)
Expand Down
2 changes: 2 additions & 0 deletions src/backend/core/tests/test_api_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ def test_api_config_anonymous():
assert response.status_code == HTTP_200_OK
assert response.json() == {
"LANGUAGES": [["en-us", "English"], ["fr-fr", "French"]],
"COMMIT":"NA",
"FEATURES": {
"CONTACTS_DISPLAY": True,
"CONTACTS_CREATE": True,
Expand All @@ -42,6 +43,7 @@ def test_api_config_authenticated():
assert response.status_code == HTTP_200_OK
assert response.json() == {
"LANGUAGES": [["en-us", "English"], ["fr-fr", "French"]],
"COMMIT":"NA",
"FEATURES": {
"CONTACTS_DISPLAY": True,
"CONTACTS_CREATE": True,
Expand Down
19 changes: 19 additions & 0 deletions src/backend/people/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,17 @@ def get_release():
return "NA" # Default: not available


def get_commit():
"""
Get the current commit of the application
"""
try:
with open(os.path.join(BASE_DIR, "version.json"), encoding="utf8") as version:
return json.load(version)["commit"]
except FileNotFoundError:
return "NA" # Default: not available


class Base(Configuration):
"""
This is the base configuration every configuration (aka environment) should inherit from. It
Expand Down Expand Up @@ -488,6 +499,14 @@ def RELEASE(self):
"""
return get_release()

# pylint: disable=invalid-name
@property
def COMMIT(self):
"""
Return the commit information.
"""
return get_release()

# pylint: disable=invalid-name
@property
def PARLER_LANGUAGES(self):
Expand Down
1 change: 1 addition & 0 deletions src/frontend/apps/desk/src/core/config/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export interface Config {
LANGUAGES: [string, string][];
RELEASE: string;
COMMIT: string;
FEATURES: {
TEAMS_DISPLAY: boolean;
};
Expand Down
13 changes: 13 additions & 0 deletions src/frontend/apps/desk/src/features/footer/Footer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import styled from 'styled-components';
import { Box, LogoGouv, StyledLink, Text } from '@/components';
import { useConfigStore } from '@/core';

import frontVersion from '../../../version.json';

import IconLink from './assets/external-link.svg';

const BlueStripe = styled.div`
Expand Down Expand Up @@ -141,6 +143,17 @@ export const Footer = () => {
))}
</Box>

<Text
as="p"
$size="m"
$margin={{ top: 'big' }}
$variation="600"
$display="hidden"
>
You have found the hidden app version information ! Well done ! back
commit is: {config?.COMMIT}; front commit is: {frontVersion?.commit}
</Text>

<Text
as="p"
$size="m"
Expand Down
6 changes: 6 additions & 0 deletions src/frontend/apps/desk/version.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"source":"people",
"version":"version",
"commit":"commit",
"build": "NA"
}

0 comments on commit f94b192

Please sign in to comment.