Mirror of an open source Kubernetes-native API gateway for microservices built on the Envoy Proxy https://www.getambassador.io
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

VERSION-template.py 1.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. # Copyright 2018 Datawire. All rights reserved.
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License
  14. from typing import NamedTuple
  15. class GitInfo(NamedTuple):
  16. commit: str
  17. branch: str
  18. dirty: bool
  19. description: str
  20. class BuildInfo(NamedTuple):
  21. version: str
  22. git: GitInfo
  23. Version = "{{VERSION}}"
  24. Build = BuildInfo(
  25. version=Version,
  26. git=GitInfo(
  27. commit="{{GITCOMMIT}}",
  28. branch="{{GITBRANCH}}",
  29. dirty=bool("{{GITDIRTY}}"),
  30. description="{{GITDESCRIPTION}}",
  31. )
  32. )
  33. if __name__ == "__main__":
  34. import sys
  35. cmd = "--compact"
  36. if len(sys.argv) > 1:
  37. cmd = sys.argv[1].lower()
  38. if (cmd == '--version') or (cmd == '-V'):
  39. print(Version)
  40. elif cmd == '--desc':
  41. print(Build.git.description)
  42. elif cmd == '--branch':
  43. print(Build.git.branch)
  44. elif cmd == '--commit':
  45. print(Build.git.commit)
  46. elif cmd == '--dirty':
  47. print(Build.git.dirty)
  48. elif cmd == '--all':
  49. print("version: %s" % Version)
  50. print("git.branch: %s" % Build.git.branch)
  51. print("git.commit: %s" % Build.git.commit)
  52. print("git.dirty: %s" % Build.git.dirty)
  53. print("git.description: %s" % Build.git.description)
  54. else: # compact
  55. print("%s (%s at %s on %s%s)" %
  56. (Version, Build.git.description, Build.git.commit, Build.git.branch,
  57. " - dirty" if Build.git.dirty else ""))