[FL-3361] fbt: stable build dates (#2751)

* scripts: using commit date for clean build timestamp; current day otherwise
* scripts: version: Removing GIT_COMMIT_DATE from final data

Co-authored-by: あく <alleteam@gmail.com>
This commit is contained in:
hedger 2023-06-09 16:27:47 +04:00 committed by GitHub
parent 49d842e213
commit 2312fe5bfc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -40,12 +40,23 @@ class GitVersion:
except subprocess.CalledProcessError: except subprocess.CalledProcessError:
version = "unknown" version = "unknown"
if "SOURCE_DATE_EPOCH" in os.environ:
commit_date = datetime.utcfromtimestamp(
int(os.environ["SOURCE_DATE_EPOCH"])
)
else:
commit_date = datetime.strptime(
self._exec_git("log -1 --format=%cd").strip(),
"%a %b %d %H:%M:%S %Y %z",
)
return { return {
"GIT_COMMIT": commit, "GIT_COMMIT": commit,
"GIT_BRANCH": branch, "GIT_BRANCH": branch,
"VERSION": version, "VERSION": version,
"BUILD_DIRTY": dirty and 1 or 0, "BUILD_DIRTY": dirty and 1 or 0,
"GIT_ORIGIN": ",".join(self._get_git_origins()), "GIT_ORIGIN": ",".join(self._get_git_origins()),
"GIT_COMMIT_DATE": commit_date,
} }
def _get_git_origins(self): def _get_git_origins(self):
@ -102,10 +113,11 @@ class Main(App):
def generate(self): def generate(self):
current_info = GitVersion(self.args.sourcedir).get_version_info() current_info = GitVersion(self.args.sourcedir).get_version_info()
if "SOURCE_DATE_EPOCH" in os.environ: build_date = (
build_date = datetime.utcfromtimestamp(int(os.environ["SOURCE_DATE_EPOCH"])) date.today()
else: if current_info["BUILD_DIRTY"]
build_date = date.today() else current_info["GIT_COMMIT_DATE"]
)
current_info.update( current_info.update(
{ {
@ -115,6 +127,8 @@ class Main(App):
} }
) )
del current_info["GIT_COMMIT_DATE"]
version_values = [] version_values = []
for key in current_info: for key in current_info:
val = current_info[key] val = current_info[key]