From 6f96f67655ee88c920bcd889f58faaf8ae78f1cf Mon Sep 17 00:00:00 2001 From: Aditya Toshniwal Date: Thu, 27 Jun 2024 13:20:00 +0530 Subject: [PATCH] Add the git commit hash details to the About dialog. #7623 --- .github/workflows/check-container-build.yml | 3 ++ .gitignore | 1 + pkg/src/build.sh | 5 ++ web/package.json | 2 +- web/pgAdmin4.py | 10 ++++ web/pgadmin/about/__init__.py | 1 + .../about/static/js/AboutComponent.jsx | 49 ++++++++----------- 7 files changed, 42 insertions(+), 29 deletions(-) diff --git a/.github/workflows/check-container-build.yml b/.github/workflows/check-container-build.yml index b7688dea5..ef4096699 100644 --- a/.github/workflows/check-container-build.yml +++ b/.github/workflows/check-container-build.yml @@ -18,6 +18,9 @@ jobs: steps: - uses: actions/checkout@v4 + with: + fetch-depth: 2 + - run: git checkout HEAD^ - name: Build the container run: docker build . diff --git a/.gitignore b/.gitignore index 75575d06d..b306f0d6a 100644 --- a/.gitignore +++ b/.gitignore @@ -48,6 +48,7 @@ node_modules/ web/pgAdmin/static/js/generated web/pgadmin/static/js/generated web/yarn-error.log +web/commit_hash /web/cacert.pem auditjs.html auditpy.txt diff --git a/pkg/src/build.sh b/pkg/src/build.sh index 117a1b831..35aff0058 100755 --- a/pkg/src/build.sh +++ b/pkg/src/build.sh @@ -32,6 +32,9 @@ fi TARBALL_NAME=$(echo "${APP_NAME}-${APP_LONG_VERSION}" | sed 's/ //g' | awk '{print tolower($0)}') DOC_TARBALL_NAME=$(echo "${APP_NAME}-${APP_LONG_VERSION}-docs" | sed 's/ //g' | awk '{print tolower($0)}') +# Get the github timestamp +git log -1 --format='%H %as' > web/commit_hash + # Output basic details to show we're working echo "Building tarballs for ${APP_NAME} version ${APP_LONG_VERSION}..." @@ -69,6 +72,8 @@ do tar cf - "${FILE}" | (cd "src-build/${TARBALL_NAME}"; tar xf -) done +tar cf - "web/commit_hash" | (cd "src-build/${TARBALL_NAME}"; tar xf -) + # Create the tarball echo Creating tarball... cd src-build || exit diff --git a/web/package.json b/web/package.json index 7c7417c40..0a1c034a2 100644 --- a/web/package.json +++ b/web/package.json @@ -168,7 +168,7 @@ "bundle:watch": "yarn run linter && yarn run webpacker:watch", "bundle:dev": "yarn run linter && yarn run webpacker", "bundle:analyze": "cross-env NODE_ENV=production ANALYZE=true yarn run bundle:dev", - "bundle": "cross-env NODE_ENV=production NODE_OPTIONS=--max-old-space-size=3072 yarn run bundle:dev", + "bundle": "cross-env NODE_ENV=production NODE_OPTIONS=--max-old-space-size=3072 yarn run bundle:dev && git log -1 --format='%H %as' > commit_hash", "test:js-once": "yarn run linter && yarn run jest --maxWorkers=50%", "test:js": "yarn run test:js-once --watch", "test:js-file": "yarn run test:js-once -t", diff --git a/web/pgAdmin4.py b/web/pgAdmin4.py index 5adbb0c48..e4aa89f82 100644 --- a/web/pgAdmin4.py +++ b/web/pgAdmin4.py @@ -103,6 +103,16 @@ if not os.path.isfile(config.SQLITE_PATH): app = create_app() app.config['sessions'] = dict() +# We load the file here instead of evaluate config +# as we don't know the path of this file in evaluate config +# commit_hash file resides in the web directory +try: + with open(os.path.join(os.path.dirname(os.path.realpath(__file__)), + 'commit_hash')) as f: + config.COMMIT_HASH = f.readline().strip() +except FileNotFoundError as _: + config.COMMIT_HASH = None + if setup_db_required: setup.setup_db(app) diff --git a/web/pgadmin/about/__init__.py b/web/pgadmin/about/__init__.py index 4739922a5..434f21a7b 100644 --- a/web/pgadmin/about/__init__.py +++ b/web/pgadmin/about/__init__.py @@ -70,6 +70,7 @@ def index(): else: info['app_mode'] = gettext('Desktop') + info['commit_hash'] = getattr(config, 'COMMIT_HASH', None) info['browser_details'] = browser info['version'] = config.APP_VERSION info['admin'] = admin diff --git a/web/pgadmin/about/static/js/AboutComponent.jsx b/web/pgadmin/about/static/js/AboutComponent.jsx index 7bb45c3b0..5323d4d32 100644 --- a/web/pgadmin/about/static/js/AboutComponent.jsx +++ b/web/pgadmin/about/static/js/AboutComponent.jsx @@ -8,33 +8,16 @@ ////////////////////////////////////////////////////////////// import gettext from 'sources/gettext'; -import { styled } from '@mui/material/styles'; import url_for from 'sources/url_for'; import React, { useEffect, useState, useRef } from 'react'; import { Box, Grid, InputLabel } from '@mui/material'; -import { DefaultButton } from '../../../static/js/components/Buttons'; -import { InputText } from '../../../static/js/components/FormComponents'; +import { InputSQL } from '../../../static/js/components/FormComponents'; import getApiInstance from '../../../static/js/api_instance'; -import { copyToClipboard } from '../../../static/js/clipboard'; -import { useDelayedCaller } from '../../../static/js/custom_hooks'; import { usePgAdmin } from '../../../static/js/BrowserComponent'; -const StyledDefaultButton = styled(DefaultButton)(({theme}) => ({ - '&.AboutComponent-copyBtn': { - marginRight: '1px', - float: 'right', - borderColor: theme.otherVars.borderColor, - fontSize: '13px', - } -})); - export default function AboutComponent() { const containerRef = useRef(); const [aboutData, setAboutData] = useState([]); - const [copyText, setCopyText] = useState(gettext('Copy')); - const revertCopiedText = useDelayedCaller(()=>{ - setCopyText(gettext('Copy')); - }); const pgAdmin = usePgAdmin(); useEffect(() => { @@ -66,6 +49,14 @@ export default function AboutComponent() { {aboutData.app_mode} + + + {gettext('Commit:')} + + + {aboutData.commit_hash} + + {gettext('Current User')} @@ -123,18 +114,20 @@ export default function AboutComponent() { } { aboutData.settings && - + - {gettext('Server Configuration')} - { - copyToClipboard(aboutData.settings); - setCopyText(gettext('Copied!')); - revertCopiedText(1500); - }}>{copyText} + {gettext('pgAdmin Server Configuration')} - - + + }