Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tools, github: Add current SOURCE_VERSION writer #23577

Merged
merged 9 commits into from
Oct 21, 2022
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions bazel/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,18 @@ independently sourced, the following steps should be followed:
1. Configure, build and/or install the [Envoy dependencies](https://www.envoyproxy.io/docs/envoy/latest/start/building#requirements).
1. `bazel build -c opt envoy` from the repository root.

### Building from a release tarball

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).
Given all required [Envoy dependencies](https://www.envoyproxy.io/docs/envoy/latest/start/building#requirements) are installed, the following steps should be followed:

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.
1. `python3 tools/github/tools/github/write_current_source_version.py` from the repository root.
1. `bazel build -c opt envoy` from the repository root.

> 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).
> 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.

## Quick start Bazel build for developers

This section describes how to and what dependencies to install to get started building Envoy with Bazel.
Expand Down
49 changes: 49 additions & 0 deletions tools/github/write_current_source_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# This script produces SOURCE_VERSION file with content from current version commit hash. As a
# reminder,SOURCE_VERSION is required when building Envoy from an extracted release tarball
# (non-git). See: bazel/get_workspace_status for more information.
#
# The SOURCE_VERSION file is produced by reading current version tag from VERSION.txt file then
# fetch the corresponding commit hash from GitHub.
#
# Note: This script can only be executed from project root directory of an extracted "release"
# tarball.

import json
import pathlib
import sys
import urllib.request

dio marked this conversation as resolved.
Show resolved Hide resolved
if __name__ == '__main__':
# Simple check if a .git directory exists. When we are in a Git repo, we should rely on git.
if pathlib.Path(".git").exists():
print(
"Failed to create SOURCE_VERSION. "
"Run this script from an extracted release tarball directory.")
sys.exit(1)

# Check if we have VERSION.txt available
current_version_file = pathlib.Path("VERSION.txt")
if not current_version_file.exists():
print(
"Failed to read VERSION.txt. "
"Run this script from project root of an extracted release tarball directory.")
sys.exit(1)

current_version = current_version_file.read_text().rstrip()

# Exit when we are in a "main" copy.
if current_version.endswith("-dev"):
print(
"Failed to create SOURCE_VERSION. "
"The current VERSION.txt contains version with '-dev' suffix. "
"Run this script from an extracted release tarball directory.")
sys.exit(1)

# Fetch the current version commit information from GitHub.
with urllib.request.urlopen("https://api.github.com/repos/envoyproxy/envoy/commits/v"
+ current_version) as response:
commit_info = json.loads(response.read())
source_version_file = pathlib.Path("SOURCE_VERSION")
with source_version_file.open("w", encoding="utf-8") as source_version:
# Write the extracted current version commit hash "sha" to SOURCE_VERSION.
source_version.write(commit_info["sha"])
dio marked this conversation as resolved.
Show resolved Hide resolved