This repository has been archived by the owner on Jul 31, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Automate pinning dependencies. (#315)
- Loading branch information
Showing
2 changed files
with
67 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
#!/usr/bin/env python | ||
''' | ||
This script uses the GitHub API to construct http_archive elements to be | ||
inserted into the WORKSPACE file. | ||
It is a fork of: | ||
https://github.com/abseil/federation-hello/blob/0c1ef91b9cc5aabf15a3ff15761837d1c8da93a6/head_sync.py | ||
''' | ||
import hashlib | ||
import json | ||
import urllib3 | ||
|
||
HTTP_ARCHIVE_TEMPLATE = """http_archive( | ||
name = "{}", | ||
urls = ["{}"], # {} | ||
strip_prefix = "{}-{}", | ||
sha256 = "{}", | ||
)""" | ||
|
||
http = urllib3.PoolManager() | ||
|
||
|
||
class ExternalDependency(object): | ||
def workspace_rule(self): | ||
raise NotImplementedError('must implement workspace_rule()') | ||
|
||
|
||
class GitHubProject(ExternalDependency): | ||
def __init__(self, name, owner, repo): | ||
self.name = name | ||
self.owner = owner | ||
self.repo = repo | ||
|
||
def workspace_rule(self): | ||
# https://developer.github.com/v3/repos/commits/ | ||
request = http.request( | ||
'GET', 'https://api.github.com/repos/{}/{}/commits'.format( | ||
project.owner, project.repo), | ||
headers = { 'User-Agent': 'Workspace Updater' }) | ||
response = json.loads(request.data.decode('utf-8')) | ||
commit = response[0]["sha"] | ||
date = response[0]["commit"]["committer"]["date"] | ||
url = 'https://github.com/{}/{}/archive/{}.zip'.format( | ||
project.owner, project.repo, commit) | ||
request = http.request('GET', url, | ||
headers = { 'User-Agent': 'Workspace Updater' }) | ||
sha256 = hashlib.sha256(request.data).hexdigest() | ||
return HTTP_ARCHIVE_TEMPLATE.format(project.name, url, date, project.repo, | ||
commit, sha256) | ||
|
||
|
||
PROJECTS = [ | ||
GitHubProject('com_google_absl', 'abseil', 'abseil-cpp'), | ||
GitHubProject('com_google_googletest', 'google', 'googletest'), | ||
GitHubProject('com_github_google_benchmark', 'google', 'benchmark'), | ||
GitHubProject('com_github_grpc_grpc', 'grpc', 'grpc'), | ||
GitHubProject('com_github_jupp0r_prometheus_cpp', 'jupp0r', 'prometheus-cpp'), | ||
GitHubProject('com_github_curl', 'curl', 'curl'), | ||
GitHubProject('com_github_tencent_rapidjson', 'Tencent', 'rapidjson'), | ||
] | ||
|
||
for project in PROJECTS: | ||
print(project.workspace_rule()) |