Skip to content

Commit 3d44f11

Browse files
authored
Add gh api call for fetching llvm version (#1942)
Fixes #1877
1 parent 3586911 commit 3d44f11

File tree

3 files changed

+27
-9
lines changed

3 files changed

+27
-9
lines changed

.github/workflows/build_llvm_libraries.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,13 @@ jobs:
2626
- name: checkout
2727
uses: actions/checkout@v3
2828

29+
- name: install dependencies
30+
run: /usr/bin/env python3 -m pip install -r requirements.txt
31+
working-directory: build-scripts
32+
2933
- name: retrive the last commit ID
3034
id: get_last_commit
31-
run: echo "last_commit=$(/usr/bin/env python3 ./build_llvm.py --llvm-ver)" >> $GITHUB_OUTPUT
35+
run: echo "last_commit=$(GH_TOKEN=${{ secrets.GITHUB_TOKEN }} /usr/bin/env python3 ./build_llvm.py --llvm-ver)" >> $GITHUB_OUTPUT
3236
working-directory: build-scripts
3337

3438
# Bump the prefix number to evict all previous caches and

build-scripts/build_llvm.py

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import argparse
88
import os
99
import pathlib
10+
import requests
1011
import shlex
1112
import shutil
1213
import subprocess
@@ -27,11 +28,23 @@ def clone_llvm(dst_dir, llvm_repo, llvm_branch):
2728
return llvm_dir
2829

2930

30-
def query_llvm_version(llvm_dir):
31-
GIT_LOG_CMD = f"git log --format=format:'%h' -1"
32-
return subprocess.check_output(
33-
shlex.split(GIT_LOG_CMD), cwd=llvm_dir, universal_newlines=True, text=True
34-
)
31+
def query_llvm_version(llvm_info):
32+
github_token = os.environ['GH_TOKEN']
33+
owner_project = llvm_info['repo'].replace("https://github.com/", "").replace(".git", "")
34+
url = f"https://api.github.com/repos/{owner_project}/commits/{llvm_info['branch']}"
35+
headers = {
36+
'Authorization': f"Bearer {github_token}"
37+
}
38+
39+
try:
40+
response = requests.request("GET", url, headers=headers, data={})
41+
response.raise_for_status()
42+
except requests.exceptions.HTTPError as error:
43+
print (error) # for debugging purpose
44+
return None
45+
46+
response = response.json()
47+
return response['sha']
3548

3649

3750
def build_llvm(llvm_dir, platform, backends, projects, use_clang=False):
@@ -253,13 +266,13 @@ def main():
253266

254267
try:
255268
llvm_info = llvm_repo_and_branch.get(platform, llvm_repo_and_branch["default"])
256-
llvm_dir = clone_llvm(deps_dir, llvm_info["repo"], llvm_info["branch"])
257269

258270
if options.llvm_ver:
259-
commit_hash = query_llvm_version(llvm_dir)
271+
commit_hash = query_llvm_version(llvm_info)
260272
print(commit_hash)
261273
return commit_hash is not None
262-
274+
275+
llvm_dir = clone_llvm(deps_dir, llvm_info["repo"], llvm_info["branch"])
263276
if (
264277
build_llvm(
265278
llvm_dir, platform, options.arch, options.project, options.use_clang

build-scripts/requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
requests==2.28.2

0 commit comments

Comments
 (0)