66 python3 scripts/get_deployed_commit.py <environment>
77
88Arguments:
9- environment: One of dev-scale | scale-test | scale-qa
9+ environment: One of dev-scale | scale-test | scale-qa | scale-qa2
1010
1111Environment variables expected:
12- DEV_BASE_URL, TEST_BASE_URL, QA_BASE_URL (from your Azure DevOps variable group)
12+ DEV_BASE_URL, TEST_BASE_URL, QA_BASE_URL, QA2_BASE_URL (from your Azure DevOps variable group)
1313
1414Purpose:
1515 - Determines the correct BASE_URL from the environment.
2222import json
2323import urllib .request
2424
25- REPO_COMMIT_ROOT = 'https://github.com/lantanagroup/link-cloud/commit/'
25+ REPO_COMMITS_API_ROOT = 'https://api.github.com/repos/lantanagroup/link-cloud/commits/'
26+
27+ # urlopen blocks indefinitely by default, which would hang the pipeline job rather than
28+ # fail it. Bound every HTTP call to the same budget.
29+ HTTP_TIMEOUT_SECONDS = 30
2630
2731def fail (msg : str ):
2832 print (f"ERROR: { msg } " , file = sys .stderr )
@@ -43,6 +47,7 @@ def main():
4347 dev_url = os .getenv ("DEV_BASE_URL" , "" )
4448 test_url = os .getenv ("TEST_BASE_URL" , "" )
4549 qa_url = os .getenv ("QA_BASE_URL" , "" )
50+ qa2_url = os .getenv ("QA2_BASE_URL" , "" )
4651
4752 base_url = ""
4853 if input_value .startswith ("https://" ):
@@ -56,12 +61,14 @@ def main():
5661 base_url = test_url
5762 elif environment == "scale-qa" :
5863 base_url = qa_url
64+ elif environment == "scale-qa2" :
65+ base_url = qa2_url
5966 else :
60- fail (f"Unknown environment '{ environment } '. Expected one of: dev-scale | scale-test | scale-qa, or a direct https:// URL" )
67+ fail (f"Unknown environment '{ environment } '. Expected one of: dev-scale | scale-test | scale-qa | scale-qa2 , or a direct https:// URL" )
6168
6269 if not base_url :
6370 fail (f"BASE_URL is empty for environment '{ environment } '. "
64- f"Ensure DEV_BASE_URL / TEST_BASE_URL / QA_BASE_URL are defined." )
71+ f"Ensure DEV_BASE_URL / TEST_BASE_URL / QA_BASE_URL / QA2_BASE_URL are defined." )
6572
6673 print (f"Environment: { environment } " )
6774 print (f"BASE_URL: { base_url } " )
@@ -75,7 +82,7 @@ def main():
7582 info_url ,
7683 headers = {'Accept' : 'application/json' }
7784 )
78- with urllib .request .urlopen (request ) as response :
85+ with urllib .request .urlopen (request , timeout = HTTP_TIMEOUT_SECONDS ) as response :
7986 body = response .read ().decode ("utf-8" )
8087 except Exception as e :
8188 fail (f"Failed to GET { info_url } : { e } " )
@@ -96,20 +103,34 @@ def main():
96103 if not commit :
97104 fail ("Could not find 'Commit' in /api/info response." )
98105
99- # If we got a short hash, try to match it with the full hash from git log
106+ # If we got a short hash, resolve it to the full hash. list-deploy-changes.py fetches both
107+ # refs with 'git fetch origin <ref>', and GitHub only serves unadvertised objects by full SHA.
108+ # The 'sha' media type returns the 40-character hash as plain text.
100109 if len (commit ) < 40 : # Full SHA-1 hash is 40 characters
101110 print (f"Attempting to translate short commit hash { commit } to full commit hash" )
102111 try :
103112 request = urllib .request .Request (
104- f"{ REPO_COMMIT_ROOT } { commit } " ,
105- headers = {'Accept' : 'application/json ' }
113+ f"{ REPO_COMMITS_API_ROOT } { commit } " ,
114+ headers = {'Accept' : 'application/vnd.github.sha ' }
106115 )
107- with urllib .request .urlopen (request ) as response :
108- full_commit_data = json .loads (response .read ().decode ("utf-8" ))
109- commit = full_commit_data .get ('payload' , {}).get ('commit' , {}).get ("sha2" , commit )
116+ with urllib .request .urlopen (request , timeout = HTTP_TIMEOUT_SECONDS ) as response :
117+ full_commit = response .read ().decode ("utf-8" ).strip ()
118+
119+ if len (full_commit ) == 40 :
120+ commit = full_commit
121+ else :
122+ print (f"Warning: Unexpected response resolving full commit hash: '{ full_commit [:100 ]} '" , file = sys .stderr )
110123 except Exception as e :
111124 print (f"Warning: Could not resolve full commit hash: { e } " , file = sys .stderr )
112125
126+ # A short hash breaks the downstream fetch in list-deploy-changes.py: 'git fetch origin
127+ # <ref>' is rejected for anything but a full SHA, and that failure is swallowed, so the
128+ # summary comes out empty with nothing in the log to explain it. Stop here instead of
129+ # publishing a FromCommit that cannot be used.
130+ if len (commit ) < 40 :
131+ fail (f"'{ commit } ' is not a full commit hash and could not be resolved to one. "
132+ f"'git fetch origin { commit } ' would fail and the deployment summary would be empty." )
133+
113134 print (f"FromCommit: { commit } " )
114135
115136 # 5. Emit Azure DevOps logging command
0 commit comments