Skip to content

Commit

Permalink
Bump
Browse files Browse the repository at this point in the history
  • Loading branch information
abejgonzalez committed Aug 23, 2024
1 parent 07c9a60 commit aeb0282
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 130 deletions.
60 changes: 3 additions & 57 deletions .github/scripts/build-default-bitstreams.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@

from pathlib import Path
from fabric.api import prefix, run, settings, execute # type: ignore
from github import Github
import time

import fabric_cfg
from ci_variables import ci_env
from github_common import upload_binary_file

from typing import List, Tuple

Expand All @@ -16,64 +15,11 @@

shared_build_dir = "/scratch/buildbot/FIRESIM_BUILD_DIR"

from_chipyard_firesim_build_recipes = "sim/firesim-staging/sample_config_build_recipes.yaml"
from_chipyard_firesim_hwdb = "sim/firesim-staging/sample_config_hwdb.yaml"
from_chipyard_firesim_build_recipes = "sims/firesim-staging/sample_config_build_recipes.yaml"
from_chipyard_firesim_hwdb = ci_env['CHIPYARD_HWDB_PATH']

sample_hwdb_filename = f"{manager_fsim_dir}/deploy/sample-backup-configs/sample_config_hwdb.yaml"

# taken from https://stackoverflow.com/questions/63427607/python-upload-files-directly-to-github-using-pygithub
# IMPORTANT: only works for binary files! (i.e. tar.gz files)
def upload_binary_file(local_file_path, gh_file_path):
print(f":DEBUG: Attempting to upload {local_file_path} to {gh_file_path}")

g = Github(ci_env['PERSONAL_ACCESS_TOKEN'])

repo = g.get_repo(f'{GH_ORG}/{GH_REPO}')
all_files = []
contents = repo.get_contents("")
while contents:
file_content = contents.pop(0)
if file_content.type == "dir":
contents.extend(repo.get_contents(file_content.path))
else:
file = file_content
all_files.append(str(file).replace('ContentFile(path="','').replace('")',''))

with open(local_file_path, 'rb') as file:
content = file.read()

tries = 10
delay = 15
msg = f"Committing files from {ci_env['GITHUB_SHA']}"
upload_branch = 'main'
r = None

# Upload to github
git_file = gh_file_path
if git_file in all_files:
contents = repo.get_contents(git_file)
for n in range(tries):
try:
r = repo.update_file(contents.path, msg, content, contents.sha, branch=upload_branch)
break
except Exception as e:
print(f"Got exception: {e}")
time.sleep(delay)
assert r is not None, f"Unable to poll 'update_file' API {tries} times"
print(f"Updated: {git_file}")
else:
for n in range(tries):
try:
r = repo.create_file(git_file, msg, content, branch=upload_branch)
break
except Exception as e:
print(f"Got exception: {e}")
time.sleep(delay)
assert r is not None, f"Unable to poll 'create_file' API {tries} times"
print(f"Created: {git_file}")

return r['commit'].sha

def run_local_buildbitstreams():
"""Runs local buildbitstreams"""

Expand Down
4 changes: 4 additions & 0 deletions .github/scripts/ci_variables.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ class CIEnvironment(TypedDict):
# Github token with more permissions to access repositories across the FireSim org.
PERSONAL_ACCESS_TOKEN: str

# Path to Chipyard's HWDB file (if it exists)
CHIPYARD_HWDB_PATH: str


GITHUB_ACTIONS_ENV_VAR_NAME = 'GITHUB_ACTIONS'
RUN_LOCAL = os.environ.get(GITHUB_ACTIONS_ENV_VAR_NAME, 'false') == 'false'
Expand All @@ -70,6 +73,7 @@ def get_ci_value(env_var: str, default_value: str = "") -> str:

'REMOTE_WORK_DIR': get_ci_value('REMOTE_WORK_DIR', local_cy_dir if RUN_LOCAL else ""),
'PERSONAL_ACCESS_TOKEN': get_ci_value('PERSONAL_ACCESS_TOKEN'),
'CHIPYARD_HWDB_PATH': get_ci_value('PERSONAL_ACCESS_TOKEN'),
}

manager_fsim_dir = ci_env['REMOTE_WORK_DIR'] + "/sims/firesim"
125 changes: 54 additions & 71 deletions .github/scripts/github_common.py
Original file line number Diff line number Diff line change
@@ -1,74 +1,57 @@
import math
import requests
import json
from github import Github
import time

import fabric_cfg
from ci_variables import ci_env

from typing import Dict, List, Any

# Github URL related constants
gh_repo_api_url = f"{ci_env['GITHUB_API_URL']}/repos/{ci_env['GITHUB_REPOSITORY']}"
gh_issues_api_url = f"{gh_repo_api_url}/issues"
gha_api_url = f"{gh_repo_api_url}/actions"
gha_runners_api_url = f"{gha_api_url}/runners"
gha_runs_api_url = f"{gha_api_url}/runs"
gha_workflow_api_url = f"{gha_runs_api_url}/{ci_env['GITHUB_RUN_ID']}"

def get_header(gh_token: str) -> Dict[str, str]:
return {
"Authorization": f"token {gh_token.strip()}",
"Accept": "application/vnd.github+json",
"User-Agent": "bar-tender",
}

def get_runners(gh_token: str) -> List[Dict[str, Any]]:
r = requests.get(gha_runners_api_url, headers=get_header(gh_token))
if r.status_code != 200:
raise Exception(f"Unable to retrieve count of GitHub Actions Runners\nFull Response Below:\n{r}")
res_dict = r.json()
runner_count = res_dict["total_count"]

runners: List[Dict[str, Any]] = []
for page_idx in range(math.ceil(runner_count / 30)):
r = requests.get(gha_runners_api_url, params={"per_page" : 30, "page" : page_idx + 1}, headers=get_header(gh_token))
if r.status_code != 200:
raise Exception(f"Unable to retrieve (sub)list of GitHub Actions Runners\nFull Response Below\n{r}")
res_dict = r.json()
runners = runners + res_dict["runners"]

return runners

def delete_runner(gh_token: str, runner: Dict[str, Any]) -> bool:
r = requests.delete(f"""{gha_runners_api_url}/{runner["id"]}""", headers=get_header(gh_token))
if r.status_code != 204:
print(f"""Unable to delete runner {runner["name"]} with id: {runner["id"]}\nFull Response Below\n{r}""")
return False
return True

def deregister_offline_runners(gh_token: str) -> None:
runners = get_runners(gh_token)
for runner in runners:
if runner["status"] == "offline":
delete_runner(gh_token, runner)

def deregister_runners(gh_token: str, runner_name: str) -> None:
runners = get_runners(gh_token)
for runner in runners:
if runner_name in runner["name"]:
delete_runner(gh_token, runner)

# obtain issue number separately since workflow-monitor shouldn't query the GH-A runner area
# since it's separate from it
def get_issue_number() -> int:
with open(ci_env['GITHUB_EVENT_PATH']) as f:
event_payload = json.load(f)
gh_issue_id = event_payload["number"]
return gh_issue_id
raise Exception(f"Unable to return an issue number using {ci_env['GITHUB_EVENT_PATH']}")

def issue_post(gh_token: str, issue_num: int, body: str) -> None:
res = requests.post(f"{gh_issues_api_url}/{issue_num}/comments",
json={"body": body}, headers=get_header(gh_token))
if res.status_code != 201:
raise Exception(f"HTTP POST error: {res} {res.json()}\nUnable to post GitHub PR comment.")
# taken from https://stackoverflow.com/questions/63427607/python-upload-files-directly-to-github-using-pygithub
# IMPORTANT: only works for binary files! (i.e. tar.gz files)
def upload_binary_file(local_file_path, gh_file_path):
print(f":DEBUG: Attempting to upload {local_file_path} to {gh_file_path}")

g = Github(ci_env['PERSONAL_ACCESS_TOKEN'])

repo = g.get_repo(f'{GH_ORG}/{GH_REPO}')
all_files = []
contents = repo.get_contents("")
while contents:
file_content = contents.pop(0)
if file_content.type == "dir":
contents.extend(repo.get_contents(file_content.path))
else:
file = file_content
all_files.append(str(file).replace('ContentFile(path="','').replace('")',''))

with open(local_file_path, 'rb') as file:
content = file.read()

tries = 10
delay = 15
msg = f"Committing files from {ci_env['GITHUB_SHA']}"
upload_branch = 'main'
r = None

# Upload to github
git_file = gh_file_path
if git_file in all_files:
contents = repo.get_contents(git_file)
for n in range(tries):
try:
r = repo.update_file(contents.path, msg, content, contents.sha, branch=upload_branch)
break
except Exception as e:
print(f"Got exception: {e}")
time.sleep(delay)
assert r is not None, f"Unable to poll 'update_file' API {tries} times"
print(f"Updated: {git_file}")
else:
for n in range(tries):
try:
r = repo.create_file(git_file, msg, content, branch=upload_branch)
break
except Exception as e:
print(f"Got exception: {e}")
time.sleep(delay)
assert r is not None, f"Unable to poll 'create_file' API {tries} times"
print(f"Created: {git_file}")

return r['commit'].sha
12 changes: 10 additions & 2 deletions .github/workflows/firesim-cluster-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ env:
PERSONAL_ACCESS_TOKEN: ${{ secrets.BARTENDER_PERSONAL_ACCESS_TOKEN }}

# temporary directories should be located in /scratch (since it's larger)
REMOTE_WORK_DIR: /scratch/buildbot/cy-shared/cy-${{ github.sha }}-${{ github.workflow }}
REMOTE_WORK_DIR: /scratch/buildbot/cy-ci-shared/cy-${{ github.sha }}-${{ github.workflow }}
JAVA_TMP_DIR: /scratch/buildbot/cy-ci-shared/cy-javatmpdir-${{ github.sha }}-${{ github.workflow }}

# misc
TERM: xterm-256-color
Expand Down Expand Up @@ -123,10 +124,15 @@ jobs:
run: |
mkdir -p $(dirname ${{ env.REMOTE_WORK_DIR }})
git clone ${{ github.workspace }} ${{ env.REMOTE_WORK_DIR }}
- name: Setup Java temp. directory
run: |
mkdir -p ${{ env.JAVA_TMP_DIR }}
- name: Setup repo (for xilinx_alveo_u250 platform)
run: |
cd ${{ env.REMOTE_WORK_DIR }}
export MAKEFLAGS="-j32"
./build-setup.sh --verbose
cd sims/firesim
source sourceme-manager.sh --skip-ssh-setup
firesim managerinit --platform xilinx_alveo_u250
Expand Down Expand Up @@ -160,14 +166,16 @@ jobs:
if: contains(github.event.pull_request.labels.*.name, 'ci:local-fpga-buildbitstream-deploy')
needs: [setup-persistent-repo]
runs-on: as4
env:
CHIPYARD_HWDB_PATH: sims/firesim-staging/sample_config_hwdb.yaml
steps:
- uses: actions/checkout@v4
- name: Run buildbitstream command and update sample local bitstreams
run: .github/scripts/build-default-bitstreams.py
- uses: peter-evans/create-pull-request@v6
with:
base: ${{ github.head_ref }}
add-paths: "sims/firesim-staging/sample_config_hwdb.yaml"
add-paths: ${{ env.CHIPYARD_HWDB_PATH }}
commit-message: "Update local bitstream(s) [ci skip]"
body: "Update local bitstream(s) for PR #${{ github.event.pull_request.number }}"
branch-suffix: random
Expand Down

0 comments on commit aeb0282

Please sign in to comment.