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
Changes from 6 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
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 sys
import json

dio marked this conversation as resolved.
Show resolved Hide resolved
from urllib import request
from pathlib import Path

# Simple check if a .git directory exists. When we are in a Git repo, we should rely on git.
if 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 = 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 request.urlopen("https://api.github.com/repos/envoyproxy/envoy/commits/v"
+ current_version) as response:
commit_info = json.loads(response.read())
source_version_file = 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"])