Skip to content
This repository was archived by the owner on Jul 31, 2023. It is now read-only.

Commit 7c3607b

Browse files
authored
Automate pinning dependencies. (#315)
1 parent 24893eb commit 7c3607b

File tree

2 files changed

+67
-11
lines changed

2 files changed

+67
-11
lines changed

RELEASING.md

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -72,17 +72,10 @@ token](https://help.github.com/articles/creating-a-personal-access-token-for-the
7272
$ git checkout -b deps remotes/upstream/v$MAJOR.$MINOR.x
7373
```
7474
75-
One day, this will be automated. In the meantime, edit the `WORKSPACE` file
76-
and for every `http_archive`:
77-
* Use `git ls-remote https://github.com/abc/def master` to determine the
78-
commit.
79-
* Download the archive and `sha256sum` it.
80-
* Change `urls = ".../archive/master.zip"` to
81-
`urls = ".../archive/$COMMIT.zip`.
82-
* Change `strip_prefix` from `-master` to `-$COMMIT`.
83-
* Add `sha256 = "$SHASUM"`.
84-
85-
Likewise update the `cmake/*.CMakeLists.txt` files.
75+
One day, this will be more automated. In the meantime,
76+
run `tools/pin_deps.py` and edit the `WORKSPACE` file accordingly.
77+
78+
Likewise update the `cmake/OpenCensusDeps.cmake` file.
8679
8780
Run `tools/presubmit.sh` to test building with bazel, and follow the
8881
[CMake README](cmake/README.md) for CMake.

tools/pin_deps.py

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#!/usr/bin/env python
2+
'''
3+
This script uses the GitHub API to construct http_archive elements to be
4+
inserted into the WORKSPACE file.
5+
6+
It is a fork of:
7+
https://github.com/abseil/federation-hello/blob/0c1ef91b9cc5aabf15a3ff15761837d1c8da93a6/head_sync.py
8+
'''
9+
import hashlib
10+
import json
11+
import urllib3
12+
13+
HTTP_ARCHIVE_TEMPLATE = """http_archive(
14+
name = "{}",
15+
urls = ["{}"], # {}
16+
strip_prefix = "{}-{}",
17+
sha256 = "{}",
18+
)"""
19+
20+
http = urllib3.PoolManager()
21+
22+
23+
class ExternalDependency(object):
24+
def workspace_rule(self):
25+
raise NotImplementedError('must implement workspace_rule()')
26+
27+
28+
class GitHubProject(ExternalDependency):
29+
def __init__(self, name, owner, repo):
30+
self.name = name
31+
self.owner = owner
32+
self.repo = repo
33+
34+
def workspace_rule(self):
35+
# https://developer.github.com/v3/repos/commits/
36+
request = http.request(
37+
'GET', 'https://api.github.com/repos/{}/{}/commits'.format(
38+
project.owner, project.repo),
39+
headers = { 'User-Agent': 'Workspace Updater' })
40+
response = json.loads(request.data.decode('utf-8'))
41+
commit = response[0]["sha"]
42+
date = response[0]["commit"]["committer"]["date"]
43+
url = 'https://github.com/{}/{}/archive/{}.zip'.format(
44+
project.owner, project.repo, commit)
45+
request = http.request('GET', url,
46+
headers = { 'User-Agent': 'Workspace Updater' })
47+
sha256 = hashlib.sha256(request.data).hexdigest()
48+
return HTTP_ARCHIVE_TEMPLATE.format(project.name, url, date, project.repo,
49+
commit, sha256)
50+
51+
52+
PROJECTS = [
53+
GitHubProject('com_google_absl', 'abseil', 'abseil-cpp'),
54+
GitHubProject('com_google_googletest', 'google', 'googletest'),
55+
GitHubProject('com_github_google_benchmark', 'google', 'benchmark'),
56+
GitHubProject('com_github_grpc_grpc', 'grpc', 'grpc'),
57+
GitHubProject('com_github_jupp0r_prometheus_cpp', 'jupp0r', 'prometheus-cpp'),
58+
GitHubProject('com_github_curl', 'curl', 'curl'),
59+
GitHubProject('com_github_tencent_rapidjson', 'Tencent', 'rapidjson'),
60+
]
61+
62+
for project in PROJECTS:
63+
print(project.workspace_rule())

0 commit comments

Comments
 (0)