From 24c832983d3bc520ebf091a027106a70a426b1e5 Mon Sep 17 00:00:00 2001 From: socar-dini <0327jane@gmail.com> Date: Thu, 24 Aug 2023 20:46:53 +0900 Subject: [PATCH] fix: add scripts to download the historical versions --- docs-website/build.gradle | 10 ++-- docs-website/download_historical_versions.py | 53 ++++++++++++++++++++ 2 files changed, 60 insertions(+), 3 deletions(-) create mode 100644 docs-website/download_historical_versions.py diff --git a/docs-website/build.gradle b/docs-website/build.gradle index 12f37033efc2f..1d98499795ee8 100644 --- a/docs-website/build.gradle +++ b/docs-website/build.gradle @@ -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) { @@ -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) diff --git a/docs-website/download_historical_versions.py b/docs-website/download_historical_versions.py new file mode 100644 index 0000000000000..e25853b6d889e --- /dev/null +++ b/docs-website/download_historical_versions.py @@ -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()