Files
shaka-packager/packager/version/generate_version_string.py
Joey Parrish d83c7b1d45 fix: Fix tags in official Docker images and binaries (#1370)
The release workflows did not run checkout with `fetch-tags: true`, so
the builds were unable to compute the correct release version number. I
audited all instances of `actions/checkout` to add `fetch-tags` where
needed and clean up unneeded options.

I also had to fix options to `docker/build-push-action`, which by
default ignores `actions/checkout` and tries to pull from git itself.
This led to the Docker build running in a context without the new tag.

Finally, to make verification easier and provide version info in the
build logs, this adds debugging info to the version-generation script
via stderr.

Closes #1366
2024-03-12 13:09:38 -07:00

45 lines
1.5 KiB
Python
Executable File

#!/usr/bin/python3
#
# Copyright 2015 Google LLC. All rights reserved.
#
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file or at
# https://developers.google.com/open-source/licenses/bsd
"""This script is used to generate version string for packager."""
import subprocess
import sys
if __name__ == '__main__':
try:
version_tag = subprocess.check_output('git tag --points-at HEAD',
stderr=subprocess.STDOUT, shell=True).decode().rstrip()
if version_tag:
print('Found version tag: {}'.format(version_tag), file=sys.stderr)
else:
print('Cannot find version tag!', file=sys.stderr)
except subprocess.CalledProcessError as e:
# git tag --points-at is not supported in old versions of git. Just ignore
# version_tag in this case.
version_tag = None
print('Old version of git, cannot determine version tag!', file=sys.stderr)
try:
version_hash = subprocess.check_output('git rev-parse --short HEAD',
stderr=subprocess.STDOUT, shell=True).decode().rstrip()
print('Version hash: {}'.format(version_hash), file=sys.stderr)
except subprocess.CalledProcessError as e:
version_hash = 'unknown-version'
print('Cannot find version hasah!', file=sys.stderr)
if version_tag:
output = '{0}-{1}'.format(version_tag, version_hash)
else:
output = version_hash
# Final debug message, mirroring what is used to generate the source file:
print('Final output: {}'.format(output), file=sys.stderr)
# Actually used to generate the source file:
print(output)