Use python version file

This commit is contained in:
Carlos Quintana 2022-05-12 16:21:36 +02:00
parent c3792dc333
commit 9959848d74
No known key found for this signature in database
GPG key ID: 15E73DCC410679F8
3 changed files with 9 additions and 17 deletions

View file

@ -120,7 +120,11 @@ jobs:
- name: Prepare version file
run: |
echo "${{ github.ref }}" > .version
BUILD_INFO_FILE=app/build_info.py
echo "SHA1 = '${{ github.ref }}'" > $BUILD_INFO_FILE
BUILD_TIME=$(date +%s)
echo "BUILD_TIME = '${BUILD_TIME}' >> $BUILD_INFO_FILE
cat $BUILD_INFO_FILE
- name: Build image and publish to Docker Registry
uses: docker/build-push-action@v3

2
app/build_info.py Normal file
View file

@ -0,0 +1,2 @@
SHA1 = "dev"
BUILD_TIME = "1652365083"

View file

@ -2,29 +2,15 @@ import os
import random
import socket
import string
from app import build_info
from ast import literal_eval
from pathlib import Path
from typing import Callable, List
from urllib.parse import urlparse
from dotenv import load_dotenv
DEFAULT_VERSION = "unknown"
def load_version() -> str:
try:
this_file_path = Path(__file__)
root_dir_path = this_file_path.parent.parent
version_file_path = root_dir_path.joinpath(".version")
with open(version_file_path, "r") as f:
return f.readline().strip()
except Exception:
print("Could not load .version. Using default version")
return DEFAULT_VERSION
SHA1 = load_version()
SHA1 = build_info.SHA1
ROOT_DIR = os.path.abspath(os.path.dirname(os.path.dirname(__file__)))