Skip to content

Commit

Permalink
add script to download artifact
Browse files Browse the repository at this point in the history
  • Loading branch information
haohanyang committed Sep 23, 2024
1 parent 5771f2f commit f29b743
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 4 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,7 @@ ci/
.idea

.eslintcache

.env
venv/
mongodb-datasource/
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mongodb-datasource",
"version": "0.0.0",
"version": "0.1.0",
"scripts": {
"build": "webpack -c ./.config/webpack/webpack.config.ts --env production",
"dev": "webpack -w -c ./.config/webpack/webpack.config.ts --env development",
Expand Down Expand Up @@ -71,4 +71,4 @@
"tslib": "2.5.3"
},
"packageManager": "npm@9.6.7"
}
}
49 changes: 49 additions & 0 deletions scripts/download_artifacts.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Download the latest GitHub Action artifact to mongodb-datasource folder
import tempfile
import zipfile
import requests
import sys
import os

pat = os.getenv("GITHUB_PAT")
if len(sys.argv) > 1:
pat = sys.argv[1]

headers = {
"Accept": "application/vnd.github+json",
"Authorization": "Bearer " + pat,
"X-GitHub-Api-Version": "2022-11-28"
}

if not pat:
print("GitHub PAT not set")
exit(1)

response = requests.get(
"https://api.github.com/repos/haohanyang/mongodb-datasource/actions/artifacts", headers=headers)

response.raise_for_status()

artifacts = response.json()["artifacts"]

if len(artifacts) == 0:
print("No artifacts found")
exit(1)

artifact_download_url = artifacts[0]["archive_download_url"]

response = requests.get(artifact_download_url, headers=headers)
response.raise_for_status()

dist_dir = "mongodb-datasource"

if os.path.isdir(dist_dir):
os.rmdir(dist_dir)

os.mkdir(dist_dir)

with tempfile.NamedTemporaryFile() as temp_file:
temp_file.write(response.content)

with zipfile.ZipFile(temp_file.name, 'r') as zip_ref:
zip_ref.extractall(dist_dir)

0 comments on commit f29b743

Please sign in to comment.