Skip to content

Commit

Permalink
Merge pull request #566 from monarch-initiative/release-from-jenkins
Browse files Browse the repository at this point in the history
Add script to create github release via jenkins job
  • Loading branch information
kevinschaper authored Feb 27, 2024
2 parents ff8fc40 + dff3a67 commit 06e03a5
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ pipeline {
sh 'poetry run ingest release --kghub'
}
}
stage('create github release') {
steps {
sh 'python scripts/create_github_release.py --kg-version ${RELEASE}'
stage('update dev deployment') {
steps {
sh 'poetry run python scripts/update-dev-solr.py'
Expand Down
74 changes: 74 additions & 0 deletions scripts/create_github_release.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import argparse
import os
import requests
from pathlib import Path


DIR = Path(__file__).parent.parent / "output"
GH_TOKEN = os.environ["GH_RELEASE_TOKEN"]
UPLOAD_FILES = [
"monarch-kg.tar.gz",
"merged_graph_stats.yaml",
"monarch-kg-denormalized-edges.tsv.gz",
"qc_report.yaml",
# "versioning metadata file eventually",
]


def create_release(kg_version: str):
print(f"Creating release for {kg_version}")
response = requests.post(
url="https://api.github.com/repos/monarch-initiative/monarch-ingest/releases",
headers={
"Accept": "application/vnd.github+json",
"Authorization": f"Bearer {GH_TOKEN}",
"X-GitHub-Api-Version": "2022-11-28",
},
json={
"tag_name": kg_version,
"target_commitish": "main",
"name": kg_version,
# "body": "body",
"draft": True,
"prerelease": False,
"generate_release_notes": True,
},
)
if response.status_code != 201:
raise Exception(f"Failed to create release: {response.text}")
release_id = response.json()["id"]
print(f"Release {kg_version} created with id {release_id}")
return release_id


def upload_assets(kg_version: str, release_id: str, files: list):
print(f"\nUploading assets for {kg_version}")
for file in files:
upload_name = file.split("/")[-1]
print(f"Uploading {file} as {upload_name}...")
with open(f"{DIR}/{file}", "rb") as f:
response = requests.post(
url=f"https://uploads.github.com/repos/monarch-initiative/monarch-ingest/releases/{release_id}/assets?name={upload_name}",
headers={
"Accept": "application/vnd.github+json",
"Authorization": f"Bearer {GH_TOKEN}",
"X-GitHub-Api-Version": "2022-11-28",
"Content-Type": "application/octet-stream",
},
data=f,
)
if response.status_code != 201:
raise Exception(f"Failed to upload asset {file}: {response.text}")
print(f"{file} uploaded successfully")


def main(kg_version: str):
release_id = create_release(kg_version)
upload_assets(kg_version, release_id, UPLOAD_FILES)


if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("--kg-version", type=str, help="KG Version to create tag and release for, ex. 2022-11-28")
args = parser.parse_args()
main(args.kg_version)

0 comments on commit 06e03a5

Please sign in to comment.