Skip to content

Commit 9dcd806

Browse files
authored
tools, github: Add current SOURCE_VERSION writer (#23577)
This adds a script to produce SOURCE_VERSION which is useful to build envoy in a non-git (from an extracted release tarball) directory. Signed-off-by: Dhi Aurrahman <[email protected]>
1 parent ce49966 commit 9dcd806

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed

bazel/README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,18 @@ independently sourced, the following steps should be followed:
3232
1. Configure, build and/or install the [Envoy dependencies](https://www.envoyproxy.io/docs/envoy/latest/start/building#requirements).
3333
1. `bazel build -c opt envoy` from the repository root.
3434

35+
### Building from a release tarball
36+
37+
To build Envoy from a release tarball, you can download a release tarball from Assets section in each release in project [Releases page](https://github.com/envoyproxy/envoy/releases).
38+
Given all required [Envoy dependencies](https://www.envoyproxy.io/docs/envoy/latest/start/building#requirements) are installed, the following steps should be followed:
39+
40+
1. Download and extract source code of a release tarball from the Releases page. For example: https://github.com/envoyproxy/envoy/releases/tag/v1.24.0.
41+
1. `python3 tools/github/tools/github/write_current_source_version.py` from the repository root.
42+
1. `bazel build -c opt envoy` from the repository root.
43+
44+
> Note: If the the `write_current_source_version.py` script is missing from the extracted source code directory, you can download it from [here](https://raw.githubusercontent.com/envoyproxy/envoy/tree/main/tools/github/write_current_source_version.py).
45+
> This script is used to generate SOURCE_VERSION that is required by [`bazel/get_workspace_status`](./get_workspace_status) to "stamp" the binary in a non-git directory.
46+
3547
## Quick start Bazel build for developers
3648

3749
This section describes how to and what dependencies to install to get started building Envoy with Bazel.
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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

Comments
 (0)