Skip to content

Commit c3792dc

Browse files
committed
Obtain git information from version file
1 parent 6b36651 commit c3792dc

File tree

4 files changed

+29
-7
lines changed

4 files changed

+29
-7
lines changed

.dockerignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@ static/upload
1313
venv/
1414
.venv
1515
.coverage
16-
htmlcov
16+
htmlcov
17+
.git/

.github/workflows/main.yml

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,16 +114,21 @@ jobs:
114114
username: ${{ secrets.DOCKER_USERNAME }}
115115
password: ${{ secrets.DOCKER_PASSWORD }}
116116

117+
# We need to checkout the repository in order for the "Create Sentry release" to work
118+
- name: Checkout repository
119+
uses: actions/checkout@v2
120+
121+
- name: Prepare version file
122+
run: |
123+
echo "${{ github.ref }}" > .version
124+
117125
- name: Build image and publish to Docker Registry
118126
uses: docker/build-push-action@v3
119127
with:
128+
context: .
120129
push: true
121130
tags: ${{ steps.meta.outputs.tags }}
122131

123-
# We need to checkout the repository in order for the "Create Sentry release" to work
124-
- name: Checkout repository
125-
uses: actions/checkout@v2
126-
127132
- name: Create Sentry release
128133
uses: getsentry/action-release@v1
129134
env:

.version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
dev

app/config.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,29 @@
22
import random
33
import socket
44
import string
5-
import subprocess
65
from ast import literal_eval
6+
from pathlib import Path
77
from typing import Callable, List
88
from urllib.parse import urlparse
99

1010
from dotenv import load_dotenv
1111

12-
SHA1 = subprocess.getoutput("git rev-parse HEAD")
12+
DEFAULT_VERSION = "unknown"
13+
14+
15+
def load_version() -> str:
16+
try:
17+
this_file_path = Path(__file__)
18+
root_dir_path = this_file_path.parent.parent
19+
version_file_path = root_dir_path.joinpath(".version")
20+
with open(version_file_path, "r") as f:
21+
return f.readline().strip()
22+
except Exception:
23+
print("Could not load .version. Using default version")
24+
return DEFAULT_VERSION
25+
26+
27+
SHA1 = load_version()
1328
ROOT_DIR = os.path.abspath(os.path.dirname(os.path.dirname(__file__)))
1429

1530

0 commit comments

Comments
 (0)