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 73aa195

Browse files
MickaelCaNicolasIRAGNE
authored andcommitted
refactor(server,ci): simplify version and repository handling
1 parent 04776ae commit 73aa195

File tree

4 files changed

+64
-75
lines changed

4 files changed

+64
-75
lines changed

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

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,18 +46,35 @@ jobs:
4646
run: |
4747
echo "timestamp=$(date +%s)" >> $GITHUB_OUTPUT
4848
echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
49+
echo "sha_full=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT
4950
50-
- name: Determine version
51+
- name: Determine version and deployment context
5152
id: version
5253
run: |
54+
REPO_URL="https://github.com/${{ github.repository }}"
55+
5356
if [[ "${{ github.ref_type }}" == "tag" ]]; then
54-
# If we're on a tag, use the tag name as version
57+
# Tag deployment - display version, link to release
5558
echo "version=${{ github.ref_name }}" >> $GITHUB_OUTPUT
59+
echo "deployment_type=tag" >> $GITHUB_OUTPUT
60+
echo "app_version=${{ github.ref_name }}" >> $GITHUB_OUTPUT
61+
echo "app_version_url=${REPO_URL}/releases/tag/${{ github.ref_name }}" >> $GITHUB_OUTPUT
62+
elif [[ "${{ github.event_name }}" == "pull_request" ]]; then
63+
# PR deployment - display pr-XXX, link to PR commit
64+
PR_NUMBER="${{ github.event.pull_request.number }}"
65+
COMMIT_HASH="${{ steps.vars.outputs.sha_full }}"
66+
echo "version=${PR_NUMBER}/merge-${COMMIT_HASH}" >> $GITHUB_OUTPUT
67+
echo "deployment_type=pr" >> $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
5670
else
57-
# If we're not on a tag, use branch-commit-hash format
71+
# Branch deployment - display branch name, link to commit
5872
BRANCH_NAME="${{ github.ref_name }}"
59-
COMMIT_HASH="${{ steps.vars.outputs.sha_short }}"
73+
COMMIT_HASH="${{ steps.vars.outputs.sha_full }}"
6074
echo "version=${BRANCH_NAME}-${COMMIT_HASH}" >> $GITHUB_OUTPUT
75+
echo "deployment_type=branch" >> $GITHUB_OUTPUT
76+
echo "app_version=${BRANCH_NAME}" >> $GITHUB_OUTPUT
77+
echo "app_version_url=${REPO_URL}/commit/${COMMIT_HASH}" >> $GITHUB_OUTPUT
6178
fi
6279
6380
- name: Login to Amazon ECR
@@ -93,6 +110,8 @@ jobs:
93110
labels: ${{ steps.meta.outputs.labels }}
94111
build-args: |
95112
VERSION=${{ steps.version.outputs.version }}
96-
REPOSITORY_URL=https://github.com/${{ github.repository }}
113+
APP_REPOSITORY=https://github.com/${{ github.repository }}
114+
APP_VERSION=${{ steps.version.outputs.app_version }}
115+
APP_VERSION_URL=${{ steps.version.outputs.app_version_url }}
97116
cache-from: type=gha
98117
cache-to: type=gha,mode=max

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

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,18 +50,35 @@ jobs:
5050
run: |
5151
echo "timestamp=$(date +%s)" >> $GITHUB_OUTPUT
5252
echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
53+
echo "sha_full=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT
5354
54-
- name: Determine version
55+
- name: Determine version and deployment context
5556
id: version
5657
run: |
58+
REPO_URL="https://github.com/${{ github.repository }}"
59+
5760
if [[ "${{ github.ref_type }}" == "tag" ]]; then
58-
# If we're on a tag, use the tag name as version
61+
# Tag deployment - display version, link to release
5962
echo "version=${{ github.ref_name }}" >> $GITHUB_OUTPUT
63+
echo "deployment_type=tag" >> $GITHUB_OUTPUT
64+
echo "app_version=${{ github.ref_name }}" >> $GITHUB_OUTPUT
65+
echo "app_version_url=${REPO_URL}/releases/tag/${{ github.ref_name }}" >> $GITHUB_OUTPUT
66+
elif [[ "${{ github.event_name }}" == "pull_request" ]]; then
67+
# PR deployment - display pr-XXX, link to PR commit
68+
PR_NUMBER="${{ github.event.pull_request.number }}"
69+
COMMIT_HASH="${{ steps.vars.outputs.sha_full }}"
70+
echo "version=${PR_NUMBER}/merge-${COMMIT_HASH}" >> $GITHUB_OUTPUT
71+
echo "deployment_type=pr" >> $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
6074
else
61-
# If we're not on a tag, use branch-commit-hash format
75+
# Branch deployment - display branch name, link to commit
6276
BRANCH_NAME="${{ github.ref_name }}"
63-
COMMIT_HASH="${{ steps.vars.outputs.sha_short }}"
77+
COMMIT_HASH="${{ steps.vars.outputs.sha_full }}"
6478
echo "version=${BRANCH_NAME}-${COMMIT_HASH}" >> $GITHUB_OUTPUT
79+
echo "deployment_type=branch" >> $GITHUB_OUTPUT
80+
echo "app_version=${BRANCH_NAME}" >> $GITHUB_OUTPUT
81+
echo "app_version_url=${REPO_URL}/commit/${COMMIT_HASH}" >> $GITHUB_OUTPUT
6582
fi
6683
6784
- name: Log in to the Container registry
@@ -102,7 +119,9 @@ jobs:
102119
labels: ${{ steps.meta.outputs.labels }}
103120
build-args: |
104121
VERSION=${{ steps.version.outputs.version }}
105-
REPOSITORY_URL=https://github.com/${{ github.repository }}
122+
APP_REPOSITORY=https://github.com/${{ github.repository }}
123+
APP_VERSION=${{ steps.version.outputs.app_version }}
124+
APP_VERSION_URL=${{ steps.version.outputs.app_version_url }}
106125
cache-from: type=gha
107126
cache-to: type=gha,mode=max
108127

‎Dockerfile

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,16 @@ FROM python:3.13.5-slim@sha256:4c2cf9917bd1cbacc5e9b07320025bdb7cdf2df7b0ceaccb5
2121
ARG UID=1000
2222
ARG GID=1000
2323
ARG VERSION=unknown
24-
ARG REPOSITORY_URL=https://github.com/coderamp-labs/gitingest
24+
ARG APP_REPOSITORY=https://github.com/coderamp-labs/gitingest
25+
ARG APP_VERSION=unknown
26+
ARG APP_VERSION_URL=https://github.com/coderamp-labs/gitingest
2527

2628
ENV PYTHONUNBUFFERED=1 \
2729
PYTHONDONTWRITEBYTECODE=1 \
2830
VERSION=${VERSION} \
29-
REPOSITORY_URL=${REPOSITORY_URL}
31+
APP_REPOSITORY=${APP_REPOSITORY} \
32+
APP_VERSION=${APP_VERSION} \
33+
APP_VERSION_URL=${APP_VERSION_URL}
3034

3135
RUN set -eux; \
3236
apt-get update; \

‎src/server/server_config.py

Lines changed: 10 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,9 @@
2424

2525
# Version and repository configuration
2626
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-
# Minimum length for a git commit hash
33-
MIN_COMMIT_HASH_LENGTH = 6
34-
35-
# Minimum number of parts in PR format to include commit hash (pr-number-commit)
36-
MIN_PR_PARTS_WITH_COMMIT = 2
27+
APP_REPOSITORY = os.getenv("APP_REPOSITORY", "https://github.com/coderamp-labs/gitingest")
28+
APP_VERSION = os.getenv("APP_VERSION", "unknown")
29+
APP_VERSION_URL = os.getenv("APP_VERSION_URL", "https://github.com/coderamp-labs/gitingest")
3730

3831

3932
def get_version_info() -> dict[str, str]:
@@ -45,59 +38,13 @@ def get_version_info() -> dict[str, str]:
4538
Dictionary containing 'version' and 'version_link' keys.
4639
4740
"""
48-
version = VERSION
49-
repo_url = REPOSITORY_URL.rstrip("/")
50-
display_version = version
51-
version_link = f"{repo_url}/tree/main" # Default fallback
52-
53-
def _looks_like_commit_hash(text: str) -> bool:
54-
"""Check if text looks like a git commit hash (alphanumeric, 6+ chars)."""
55-
return len(text) >= MIN_COMMIT_HASH_LENGTH and text.isalnum() and any(c.isalpha() for c in text)
56-
57-
# Check if version contains dashes
58-
if version != "unknown" and ("-" in version):
59-
parts = version.split("-")
60-
if len(parts) >= MIN_BRANCH_COMMIT_PARTS:
61-
# Check if first part indicates a PR
62-
if parts[0].lower() in ("pr", "pull"):
63-
# Extract PR number and commit hash from the parts
64-
try:
65-
pr_number = int(parts[1])
66-
display_version = f"pr-{pr_number}"
67-
# If there's a commit hash after the PR number, link to the commit in the PR
68-
if len(parts) > MIN_PR_PARTS_WITH_COMMIT:
69-
commit_hash = parts[-1]
70-
version_link = f"{repo_url}/pull/{pr_number}/commits/{commit_hash}"
71-
else:
72-
# No commit hash, link to the PR page
73-
version_link = f"{repo_url}/pull/{pr_number}"
74-
except (ValueError, IndexError):
75-
# If PR number is invalid, fallback to main branch
76-
display_version = version
77-
version_link = f"{repo_url}/tree/main"
78-
elif _looks_like_commit_hash(parts[-1]):
79-
# This looks like branch-commit format (e.g., "main-abc1234")
80-
# Display only the branch name, link to the commit
81-
branch_name = parts[0]
82-
commit_hash = parts[-1]
83-
display_version = branch_name
84-
version_link = f"{repo_url}/commit/{commit_hash}"
85-
else:
86-
# This looks like a tag version with dashes (e.g., "release-2.1.0")
87-
display_version = version
88-
version_link = f"{repo_url}/releases/tag/{version}"
89-
else:
90-
# Fallback to main branch
91-
display_version = version
92-
version_link = f"{repo_url}/tree/main"
93-
elif version != "unknown":
94-
# This looks like a tag version
95-
display_version = version
96-
version_link = f"{repo_url}/releases/tag/{version}"
97-
else:
98-
# Unknown version, link to main branch
99-
display_version = "unknown"
100-
version_link = f"{repo_url}/tree/main"
41+
# Use pre-computed values from GitHub Actions
42+
display_version = APP_VERSION
43+
version_link = APP_VERSION_URL
44+
45+
# Fallback to repository root if no URL is provided
46+
if version_link == APP_REPOSITORY or not version_link:
47+
version_link = f"{APP_REPOSITORY.rstrip('/')}/tree/main"
10148

10249
return {
10350
"version": display_version,

0 commit comments

Comments
(0)

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