Skip to content

Commit dd57e61

Browse files
committed
feat(web): add version info display
1 parent dcef8ef commit dd57e61

File tree

8 files changed

+112
-21
lines changed

8 files changed

+112
-21
lines changed

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,19 @@ jobs:
4747
echo "timestamp=$(date +%s)" >> $GITHUB_OUTPUT
4848
echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
4949
50+
- name: Determine version
51+
id: version
52+
run: |
53+
if [[ "${{ github.ref_type }}" == "tag" ]]; then
54+
# If we're on a tag, use the tag name as version
55+
echo "version=${{ github.ref_name }}" >> $GITHUB_OUTPUT
56+
else
57+
# If we're not on a tag, use branch-commit-hash format
58+
BRANCH_NAME="${{ github.ref_name }}"
59+
COMMIT_HASH="${{ steps.vars.outputs.sha_short }}"
60+
echo "version=${BRANCH_NAME}-${COMMIT_HASH}" >> $GITHUB_OUTPUT
61+
fi
62+
5063
- name: Login to Amazon ECR
5164
id: login-ecr
5265
uses: aws-actions/amazon-ecr-login@v2
@@ -78,5 +91,8 @@ jobs:
7891
push: ${{ github.event_name != 'pull_request' || env.PUSH_FROM_PR == 'true' }}
7992
tags: ${{ steps.meta.outputs.tags }}
8093
labels: ${{ steps.meta.outputs.labels }}
94+
build-args: |
95+
VERSION=${{ steps.version.outputs.version }}
96+
REPOSITORY_URL=https://github.com/${{ github.repository }}
8197
cache-from: type=gha
8298
cache-to: type=gha,mode=max

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,19 @@ jobs:
5151
echo "timestamp=$(date +%s)" >> $GITHUB_OUTPUT
5252
echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
5353
54+
- name: Determine version
55+
id: version
56+
run: |
57+
if [[ "${{ github.ref_type }}" == "tag" ]]; then
58+
# If we're on a tag, use the tag name as version
59+
echo "version=${{ github.ref_name }}" >> $GITHUB_OUTPUT
60+
else
61+
# If we're not on a tag, use branch-commit-hash format
62+
BRANCH_NAME="${{ github.ref_name }}"
63+
COMMIT_HASH="${{ steps.vars.outputs.sha_short }}"
64+
echo "version=${BRANCH_NAME}-${COMMIT_HASH}" >> $GITHUB_OUTPUT
65+
fi
66+
5467
- name: Log in to the Container registry
5568
uses: docker/login-action@74a5d142397b4f367a81961eba4e8cd7edddf772 # v3.4.0
5669
with:
@@ -87,6 +100,9 @@ jobs:
87100
push: ${{ github.event_name != 'pull_request' || env.PUSH_FROM_PR == 'true' }}
88101
tags: ${{ steps.meta.outputs.tags }}
89102
labels: ${{ steps.meta.outputs.labels }}
103+
build-args: |
104+
VERSION=${{ steps.version.outputs.version }}
105+
REPOSITORY_URL=https://github.com/${{ github.repository }}
90106
cache-from: type=gha
91107
cache-to: type=gha,mode=max
92108

Dockerfile

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

2121
ARG UID=1000
2222
ARG GID=1000
23+
ARG VERSION=unknown
24+
ARG REPOSITORY_URL=https://github.com/coderamp-labs/gitingest
2325

2426
ENV PYTHONUNBUFFERED=1 \
25-
PYTHONDONTWRITEBYTECODE=1
27+
PYTHONDONTWRITEBYTECODE=1 \
28+
VERSION=${VERSION} \
29+
REPOSITORY_URL=${REPOSITORY_URL}
2630

2731
RUN set -eux; \
2832
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-
return templates.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+
return templates.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-
return templates.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+
return templates.TemplateResponse("index.jinja", context)

src/server/server_config.py

Lines changed: 45 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,50 @@
2122
]
2223

2324

25+
# Version and repository configuration
26+
VERSION = os.getenv("VERSION", "unknown")
27+
REPOSITORY_URL = os.getenv("REPOSITORY_URL", "https://github.com/coderamp-labs/gitingest")
28+
29+
# Minimum number of parts expected in branch-commit format (e.g., "main-abc1234")
30+
MIN_BRANCH_COMMIT_PARTS = 2
31+
32+
33+
def get_version_info() -> dict[str, str]:
34+
"""Get version information including display version and link.
35+
36+
Returns
37+
-------
38+
dict[str, str]
39+
Dictionary containing 'version' and 'version_link' keys.
40+
41+
"""
42+
version = VERSION
43+
repo_url = REPOSITORY_URL.rstrip("/")
44+
45+
# Check if version looks like a tag (doesn't contain branch-commit pattern)
46+
if version != "unknown" and "-" in version and len(version.split("-")) >= MIN_BRANCH_COMMIT_PARTS:
47+
# This looks like branch-commit format (e.g., "main-abc1234")
48+
parts = version.split("-")
49+
if len(parts) >= MIN_BRANCH_COMMIT_PARTS:
50+
# Take the last part as commit hash
51+
commit_hash = parts[-1]
52+
version_link = f"{repo_url}/commit/{commit_hash}"
53+
else:
54+
# Fallback to main branch
55+
version_link = f"{repo_url}/tree/main"
56+
elif version != "unknown":
57+
# This looks like a tag version
58+
version_link = f"{repo_url}/releases/tag/{version}"
59+
else:
60+
# Unknown version, link to main branch
61+
version_link = f"{repo_url}/tree/main"
62+
63+
return {
64+
"version": version,
65+
"version_link": version_link,
66+
}
67+
68+
2469
# Use absolute path to templates directory
2570
templates_dir = Path(__file__).parent / "templates"
2671
templates = Jinja2Templates(directory=templates_dir)

src/server/templates/components/footer.jinja

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,13 @@
1818
'Discord') }}
1919
</div>
2020
</div>
21+
{# Version information row #}
22+
<div class="mt-2 text-center text-xs text-gray-600">
23+
<span>Version:</span>
24+
<a href="{{ version_link }}"
25+
target="_blank"
26+
rel="noopener noreferrer"
27+
class="text-blue-600 hover:text-blue-800 underline">{{ version }}</a>
28+
</div>
2129
</div>
2230
</footer>

0 commit comments

Comments
 (0)