Skip to content

Commit

Permalink
fix: add scripts to download the historical versions
Browse files Browse the repository at this point in the history
  • Loading branch information
yoonhyejin committed Aug 24, 2023
1 parent c5b01c2 commit 24c8329
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 3 deletions.
10 changes: 7 additions & 3 deletions docs-website/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,12 @@ task yarnGenerate(type: YarnTask, dependsOn: [yarnInstall,
args = ['run', 'generate']
}

task yarnStart(type: YarnTask, dependsOn: [yarnInstall, yarnGenerate]) {
task downloadHistoricalVersion(type: Exec) {
workingDir '.'
commandLine 'python', 'download_historical_versions.py'
}

task yarnStart(type: YarnTask, dependsOn: [yarnInstall, yarnGenerate, downloadHistoricalVersion]) {
args = ['run', 'start']
}
task fastReload(type: YarnTask) {
Expand Down Expand Up @@ -105,8 +110,7 @@ task serve(type: YarnTask, dependsOn: [yarnInstall] ) {
}


task yarnBuild(type: YarnTask, dependsOn: [yarnLint, yarnGenerate]) {
inputs.files(projectMdFiles)
task yarnBuild(type: YarnTask, dependsOn: [yarnLint, yarnGenerate, downloadHistoricalVersion]) { inputs.files(projectMdFiles)
inputs.file("package.json").withPathSensitivity(PathSensitivity.RELATIVE)
inputs.dir("src").withPathSensitivity(PathSensitivity.RELATIVE)
inputs.dir("static").withPathSensitivity(PathSensitivity.RELATIVE)
Expand Down
53 changes: 53 additions & 0 deletions docs-website/download_historical_versions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import os
import tarfile

import requests


def download_file(url, destination):
with requests.get(url, stream=True) as response:
response.raise_for_status()
with open(destination, "wb") as f:
for chunk in response.iter_content(chunk_size=8192):
f.write(chunk)


def fetch_tar_urls(repo_url, folder_path):
api_url = f"{repo_url}/contents/{folder_path}"
response = requests.get(api_url)
response.raise_for_status()
data = response.json()
tar_urls = [
file["download_url"] for file in data if file["name"].endswith(".tar.gz")
]
print(tar_urls)
return tar_urls


def main():
repo_url = "https://api.github.com/repos/acryldata/static-assets-test"
folder_path = "versioned_docs"

destination_dir = "versioned_docs"
if not os.path.exists(destination_dir):
os.makedirs(destination_dir)

tar_urls = fetch_tar_urls(repo_url, folder_path)

for url in tar_urls:
filename = os.path.basename(url)
destination_path = os.path.join(destination_dir, filename)

try:
download_file(url, destination_path)
print(f"Downloaded {filename} to {destination_dir}")
with tarfile.open(destination_path, "r:gz") as tar:
tar.extractall()
os.remove(destination_path)
except requests.exceptions.RequestException as e:
print(f"Error while downloading {filename}: {e}")
continue


if __name__ == "__main__":
main()

0 comments on commit 24c8329

Please sign in to comment.