|
| 1 | +# This script produces SOURCE_VERSION file with content from current version commit hash. As a |
| 2 | +# reminder,SOURCE_VERSION is required when building Envoy from an extracted release tarball |
| 3 | +# (non-git). See: bazel/get_workspace_status for more information. |
| 4 | +# |
| 5 | +# The SOURCE_VERSION file is produced by reading current version tag from VERSION.txt file then |
| 6 | +# fetch the corresponding commit hash from GitHub. |
| 7 | +# |
| 8 | +# Note: This script can only be executed from project root directory of an extracted "release" |
| 9 | +# tarball. |
| 10 | + |
| 11 | +import json |
| 12 | +import pathlib |
| 13 | +import sys |
| 14 | +import urllib.request |
| 15 | + |
| 16 | +if __name__ == '__main__': |
| 17 | + # Simple check if a .git directory exists. When we are in a Git repo, we should rely on git. |
| 18 | + if pathlib.Path(".git").exists(): |
| 19 | + print( |
| 20 | + "Failed to create SOURCE_VERSION. " |
| 21 | + "Run this script from an extracted release tarball directory.") |
| 22 | + sys.exit(1) |
| 23 | + |
| 24 | + # Check if we have VERSION.txt available |
| 25 | + current_version_file = pathlib.Path("VERSION.txt") |
| 26 | + if not current_version_file.exists(): |
| 27 | + print( |
| 28 | + "Failed to read VERSION.txt. " |
| 29 | + "Run this script from project root of an extracted release tarball directory.") |
| 30 | + sys.exit(1) |
| 31 | + |
| 32 | + current_version = current_version_file.read_text().rstrip() |
| 33 | + |
| 34 | + # Exit when we are in a "main" copy. |
| 35 | + if current_version.endswith("-dev"): |
| 36 | + print( |
| 37 | + "Failed to create SOURCE_VERSION. " |
| 38 | + "The current VERSION.txt contains version with '-dev' suffix. " |
| 39 | + "Run this script from an extracted release tarball directory.") |
| 40 | + sys.exit(1) |
| 41 | + |
| 42 | + # Fetch the current version commit information from GitHub. |
| 43 | + with urllib.request.urlopen("https://api.github.com/repos/envoyproxy/envoy/commits/v" |
| 44 | + + current_version) as response: |
| 45 | + commit_info = json.loads(response.read()) |
| 46 | + source_version_file = pathlib.Path("SOURCE_VERSION") |
| 47 | + # Write the extracted current version commit hash "sha" to SOURCE_VERSION. |
| 48 | + source_version_file.write_text(commit_info["sha"]) |
0 commit comments