Skip to content

Commit

Permalink
Read API cache data from json
Browse files Browse the repository at this point in the history
Signed-off-by: William Vinnicombe <william.vinnicombe@raspberrypi.com>
  • Loading branch information
will-v-pi committed Jul 1, 2024
1 parent 71d7bd4 commit 884b143
Show file tree
Hide file tree
Showing 8 changed files with 477 additions and 155 deletions.
24 changes: 23 additions & 1 deletion .github/workflows/static.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,34 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Enable corepack
run: corepack enable
- name: Setup node v18
uses: actions/setup-node@v4
with:
# the current node version use in vscode
node-version: '18'
cache: 'yarn'
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.x'
- name: Install Dependencies
run: |
yarn
pip install requests js2py
- name: Generate Cache JSON
env:
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
run: |
yarn run compile
python3 scripts/genCache.py
- name: Setup Pages
uses: actions/configure-pages@v4
- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
# Upload entire repository
# Upload data directory
path: 'data'
- name: Deploy to GitHub Pages
id: deployment
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -497,3 +497,5 @@ fabric.properties
*.zip

!vendor/**/dist

tmp.py
1 change: 1 addition & 0 deletions .vscodeignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ rollup.config.mjs
**/*.ts
.pnp*
*.vsix
tmp.py

# make sure scripts and data are always included
!scripts/**
Expand Down
242 changes: 242 additions & 0 deletions data/0.10.0/github-cache.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,242 @@
{
"githubApiCache-0-0": [
"1.5.1"
],
"githubApiCache-0-1": {
"assets": [
{
"id": 112935743,
"name": "sdk-1.5.1-html-doc.zip",
"browser_download_url": "https://github.com/raspberrypi/pico-sdk/releases/download/1.5.1/sdk-1.5.1-html-doc.zip"
}
],
"assetsUrl": "https://api.github.com/repos/raspberrypi/pico-sdk/releases/107707260/assets"
},
"githubApiCache-1-0": [
"v3.28.0-rc6"
],
"githubApiCache-1-1": {
"assets": [
{
"id": 138286886,
"name": "cmake-3.28.0-rc6-files-v1.json",
"browser_download_url": "https://github.com/Kitware/CMake/releases/download/v3.28.0-rc6/cmake-3.28.0-rc6-files-v1.json"
},
{
"id": 138286887,
"name": "cmake-3.28.0-rc6-linux-aarch64.sh",
"browser_download_url": "https://github.com/Kitware/CMake/releases/download/v3.28.0-rc6/cmake-3.28.0-rc6-linux-aarch64.sh"
},
{
"id": 138286891,
"name": "cmake-3.28.0-rc6-linux-aarch64.tar.gz",
"browser_download_url": "https://github.com/Kitware/CMake/releases/download/v3.28.0-rc6/cmake-3.28.0-rc6-linux-aarch64.tar.gz"
},
{
"id": 138286893,
"name": "cmake-3.28.0-rc6-linux-x86_64.sh",
"browser_download_url": "https://github.com/Kitware/CMake/releases/download/v3.28.0-rc6/cmake-3.28.0-rc6-linux-x86_64.sh"
},
{
"id": 138286897,
"name": "cmake-3.28.0-rc6-linux-x86_64.tar.gz",
"browser_download_url": "https://github.com/Kitware/CMake/releases/download/v3.28.0-rc6/cmake-3.28.0-rc6-linux-x86_64.tar.gz"
},
{
"id": 138286903,
"name": "cmake-3.28.0-rc6-macos-universal.dmg",
"browser_download_url": "https://github.com/Kitware/CMake/releases/download/v3.28.0-rc6/cmake-3.28.0-rc6-macos-universal.dmg"
},
{
"id": 138286905,
"name": "cmake-3.28.0-rc6-macos-universal.tar.gz",
"browser_download_url": "https://github.com/Kitware/CMake/releases/download/v3.28.0-rc6/cmake-3.28.0-rc6-macos-universal.tar.gz"
},
{
"id": 138286910,
"name": "cmake-3.28.0-rc6-macos10.10-universal.dmg",
"browser_download_url": "https://github.com/Kitware/CMake/releases/download/v3.28.0-rc6/cmake-3.28.0-rc6-macos10.10-universal.dmg"
},
{
"id": 138286923,
"name": "cmake-3.28.0-rc6-macos10.10-universal.tar.gz",
"browser_download_url": "https://github.com/Kitware/CMake/releases/download/v3.28.0-rc6/cmake-3.28.0-rc6-macos10.10-universal.tar.gz"
},
{
"id": 138286925,
"name": "cmake-3.28.0-rc6-SHA-256.txt",
"browser_download_url": "https://github.com/Kitware/CMake/releases/download/v3.28.0-rc6/cmake-3.28.0-rc6-SHA-256.txt"
},
{
"id": 138286926,
"name": "cmake-3.28.0-rc6-SHA-256.txt.asc",
"browser_download_url": "https://github.com/Kitware/CMake/releases/download/v3.28.0-rc6/cmake-3.28.0-rc6-SHA-256.txt.asc"
},
{
"id": 138286927,
"name": "cmake-3.28.0-rc6-windows-arm64.msi",
"browser_download_url": "https://github.com/Kitware/CMake/releases/download/v3.28.0-rc6/cmake-3.28.0-rc6-windows-arm64.msi"
},
{
"id": 138286932,
"name": "cmake-3.28.0-rc6-windows-arm64.zip",
"browser_download_url": "https://github.com/Kitware/CMake/releases/download/v3.28.0-rc6/cmake-3.28.0-rc6-windows-arm64.zip"
},
{
"id": 138286933,
"name": "cmake-3.28.0-rc6-windows-i386.msi",
"browser_download_url": "https://github.com/Kitware/CMake/releases/download/v3.28.0-rc6/cmake-3.28.0-rc6-windows-i386.msi"
},
{
"id": 138286934,
"name": "cmake-3.28.0-rc6-windows-i386.zip",
"browser_download_url": "https://github.com/Kitware/CMake/releases/download/v3.28.0-rc6/cmake-3.28.0-rc6-windows-i386.zip"
},
{
"id": 138286935,
"name": "cmake-3.28.0-rc6-windows-x86_64.msi",
"browser_download_url": "https://github.com/Kitware/CMake/releases/download/v3.28.0-rc6/cmake-3.28.0-rc6-windows-x86_64.msi"
},
{
"id": 138286937,
"name": "cmake-3.28.0-rc6-windows-x86_64.zip",
"browser_download_url": "https://github.com/Kitware/CMake/releases/download/v3.28.0-rc6/cmake-3.28.0-rc6-windows-x86_64.zip"
},
{
"id": 138286939,
"name": "cmake-3.28.0-rc6.tar.gz",
"browser_download_url": "https://github.com/Kitware/CMake/releases/download/v3.28.0-rc6/cmake-3.28.0-rc6.tar.gz"
},
{
"id": 138286941,
"name": "cmake-3.28.0-rc6.zip",
"browser_download_url": "https://github.com/Kitware/CMake/releases/download/v3.28.0-rc6/cmake-3.28.0-rc6.zip"
}
],
"assetsUrl": "https://api.github.com/repos/Kitware/CMake/releases/132188415/assets"
},
"githubApiCache-2-0": [
"v1.12.1"
],
"githubApiCache-2-1": {
"assets": [
{
"id": 167333823,
"name": "ninja-linux-aarch64.zip",
"browser_download_url": "https://github.com/ninja-build/ninja/releases/download/v1.12.1/ninja-linux-aarch64.zip"
},
{
"id": 167333509,
"name": "ninja-linux.zip",
"browser_download_url": "https://github.com/ninja-build/ninja/releases/download/v1.12.1/ninja-linux.zip"
},
{
"id": 167333196,
"name": "ninja-mac.zip",
"browser_download_url": "https://github.com/ninja-build/ninja/releases/download/v1.12.1/ninja-mac.zip"
},
{
"id": 167333379,
"name": "ninja-win.zip",
"browser_download_url": "https://github.com/ninja-build/ninja/releases/download/v1.12.1/ninja-win.zip"
},
{
"id": 167333478,
"name": "ninja-winarm64.zip",
"browser_download_url": "https://github.com/ninja-build/ninja/releases/download/v1.12.1/ninja-winarm64.zip"
}
],
"assetsUrl": "https://api.github.com/repos/ninja-build/ninja/releases/155357494/assets"
},
"githubApiCache-3-0": [
"v1.5.1-alpha-1"
],
"githubApiCache-3-1": {
"assets": [
{
"id": 141973997,
"name": "openocd-0.12.0-x64-win.zip",
"browser_download_url": "https://github.com/will-v-pi/pico-sdk-tools/releases/download/v1.5.1-alpha-1/openocd-0.12.0-x64-win.zip"
},
{
"id": 141974002,
"name": "pico-sdk-tools-1.5.1-x64-win.zip",
"browser_download_url": "https://github.com/will-v-pi/pico-sdk-tools/releases/download/v1.5.1-alpha-1/pico-sdk-tools-1.5.1-x64-win.zip"
},
{
"id": 141974003,
"name": "picotool-1.1.2-x64-win.zip",
"browser_download_url": "https://github.com/will-v-pi/pico-sdk-tools/releases/download/v1.5.1-alpha-1/picotool-1.1.2-x64-win.zip"
}
],
"assetsUrl": "https://api.github.com/repos/will-v-pi/pico-sdk-tools/releases/134896110/assets"
},
"githubApiCache-4-0": [
"v0.12.0-2"
],
"githubApiCache-4-1": {
"assets": [
{
"id": 124558743,
"name": "xpack-openocd-0.12.0-2-darwin-arm64.tar.gz",
"browser_download_url": "https://github.com/xpack-dev-tools/openocd-xpack/releases/download/v0.12.0-2/xpack-openocd-0.12.0-2-darwin-arm64.tar.gz"
},
{
"id": 124558741,
"name": "xpack-openocd-0.12.0-2-darwin-arm64.tar.gz.sha",
"browser_download_url": "https://github.com/xpack-dev-tools/openocd-xpack/releases/download/v0.12.0-2/xpack-openocd-0.12.0-2-darwin-arm64.tar.gz.sha"
},
{
"id": 124558736,
"name": "xpack-openocd-0.12.0-2-darwin-x64.tar.gz",
"browser_download_url": "https://github.com/xpack-dev-tools/openocd-xpack/releases/download/v0.12.0-2/xpack-openocd-0.12.0-2-darwin-x64.tar.gz"
},
{
"id": 124558734,
"name": "xpack-openocd-0.12.0-2-darwin-x64.tar.gz.sha",
"browser_download_url": "https://github.com/xpack-dev-tools/openocd-xpack/releases/download/v0.12.0-2/xpack-openocd-0.12.0-2-darwin-x64.tar.gz.sha"
},
{
"id": 124558733,
"name": "xpack-openocd-0.12.0-2-linux-arm.tar.gz",
"browser_download_url": "https://github.com/xpack-dev-tools/openocd-xpack/releases/download/v0.12.0-2/xpack-openocd-0.12.0-2-linux-arm.tar.gz"
},
{
"id": 124558731,
"name": "xpack-openocd-0.12.0-2-linux-arm.tar.gz.sha",
"browser_download_url": "https://github.com/xpack-dev-tools/openocd-xpack/releases/download/v0.12.0-2/xpack-openocd-0.12.0-2-linux-arm.tar.gz.sha"
},
{
"id": 124558729,
"name": "xpack-openocd-0.12.0-2-linux-arm64.tar.gz",
"browser_download_url": "https://github.com/xpack-dev-tools/openocd-xpack/releases/download/v0.12.0-2/xpack-openocd-0.12.0-2-linux-arm64.tar.gz"
},
{
"id": 124558727,
"name": "xpack-openocd-0.12.0-2-linux-arm64.tar.gz.sha",
"browser_download_url": "https://github.com/xpack-dev-tools/openocd-xpack/releases/download/v0.12.0-2/xpack-openocd-0.12.0-2-linux-arm64.tar.gz.sha"
},
{
"id": 124558723,
"name": "xpack-openocd-0.12.0-2-linux-x64.tar.gz",
"browser_download_url": "https://github.com/xpack-dev-tools/openocd-xpack/releases/download/v0.12.0-2/xpack-openocd-0.12.0-2-linux-x64.tar.gz"
},
{
"id": 124558720,
"name": "xpack-openocd-0.12.0-2-linux-x64.tar.gz.sha",
"browser_download_url": "https://github.com/xpack-dev-tools/openocd-xpack/releases/download/v0.12.0-2/xpack-openocd-0.12.0-2-linux-x64.tar.gz.sha"
},
{
"id": 124558714,
"name": "xpack-openocd-0.12.0-2-win32-x64.zip",
"browser_download_url": "https://github.com/xpack-dev-tools/openocd-xpack/releases/download/v0.12.0-2/xpack-openocd-0.12.0-2-win32-x64.zip"
},
{
"id": 124558710,
"name": "xpack-openocd-0.12.0-2-win32-x64.zip.sha",
"browser_download_url": "https://github.com/xpack-dev-tools/openocd-xpack/releases/download/v0.12.0-2/xpack-openocd-0.12.0-2-win32-x64.zip.sha"
}
],
"assetsUrl": "https://api.github.com/repos/xpack-dev-tools/openocd-xpack/releases/119866462/assets"
}
}
99 changes: 99 additions & 0 deletions scripts/genCache.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
import json
import os
import sys

import requests
import js2py


dir_path = os.path.dirname(os.path.realpath(__file__))
os.chdir(f"{dir_path}/..")

# Extract js for variables
with open("dist/extension.cjs", "r") as f:
keep = False
txt = ""
for line in f.readlines():
if "const EXT_USER_AGENT =" in line:
keep = True
elif "getAuthorizationHeaders" in line:
keep = False
elif "const CURRENT_DATA_VERSION =" in line:
keep = True

if keep:
txt += line

if "const CURRENT_DATA_VERSION =" in line:
keep = False

parsed = js2py.translate_js(txt)
with open("tmp.py", "w") as f:
f.write(parsed)
sys.path.append(os.getcwd())

import tmp

stuff = tmp.var.to_python()

# stuff.GithubRepository has conversions in both directions, so is twice the size
num_repos = 0
for _ in stuff.GithubRepository:
num_repos += 0.5
num_repos = int(num_repos)
assert num_repos == 5
print("Num repos", num_repos)


# Only provide data for these versions
versions = [
"1.5.1",
"v3.28.0-rc6",
"v1.12.1",
"v1.5.1-alpha-1",
"v0.12.0-2",
]

headers = {
"X-GitHub-Api-Version": "2022-11-28",
"User-Agent": stuff.EXT_USER_AGENT,
"Authorization": f"Bearer {os.environ['GITHUB_TOKEN']}"
}

ret = {}
for repo in range(num_repos):
ret[f"githubApiCache-{repo}-0"] = versions[repo]

version = versions[repo]
owner = stuff.ownerOfRepository(repo)
name = stuff.repoNameOfRepository(repo)
x = requests.get(
f"{stuff.GITHUB_API_BASE_URL}/repos/{owner}/{name}/releases/tags/{version}",
headers=headers
)
data = json.loads(x.content)
assets = []
for asset in data["assets"]:
assets.append({
"id": asset["id"],
"name": asset["name"],
"browser_download_url": asset["browser_download_url"]
})
data = {
"assets": assets,
"assetsUrl": data["assets_url"]
}

ret[f"githubApiCache-{repo}-1"] = data


for k, v in ret.items():
idx = int(k.split('-')[1])
print(f"{k} is {stuff.GithubRepository[idx]}")
if isinstance(v, list):
print(v)
else:
print(v["assets"][0])

with open(f"data/{stuff.CURRENT_DATA_VERSION}/github-cache.json", "w") as f:
json.dump(ret, f, indent=2)
Loading

0 comments on commit 884b143

Please sign in to comment.