From 841df99d61cd654db5783b94c232f801002deece Mon Sep 17 00:00:00 2001 From: Manuel Cortez Date: Sat, 18 Jul 2020 01:52:41 -0500 Subject: [PATCH] Write new alpha version info on every build --- .gitlab-ci.yml | 1 + src/write_version_data.py | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) create mode 100644 src/write_version_data.py diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index a5bfb23..4bcbbc0 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -39,6 +39,7 @@ public: stage: build script: - cd src + - 'python write_version_data.py' - 'python setup.py build' - '&$env:NSIS installer.nsi' - cd .. diff --git a/src/write_version_data.py b/src/write_version_data.py new file mode 100644 index 0000000..ff0742e --- /dev/null +++ b/src/write_version_data.py @@ -0,0 +1,19 @@ +#! /usr/bin/env python# -*- coding: iso-8859-1 -*- +""" Write version info (taken from the last commit) to application.py. This method has been implemented this way for running the alpha channel updates. +This file is not intended to be called by the user. It will be used only by the Gitlab CI runner.""" +import requests +from codecs import open + +print("Writing version data for alpha update...") +commit_info = requests.get("https://code.manuelcortez.net/api/v4/projects/5/repository/commits/master") +commit_info = commit_info.json() +commit = commit_info["short_id"] +print("Got new version info: {commit}".format(commit=commit,)) +file = open("application.py", "r", encoding="utf-8") +lines = file.readlines() +lines[-1] = 'update_next_version = "{commit}"'.format(commit=commit,) +file.close() +file2 = open("application.py", "w", encoding="utf-8") +file2.writelines(lines) +file2.close() +print("Wrote application.py with the new version info.") \ No newline at end of file