Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 867c2d9

Browse files
MickaelCaNicolasIRAGNE
andauthored
feat(web): add version info display (#483)
Co-authored-by: Nicolas IRAGNE <nicoragne@hotmail.fr>
1 parent ca11748 commit 867c2d9

File tree

8 files changed

+136
-22
lines changed

8 files changed

+136
-22
lines changed

‎.github/workflows/docker-build.ecr.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ jobs:
3333
steps:
3434
- name: Checkout
3535
uses: actions/checkout@v4
36+
with:
37+
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}
3638

3739
- name: configure aws credentials
3840
uses: aws-actions/configure-aws-credentials@v4
@@ -46,6 +48,32 @@ jobs:
4648
run: |
4749
echo "timestamp=$(date +%s)" >> $GITHUB_OUTPUT
4850
echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
51+
echo "sha_full=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT
52+
53+
- name: Determine version and deployment context
54+
id: version
55+
run: |
56+
REPO_URL="https://github.com/${{ github.repository }}"
57+
58+
if [[ "${{ github.ref_type }}" == "tag" ]]; then
59+
# Tag deployment - display version, link to release
60+
echo "version=${{ github.ref_name }}" >> $GITHUB_OUTPUT
61+
echo "app_version=${{ github.ref_name }}" >> $GITHUB_OUTPUT
62+
echo "app_version_url=${REPO_URL}/releases/tag/${{ github.ref_name }}" >> $GITHUB_OUTPUT
63+
elif [[ "${{ github.event_name }}" == "pull_request" ]]; then
64+
# PR deployment - display pr-XXX, link to PR commit
65+
PR_NUMBER="${{ github.event.pull_request.number }}"
66+
COMMIT_HASH="${{ steps.vars.outputs.sha_full }}"
67+
echo "version=${PR_NUMBER}/merge-${COMMIT_HASH}" >> $GITHUB_OUTPUT
68+
echo "app_version=pr-${PR_NUMBER}" >> $GITHUB_OUTPUT
69+
echo "app_version_url=${REPO_URL}/pull/${PR_NUMBER}/commits/${COMMIT_HASH}" >> $GITHUB_OUTPUT
70+
else
71+
# Branch deployment - display branch name, link to commit
72+
BRANCH_NAME="${{ github.ref_name }}"
73+
COMMIT_HASH="${{ steps.vars.outputs.sha_full }}"
74+
echo "app_version=${BRANCH_NAME}" >> $GITHUB_OUTPUT
75+
echo "app_version_url=${REPO_URL}/commit/${COMMIT_HASH}" >> $GITHUB_OUTPUT
76+
fi
4977
5078
- name: Login to Amazon ECR
5179
id: login-ecr
@@ -78,5 +106,9 @@ jobs:
78106
push: ${{ github.event_name != 'pull_request' || env.PUSH_FROM_PR == 'true' }}
79107
tags: ${{ steps.meta.outputs.tags }}
80108
labels: ${{ steps.meta.outputs.labels }}
109+
build-args: |
110+
APP_REPOSITORY=https://github.com/${{ github.repository }}
111+
APP_VERSION=${{ steps.version.outputs.app_version }}
112+
APP_VERSION_URL=${{ steps.version.outputs.app_version_url }}
81113
cache-from: type=gha
82114
cache-to: type=gha,mode=max

‎.github/workflows/docker-build.ghcr.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,40 @@ jobs:
4444
egress-policy: audit
4545

4646
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
47+
with:
48+
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}
4749

4850
- name: Set current timestamp
4951
id: vars
5052
run: |
5153
echo "timestamp=$(date +%s)" >> $GITHUB_OUTPUT
5254
echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
55+
echo "sha_full=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT
56+
57+
- name: Determine version and deployment context
58+
id: version
59+
run: |
60+
REPO_URL="https://github.com/${{ github.repository }}"
61+
62+
if [[ "${{ github.ref_type }}" == "tag" ]]; then
63+
# Tag deployment - display version, link to release
64+
echo "version=${{ github.ref_name }}" >> $GITHUB_OUTPUT
65+
echo "app_version=${{ github.ref_name }}" >> $GITHUB_OUTPUT
66+
echo "app_version_url=${REPO_URL}/releases/tag/${{ github.ref_name }}" >> $GITHUB_OUTPUT
67+
elif [[ "${{ github.event_name }}" == "pull_request" ]]; then
68+
# PR deployment - display pr-XXX, link to PR commit
69+
PR_NUMBER="${{ github.event.pull_request.number }}"
70+
COMMIT_HASH="${{ steps.vars.outputs.sha_full }}"
71+
echo "version=${PR_NUMBER}/merge-${COMMIT_HASH}" >> $GITHUB_OUTPUT
72+
echo "app_version=pr-${PR_NUMBER}" >> $GITHUB_OUTPUT
73+
echo "app_version_url=${REPO_URL}/pull/${PR_NUMBER}/commits/${COMMIT_HASH}" >> $GITHUB_OUTPUT
74+
else
75+
# Branch deployment - display branch name, link to commit
76+
BRANCH_NAME="${{ github.ref_name }}"
77+
COMMIT_HASH="${{ steps.vars.outputs.sha_full }}"
78+
echo "app_version=${BRANCH_NAME}" >> $GITHUB_OUTPUT
79+
echo "app_version_url=${REPO_URL}/commit/${COMMIT_HASH}" >> $GITHUB_OUTPUT
80+
fi
5381
5482
- name: Log in to the Container registry
5583
uses: docker/login-action@184bdaa0721073962dff0199f1fb9940f07167d1 # v3.5.0
@@ -87,6 +115,10 @@ jobs:
87115
push: ${{ github.event_name != 'pull_request' || env.PUSH_FROM_PR == 'true' }}
88116
tags: ${{ steps.meta.outputs.tags }}
89117
labels: ${{ steps.meta.outputs.labels }}
118+
build-args: |
119+
APP_REPOSITORY=https://github.com/${{ github.repository }}
120+
APP_VERSION=${{ steps.version.outputs.app_version }}
121+
APP_VERSION_URL=${{ steps.version.outputs.app_version_url }}
90122
cache-from: type=gha
91123
cache-to: type=gha,mode=max
92124

‎Dockerfile

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,15 @@ FROM python:3.13.5-slim@sha256:4c2cf9917bd1cbacc5e9b07320025bdb7cdf2df7b0ceaccb5
2020

2121
ARG UID=1000
2222
ARG GID=1000
23+
ARG APP_REPOSITORY=https://github.com/coderamp-labs/gitingest
24+
ARG APP_VERSION=unknown
25+
ARG APP_VERSION_URL=https://github.com/coderamp-labs/gitingest
2326

2427
ENV PYTHONUNBUFFERED=1 \
25-
PYTHONDONTWRITEBYTECODE=1
28+
PYTHONDONTWRITEBYTECODE=1 \
29+
APP_REPOSITORY=${APP_REPOSITORY} \
30+
APP_VERSION=${APP_VERSION} \
31+
APP_VERSION_URL=${APP_VERSION_URL}
2632

2733
RUN set -eux; \
2834
apt-get update; \

‎src/server/main.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
from gitingest.utils.logging_config import get_logger
1919
from server.metrics_server import start_metrics_server
2020
from server.routers import dynamic, index, ingest
21-
from server.server_config import templates
21+
from server.server_config import get_version_info, templates
2222
from server.server_utils import limiter, rate_limit_exception_handler
2323

2424
# Load environment variables from .env file
@@ -169,7 +169,9 @@ async def custom_swagger_ui(request: Request) -> HTMLResponse:
169169
- **HTMLResponse**: Custom Swagger UI documentation page
170170
171171
"""
172-
return templates.TemplateResponse("swagger_ui.jinja", {"request": request})
172+
context = {"request": request}
173+
context.update(get_version_info())
174+
return templates.TemplateResponse("swagger_ui.jinja", context)
173175

174176

175177
@app.get("/api", include_in_schema=True)

‎src/server/routers/dynamic.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from fastapi import APIRouter, Request
44
from fastapi.responses import HTMLResponse
55

6-
from server.server_config import templates
6+
from server.server_config import get_version_info, templates
77

88
router = APIRouter()
99

@@ -29,11 +29,11 @@ async def catch_all(request: Request, full_path: str) -> HTMLResponse:
2929
and other default parameters such as file size.
3030
3131
"""
32-
returntemplates.TemplateResponse(
33-
"git.jinja",
34-
{
35-
"request": request,
36-
"repo_url": full_path,
37-
"default_max_file_size": 243,
38-
},
39-
)
32+
context= {
33+
"request": request,
34+
"repo_url": full_path,
35+
"default_max_file_size": 243,
36+
}
37+
context.update(get_version_info())
38+
39+
returntemplates.TemplateResponse("git.jinja", context)

‎src/server/routers/index.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from fastapi import APIRouter, Request
44
from fastapi.responses import HTMLResponse
55

6-
from server.server_config import EXAMPLE_REPOS, templates
6+
from server.server_config import EXAMPLE_REPOS, get_version_info, templates
77

88
router = APIRouter()
99

@@ -27,11 +27,11 @@ async def home(request: Request) -> HTMLResponse:
2727
and other default parameters such as file size.
2828
2929
"""
30-
returntemplates.TemplateResponse(
31-
"index.jinja",
32-
{
33-
"request": request,
34-
"examples": EXAMPLE_REPOS,
35-
"default_max_file_size": 243,
36-
},
37-
)
30+
context= {
31+
"request": request,
32+
"examples": EXAMPLE_REPOS,
33+
"default_max_file_size": 243,
34+
}
35+
context.update(get_version_info())
36+
37+
returntemplates.TemplateResponse("index.jinja", context)

‎src/server/server_config.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from __future__ import annotations
44

5+
import os
56
from pathlib import Path
67

78
from fastapi.templating import Jinja2Templates
@@ -21,6 +22,35 @@
2122
]
2223

2324

25+
# Version and repository configuration
26+
APP_REPOSITORY = os.getenv("APP_REPOSITORY", "https://github.com/coderamp-labs/gitingest")
27+
APP_VERSION = os.getenv("APP_VERSION", "unknown")
28+
APP_VERSION_URL = os.getenv("APP_VERSION_URL", "https://github.com/coderamp-labs/gitingest")
29+
30+
31+
def get_version_info() -> dict[str, str]:
32+
"""Get version information including display version and link.
33+
34+
Returns
35+
-------
36+
dict[str, str]
37+
Dictionary containing 'version' and 'version_link' keys.
38+
39+
"""
40+
# Use pre-computed values from GitHub Actions
41+
display_version = APP_VERSION
42+
version_link = APP_VERSION_URL
43+
44+
# Fallback to repository root if no URL is provided
45+
if version_link == APP_REPOSITORY or not version_link:
46+
version_link = f"{APP_REPOSITORY.rstrip('/')}/tree/main"
47+
48+
return {
49+
"version": display_version,
50+
"version_link": version_link,
51+
}
52+
53+
2454
# Use absolute path to templates directory
2555
templates_dir = Path(__file__).parent / "templates"
2656
templates = Jinja2Templates(directory=templates_dir)

‎src/server/templates/components/footer.jinja

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{% from 'components/_macros.jinja' import footer_icon_link %}
22
<footer class="w-full border-t-[3px] border-gray-900 mt-auto">
33
<div class="max-w-4xl mx-auto px-4 py-4">
4-
<div class="grid grid-cols-2 items-center text-gray-900 text-sm">
4+
<div class="grid grid-cols-3 items-center text-gray-900 text-sm">
55
{# Left column — Chrome + PyPI #}
66
<div class="flex items-center space-x-4">
77
{{ footer_icon_link('https://chromewebstore.google.com/detail/adfjahbijlkjfoicpjkhjicpjpjfaood',
@@ -11,6 +11,18 @@
1111
'icons/python.svg',
1212
'Python Package') }}
1313
</div>
14+
{# Middle column - Version information #}
15+
<div class="flex justify-center">
16+
<span>Version:&nbsp;</span>
17+
{% if version != "unknown" %}
18+
<a href="{{ version_link }}"
19+
target="_blank"
20+
rel="noopener noreferrer"
21+
class="text-blue-600 hover:text-blue-800 underline">{{ version }}</a>
22+
{% else %}
23+
<span>{{ version }}</span>
24+
{% endif %}
25+
</div>
1426
{# Right column - Discord #}
1527
<div class="flex justify-end">
1628
{{ footer_icon_link('https://discord.gg/zerRaGK9EC',

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /