Skip to content

feat(web): add version info display #483

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions .github/workflows/docker-build.ecr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}

- name: configure aws credentials
uses: aws-actions/configure-aws-credentials@v4
Expand All @@ -46,6 +48,32 @@ jobs:
run: |
echo "timestamp=$(date +%s)" >> $GITHUB_OUTPUT
echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
echo "sha_full=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT

- name: Determine version and deployment context
id: version
run: |
REPO_URL="https://github.com/${{ github.repository }}"

if [[ "${{ github.ref_type }}" == "tag" ]]; then
# Tag deployment - display version, link to release
echo "version=${{ github.ref_name }}" >> $GITHUB_OUTPUT
echo "app_version=${{ github.ref_name }}" >> $GITHUB_OUTPUT
echo "app_version_url=${REPO_URL}/releases/tag/${{ github.ref_name }}" >> $GITHUB_OUTPUT
elif [[ "${{ github.event_name }}" == "pull_request" ]]; then
# PR deployment - display pr-XXX, link to PR commit
PR_NUMBER="${{ github.event.pull_request.number }}"
COMMIT_HASH="${{ steps.vars.outputs.sha_full }}"
echo "version=${PR_NUMBER}/merge-${COMMIT_HASH}" >> $GITHUB_OUTPUT
echo "app_version=pr-${PR_NUMBER}" >> $GITHUB_OUTPUT
echo "app_version_url=${REPO_URL}/pull/${PR_NUMBER}/commits/${COMMIT_HASH}" >> $GITHUB_OUTPUT
else
# Branch deployment - display branch name, link to commit
BRANCH_NAME="${{ github.ref_name }}"
COMMIT_HASH="${{ steps.vars.outputs.sha_full }}"
echo "app_version=${BRANCH_NAME}" >> $GITHUB_OUTPUT
echo "app_version_url=${REPO_URL}/commit/${COMMIT_HASH}" >> $GITHUB_OUTPUT
fi

- name: Login to Amazon ECR
id: login-ecr
Expand Down Expand Up @@ -78,5 +106,9 @@ jobs:
push: ${{ github.event_name != 'pull_request' || env.PUSH_FROM_PR == 'true' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: |
APP_REPOSITORY=https://github.com/${{ github.repository }}
APP_VERSION=${{ steps.version.outputs.app_version }}
APP_VERSION_URL=${{ steps.version.outputs.app_version_url }}
cache-from: type=gha
cache-to: type=gha,mode=max
32 changes: 32 additions & 0 deletions .github/workflows/docker-build.ghcr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,40 @@ jobs:
egress-policy: audit

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

- name: Set current timestamp
id: vars
run: |
echo "timestamp=$(date +%s)" >> $GITHUB_OUTPUT
echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
echo "sha_full=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT

- name: Determine version and deployment context
id: version
run: |
REPO_URL="https://github.com/${{ github.repository }}"

if [[ "${{ github.ref_type }}" == "tag" ]]; then
# Tag deployment - display version, link to release
echo "version=${{ github.ref_name }}" >> $GITHUB_OUTPUT
echo "app_version=${{ github.ref_name }}" >> $GITHUB_OUTPUT
echo "app_version_url=${REPO_URL}/releases/tag/${{ github.ref_name }}" >> $GITHUB_OUTPUT
elif [[ "${{ github.event_name }}" == "pull_request" ]]; then
# PR deployment - display pr-XXX, link to PR commit
PR_NUMBER="${{ github.event.pull_request.number }}"
COMMIT_HASH="${{ steps.vars.outputs.sha_full }}"
echo "version=${PR_NUMBER}/merge-${COMMIT_HASH}" >> $GITHUB_OUTPUT
echo "app_version=pr-${PR_NUMBER}" >> $GITHUB_OUTPUT
echo "app_version_url=${REPO_URL}/pull/${PR_NUMBER}/commits/${COMMIT_HASH}" >> $GITHUB_OUTPUT
else
# Branch deployment - display branch name, link to commit
BRANCH_NAME="${{ github.ref_name }}"
COMMIT_HASH="${{ steps.vars.outputs.sha_full }}"
echo "app_version=${BRANCH_NAME}" >> $GITHUB_OUTPUT
echo "app_version_url=${REPO_URL}/commit/${COMMIT_HASH}" >> $GITHUB_OUTPUT
fi

- name: Log in to the Container registry
uses: docker/login-action@74a5d142397b4f367a81961eba4e8cd7edddf772 # v3.4.0
Expand Down Expand Up @@ -87,6 +115,10 @@ jobs:
push: ${{ github.event_name != 'pull_request' || env.PUSH_FROM_PR == 'true' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: |
APP_REPOSITORY=https://github.com/${{ github.repository }}
APP_VERSION=${{ steps.version.outputs.app_version }}
APP_VERSION_URL=${{ steps.version.outputs.app_version_url }}
cache-from: type=gha
cache-to: type=gha,mode=max

Expand Down
8 changes: 7 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,15 @@ FROM python:3.13.5-slim@sha256:4c2cf9917bd1cbacc5e9b07320025bdb7cdf2df7b0ceaccb5

ARG UID=1000
ARG GID=1000
ARG APP_REPOSITORY=https://github.com/coderamp-labs/gitingest
ARG APP_VERSION=unknown
ARG APP_VERSION_URL=https://github.com/coderamp-labs/gitingest

ENV PYTHONUNBUFFERED=1 \
PYTHONDONTWRITEBYTECODE=1
PYTHONDONTWRITEBYTECODE=1 \
APP_REPOSITORY=${APP_REPOSITORY} \
APP_VERSION=${APP_VERSION} \
APP_VERSION_URL=${APP_VERSION_URL}

RUN set -eux; \
apt-get update; \
Expand Down
6 changes: 4 additions & 2 deletions src/server/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from gitingest.utils.logging_config import get_logger
from server.metrics_server import start_metrics_server
from server.routers import dynamic, index, ingest
from server.server_config import templates
from server.server_config import get_version_info, templates
from server.server_utils import limiter, rate_limit_exception_handler

# Load environment variables from .env file
Expand Down Expand Up @@ -169,7 +169,9 @@ async def custom_swagger_ui(request: Request) -> HTMLResponse:
- **HTMLResponse**: Custom Swagger UI documentation page

"""
return templates.TemplateResponse("swagger_ui.jinja", {"request": request})
context = {"request": request}
context.update(get_version_info())
return templates.TemplateResponse("swagger_ui.jinja", context)


@app.get("/api", include_in_schema=True)
Expand Down
18 changes: 9 additions & 9 deletions src/server/routers/dynamic.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from fastapi import APIRouter, Request
from fastapi.responses import HTMLResponse

from server.server_config import templates
from server.server_config import get_version_info, templates

router = APIRouter()

Expand All @@ -29,11 +29,11 @@ async def catch_all(request: Request, full_path: str) -> HTMLResponse:
and other default parameters such as file size.

"""
return templates.TemplateResponse(
"git.jinja",
{
"request": request,
"repo_url": full_path,
"default_max_file_size": 243,
},
)
context = {
"request": request,
"repo_url": full_path,
"default_max_file_size": 243,
}
context.update(get_version_info())

return templates.TemplateResponse("git.jinja", context)
18 changes: 9 additions & 9 deletions src/server/routers/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from fastapi import APIRouter, Request
from fastapi.responses import HTMLResponse

from server.server_config import EXAMPLE_REPOS, templates
from server.server_config import EXAMPLE_REPOS, get_version_info, templates

router = APIRouter()

Expand All @@ -27,11 +27,11 @@ async def home(request: Request) -> HTMLResponse:
and other default parameters such as file size.

"""
return templates.TemplateResponse(
"index.jinja",
{
"request": request,
"examples": EXAMPLE_REPOS,
"default_max_file_size": 243,
},
)
context = {
"request": request,
"examples": EXAMPLE_REPOS,
"default_max_file_size": 243,
}
context.update(get_version_info())

return templates.TemplateResponse("index.jinja", context)
30 changes: 30 additions & 0 deletions src/server/server_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from __future__ import annotations

import os
from pathlib import Path

from fastapi.templating import Jinja2Templates
Expand All @@ -21,6 +22,35 @@
]


# Version and repository configuration
APP_REPOSITORY = os.getenv("APP_REPOSITORY", "https://github.com/coderamp-labs/gitingest")
APP_VERSION = os.getenv("APP_VERSION", "unknown")
APP_VERSION_URL = os.getenv("APP_VERSION_URL", "https://github.com/coderamp-labs/gitingest")


def get_version_info() -> dict[str, str]:
"""Get version information including display version and link.

Returns
-------
dict[str, str]
Dictionary containing 'version' and 'version_link' keys.

"""
# Use pre-computed values from GitHub Actions
display_version = APP_VERSION
version_link = APP_VERSION_URL

# Fallback to repository root if no URL is provided
if version_link == APP_REPOSITORY or not version_link:
version_link = f"{APP_REPOSITORY.rstrip('/')}/tree/main"

return {
"version": display_version,
"version_link": version_link,
}


# Use absolute path to templates directory
templates_dir = Path(__file__).parent / "templates"
templates = Jinja2Templates(directory=templates_dir)
14 changes: 13 additions & 1 deletion src/server/templates/components/footer.jinja
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{% from 'components/_macros.jinja' import footer_icon_link %}
<footer class="w-full border-t-[3px] border-gray-900 mt-auto">
<div class="max-w-4xl mx-auto px-4 py-4">
<div class="grid grid-cols-2 items-center text-gray-900 text-sm">
<div class="grid grid-cols-3 items-center text-gray-900 text-sm">
{# Left column — Chrome + PyPI #}
<div class="flex items-center space-x-4">
{{ footer_icon_link('https://chromewebstore.google.com/detail/adfjahbijlkjfoicpjkhjicpjpjfaood',
Expand All @@ -11,6 +11,18 @@
'icons/python.svg',
'Python Package') }}
</div>
{# Middle column - Version information #}
<div class="flex justify-center">
<span>Version:&nbsp;</span>
{% if version != "unknown" %}
<a href="{{ version_link }}"
target="_blank"
rel="noopener noreferrer"
class="text-blue-600 hover:text-blue-800 underline">{{ version }}</a>
{% else %}
<span>{{ version }}</span>
{% endif %}
</div>
{# Right column - Discord #}
<div class="flex justify-end">
{{ footer_icon_link('https://discord.gg/zerRaGK9EC',
Expand Down
Loading