1111from github import Github , GithubException
1212
1313from lib .base_logger import logger
14+ from scripts .release .kubectl_mongodb .python .consts import *
1415
1516GITHUB_TOKEN = os .environ .get ("GH_TOKEN" )
16- GITHUB_REPO = "mongodb/mongodb-kubernetes"
1717
18- AWS_REGION = "eu-north-1"
19-
20- STAGING_S3_BUCKET_NAME = "mongodb-kubernetes-dev"
21- RELEASE_S3_BUCKET_NAME = "mongodb-kubernetes-staging"
22-
23- KUBECTL_PLUGIN_BINARY_NAME = "kubectl-mongodb"
2418S3_BUCKET_KUBECTL_PLUGIN_SUBPATH = KUBECTL_PLUGIN_BINARY_NAME
2519
26- LOCAL_ARTIFACTS_DIR = "artifacts"
27- CHECKSUMS_PATH = f"{ LOCAL_ARTIFACTS_DIR } /checksums.txt"
28-
29-
3020def main ():
3121 parser = argparse .ArgumentParser ()
3222 parser .add_argument (
@@ -51,6 +41,28 @@ def main():
5141
5242 upload_assets_to_github_release (artifacts , args .release_version )
5343
44+ # get_commit_from_tag gets the commit associated with a release tag, so that we can use that
45+ # commit to pull the artifacts from staging bucket.
46+ def get_commit_from_tag (tag : str ) -> str :
47+ try :
48+ subprocess .run (
49+ ["git" , "fetch" , "--tags" ],
50+ capture_output = True ,
51+ text = True ,
52+ check = True
53+ )
54+
55+ result = subprocess .run (
56+ ["git" , "rev-parse" , f"{ tag } ^{{commit}}" ], # git rev-parse v1.1.1^{commit}
57+ capture_output = True ,
58+ text = True ,
59+ check = True
60+ )
61+ return result .stdout .strip ()
62+
63+ except subprocess .CalledProcessError as e :
64+ logger .info (f"Failed to get commit for tag: { tag } , err: { e .stderr .strip ()} " )
65+ sys .exit (1 )
5466
5567# generate_checksums generates checksums for the artifacts that we are going to upload to github release as assets.
5668# It's formatted: checksum artifact_name
@@ -151,20 +163,15 @@ def sign_and_verify_artifacts():
151163 sys .exit (1 )
152164
153165
154- def artifacts_source_dir_s3 (commit_sha : str ):
155- return f"{ S3_BUCKET_KUBECTL_PLUGIN_SUBPATH } /{ commit_sha } /dist/"
156-
157-
158- def artifacts_dest_dir_s3 (release_verion : str ):
159- return f"{ S3_BUCKET_KUBECTL_PLUGIN_SUBPATH } /{ release_verion } /dist/"
160-
161-
162166def s3_artifacts_path_to_local_path (release_version : str , commit_sha : str ):
167+ s3_common_path = f"{ S3_BUCKET_KUBECTL_PLUGIN_SUBPATH } /{ commit_sha } /dist"
163168 return {
164- f"{ S3_BUCKET_KUBECTL_PLUGIN_SUBPATH } /{ commit_sha } /dist/kubectl-mongodb_darwin_amd64_v1/" : f"kubectl-mongodb_{ release_version } _darwin_amd64" ,
165- f"{ S3_BUCKET_KUBECTL_PLUGIN_SUBPATH } /{ commit_sha } /dist/kubectl-mongodb_darwin_arm64/" : f"kubectl-mongodb_{ release_version } _darwin_arm64" ,
166- f"{ S3_BUCKET_KUBECTL_PLUGIN_SUBPATH } /{ commit_sha } /dist/kubectl-mongodb_linux_amd64_v1/" : f"kubectl-mongodb_{ release_version } _linux_amd64" ,
167- f"{ S3_BUCKET_KUBECTL_PLUGIN_SUBPATH } /{ commit_sha } /dist/kubectl-mongodb_linux_arm64/" : f"kubectl-mongodb_{ release_version } _linux_arm64" ,
169+ f"{ s3_common_path } /kubectl-mongodb_darwin_amd64_v1/" : f"kubectl-mongodb_{ release_version } _darwin_amd64" ,
170+ f"{ s3_common_path } /kubectl-mongodb_darwin_arm64/" : f"kubectl-mongodb_{ release_version } _darwin_arm64" ,
171+ f"{ s3_common_path } /kubectl-mongodb_linux_amd64_v1/" : f"kubectl-mongodb_{ release_version } _linux_amd64" ,
172+ f"{ s3_common_path } /kubectl-mongodb_linux_arm64/" : f"kubectl-mongodb_{ release_version } _linux_arm64" ,
173+ f"{ s3_common_path } /kubectl-mongodb_linux_ppc64le/" : f"kubectl-mongodb_{ release_version } _linux_ppc64le" ,
174+ f"{ s3_common_path } /kubectl-mongodb_linux_s390x/" : f"kubectl-mongodb_{ release_version } _linux_s390x" ,
168175 }
169176
170177
0 commit comments