Skip to content

Commit 1f46a1d

Browse files
committed
Add endpoint to show app version info via API and GUI.
Update the CI/CD pipeline to automatically place version information in the version.yml file prior to packaging the app. That way the app knows what version it is based on the tag.
1 parent 02359e8 commit 1f46a1d

File tree

7 files changed

+98
-7
lines changed

7 files changed

+98
-7
lines changed

.github/workflows/main-branch-after-merge-actions.yml

+10-6
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,16 @@ jobs:
4848
coverage run -m pytest
4949
coverage report --fail-under 40
5050
51+
- name: Bump version and push tag
52+
id: tag_version
53+
uses: mathieudutour/github-tag-action@v6.1
54+
with:
55+
github_token: ${{ secrets.GITHUB_TOKEN }}
56+
57+
- name: Update Package Version
58+
run: |
59+
python version.py -v ${{ steps.tag_version.outputs.new_tag }}
60+
5161
- name: Run PyInstaller
5262
run: |
5363
python package.py
@@ -56,12 +66,6 @@ jobs:
5666
run: |
5767
python checksum.py
5868
59-
- name: Bump version and push tag
60-
id: tag_version
61-
uses: mathieudutour/github-tag-action@v6.1
62-
with:
63-
github_token: ${{ secrets.GITHUB_TOKEN }}
64-
6569
- name: Create a GitHub release
6670
uses: ncipollo/release-action@v1
6771
with:

application/api/v1/blueprints/app.py

+13-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
import os
12
import threading
23
import sqlalchemy.exc as exc
4+
import yaml
35

4-
from flask import Blueprint, jsonify, request
6+
from flask import Blueprint, jsonify, request, current_app
57
from flask.views import MethodView
68

79
from application.api.controllers import app as app_controller
@@ -14,6 +16,16 @@
1416
app = Blueprint("app", __name__, url_prefix="/v1")
1517

1618

19+
@app.route("/version", methods=["GET"])
20+
def get_version():
21+
version_file = os.path.join(current_app.static_folder, "version.yml")
22+
23+
with open(version_file, "r") as file:
24+
version_data = yaml.safe_load(file)
25+
26+
return jsonify(version_data)
27+
28+
1729
@app.route("/thread/status/<int:ident>", methods=["GET"])
1830
def is_thread_alive(ident: int):
1931
logger.debug("Checking thread!")
+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
from PyQt5.QtWidgets import (
2+
QWidget,
3+
QLabel,
4+
QVBoxLayout,
5+
)
6+
7+
from application.common.decorators import timeit
8+
from operator_client import Operator
9+
10+
11+
class AboutWidget(QWidget):
12+
@timeit
13+
def __init__(
14+
self,
15+
client: Operator,
16+
parent: QWidget = None,
17+
):
18+
super(QWidget, self).__init__(parent)
19+
self._layout = QVBoxLayout()
20+
self._client = client
21+
self._initialized = False
22+
23+
self.init_ui()
24+
25+
def init_ui(self):
26+
v_layout = QVBoxLayout()
27+
28+
version = self._client.app.get_app_version()
29+
q_label = QLabel(f"Software Version: {version}")
30+
v_layout.addWidget(q_label)
31+
32+
self._layout.addLayout(v_layout)
33+
34+
self.setFocus()
35+
self.setLayout(self._layout)
36+
self.show()

application/gui/widgets/settings_widget.py

+9
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from application.common import constants, logger
1212
from application.common.decorators import timeit
1313
from application.gui.globals import GuiGlobals
14+
from application.gui.widgets.about_widget import AboutWidget
1415
from application.gui.widgets.file_select_widget import FileSelectWidget
1516
from application.gui.widgets.nginx_widget import NginxWidget
1617
from application.gui.widgets.tokens_widget import TokensWidget
@@ -27,6 +28,8 @@ def __init__(self, client: Operator, globals: GuiGlobals, parent: QWidget = None
2728
self._globals = globals
2829
self._initialized = False
2930

31+
self._about_widget = AboutWidget(self._client, self)
32+
3033
self._token_widget = TokensWidget(
3134
self._client,
3235
self._globals._global_clipboard,
@@ -65,6 +68,7 @@ def init_ui(self):
6568
self.tab1 = QWidget()
6669
self.tab2 = QWidget()
6770
self.tab3 = QWidget()
71+
self.tab4 = QWidget()
6872

6973
tab1_layout = QVBoxLayout()
7074
tab1_layout.addLayout(self._create_steam_path_setting(steam_install_dir))
@@ -85,9 +89,14 @@ def init_ui(self):
8589
tab3_layout.addWidget(self._nginx_widget)
8690
self.tab3.setLayout(tab3_layout)
8791

92+
tab4_layout = QVBoxLayout()
93+
tab4_layout.addWidget(self._about_widget)
94+
self.tab4.setLayout(tab4_layout)
95+
8896
self.tabs.addTab(self.tab1, "Paths")
8997
self.tabs.addTab(self.tab2, "Tokens")
9098
self.tabs.addTab(self.tab3, "Nginx")
99+
self.tabs.addTab(self.tab4, "About")
91100

92101
self._layout.addWidget(self.tabs)
93102

application/static/version.yml

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
version: 0.0.0

requirements.txt

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ pyjwt
1111
pyopenssl
1212
pyqt5
1313
python-dotenv
14+
pyyaml
1415
requests
1516
validators==0.20.0
1617
vdf==3.4

version.py

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import argparse
2+
import os
3+
import yaml
4+
5+
6+
def set_version(new_version: str):
7+
version_file = os.path.join("application", "static", "version.yml")
8+
9+
with open(version_file, "r") as ver_file:
10+
version_data = yaml.safe_load(ver_file)
11+
ver_file.close()
12+
13+
with open(version_file, "w") as ver_file:
14+
version_data["version"] = new_version
15+
yaml.dump(version_data, ver_file)
16+
ver_file.close()
17+
18+
19+
if __name__ == "__main__":
20+
parser = argparse.ArgumentParser()
21+
parser.add_argument("-v", "--version", type=str, help="New Version String")
22+
args = parser.parse_args()
23+
24+
if args.version is None:
25+
print("Error: Missing Argument! Try again.")
26+
else:
27+
print(f"Version String: {args.version}")
28+
set_version(args.version)

0 commit comments

Comments
 (0)