diff --git a/Jenkinsfile b/Jenkinsfile index ccaf9723..58e4fb2a 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -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' diff --git a/scripts/create_github_release.py b/scripts/create_github_release.py new file mode 100644 index 00000000..abcd10a1 --- /dev/null +++ b/scripts/create_github_release.py @@ -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)