Skip to content

Commit 56eece6

Browse files
authored
Use GitHub App to report CI status (#4796)
If this works, we will no longer nee to have a runner waiting for the gitlab ci results. After gitlab finishes the CI, it will use the GitHub App we have installed to post a comment. Note that we will not be able to test it until this is merged.
1 parent 85dcd33 commit 56eece6

File tree

1 file changed

+66
-0
lines changed

1 file changed

+66
-0
lines changed

.gitlab/hpsf-gitlab-ci.yml

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,3 +100,69 @@ Intel-PVC:
100100
- export AMREX_THE_ARENA_INIT_SIZE=1e9
101101
- ctest -j 4 --test-dir build --output-on-failure
102102

103+
post_github_comment:
104+
stage: .post
105+
image: python:3.11-slim
106+
script:
107+
- pip install PyJWT requests cryptography
108+
- |
109+
python3 << 'EOF'
110+
import jwt
111+
import time
112+
import requests
113+
import os
114+
import sys
115+
import base64
116+
117+
# Generate JWT for GitHub App authentication
118+
app_id = os.environ['GITHUB_APP_ID']
119+
payload = {
120+
'iat': int(time.time()),
121+
'exp': int(time.time()) + 600,
122+
'iss': app_id
123+
}
124+
token = jwt.encode(
125+
payload,
126+
base64.b64decode(os.environ['GITHUB_APP_PRIVATE_KEY']).decode('utf-8'),
127+
algorithm='RS256'
128+
)
129+
130+
# Get installation access token
131+
installation_id = os.environ['GITHUB_APP_INSTALLATION_ID']
132+
headers = {
133+
'Authorization': f'Bearer {token}',
134+
'Accept': 'application/vnd.github+json'
135+
}
136+
token_response = requests.post(
137+
f'https://api.github.com/app/installations/{installation_id}/access_tokens',
138+
headers=headers
139+
)
140+
if token_response.status_code != 201:
141+
print(f"Failed to get access token: HTTP {token_response.status_code}")
142+
sys.exit(1)
143+
144+
# Post comment to PR
145+
pr_number = os.environ.get('GITHUB_PR_NUMBER')
146+
pipeline_url = os.environ['CI_PIPELINE_URL']
147+
pipeline_status = os.environ['CI_PIPELINE_STATUS']
148+
149+
comment_body = f"GitLab pipeline [{pipeline_status}]({pipeline_url})"
150+
151+
comment_response = requests.post(
152+
f'https://api.github.com/repos/AMReX-Codes/amrex/issues/{pr_number}/comments',
153+
headers = {
154+
'Authorization': f'Bearer {token_response.json()["token"]}',
155+
'Accept': 'application/vnd.github+json'
156+
},
157+
json={'body': comment_body}
158+
)
159+
del token_response
160+
if comment_response.status_code != 201:
161+
print(f"Failed to post comment: HTTP {comment_response.status_code}")
162+
sys.exit(1)
163+
del comment_response
164+
print("Successfully posted comment to GitHub PR")
165+
EOF
166+
when: always
167+
rules:
168+
- if: $GITHUB_PR_NUMBER

0 commit comments

Comments
 (0)