Skip to content

Commit 2221255

Browse files
committed
Setup internal CI workflow
1 parent e35b547 commit 2221255

File tree

2 files changed

+105
-0
lines changed

2 files changed

+105
-0
lines changed

.github/workflows/internal-build.yml

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: Run internal build
2+
3+
on:
4+
pull_request:
5+
paths-ignore:
6+
- 'doc/**'
7+
8+
concurrency:
9+
# Cancel existing builds for the same PR.
10+
# Otherwise, all other builds will be allowed to run through.
11+
group: internal-build.yml-${{ github.event.pull_request.number || github.run_id }}
12+
cancel-in-progress: true
13+
14+
jobs:
15+
internal-build:
16+
runs-on: ubuntu-latest
17+
steps:
18+
- uses: actions/checkout@v4
19+
with:
20+
show-progress: false
21+
- name: Run internal build
22+
env:
23+
CI_URL: ${{ secrets.CI_URL }}
24+
CI_CLIENT_ID: ${{ secrets.CI_CF_ACCESS_CLIENT_ID }}
25+
CI_CLIENT_SECRET: ${{ secrets.CI_CF_ACCESS_CLIENT_SECRET }}
26+
run: |
27+
python3 ./tools/cross/internal_build.py \
28+
${{github.event.pull_request.id}} \
29+
${{github.event.pull_request.head.sha}} \
30+
$GITHUB_RUN_ATTEMPT \
31+
"${{github.event.pull_request.head.ref}}" \
32+
$CI_URL \
33+
$CI_CLIENT_ID \
34+
$CI_CLIENT_SECRET

tools/cross/internal_build.py

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
import argparse
2+
import requests
3+
import time
4+
import sys
5+
6+
def parse_args():
7+
parser = argparse.ArgumentParser()
8+
9+
parser.add_argument("pr_id", help="Pull Request ID")
10+
parser.add_argument("sha", help="Commit SHA")
11+
parser.add_argument("run_attempt", help="# of Run Attempt")
12+
parser.add_argument("branch_name", help="PR's Branch Name")
13+
parser.add_argument("URL", help="URL to submit build task")
14+
parser.add_argument("client_id", help="CF Access client id")
15+
parser.add_argument("secret", help="CF Access client secret")
16+
17+
return parser.parse_args()
18+
19+
if __name__ == "__main__":
20+
args = parse_args()
21+
22+
# Submit build job
23+
headers = {
24+
"CF-Access-Client-Id": args.client_id,
25+
"CF-Access-Client-Secret": args.secret
26+
}
27+
28+
payload = {
29+
"pr_id": args.pr_id,
30+
"commit_sha": args.sha,
31+
"run_attempt": args.run_attempt,
32+
"branch_name": args.branch_name
33+
}
34+
35+
workflow_id = ''
36+
try:
37+
resp = requests.post(args.URL, headers=headers, json=payload)
38+
resp.raise_for_status()
39+
40+
workflow_id = resp.json().id
41+
except Exception as err:
42+
print(f"Unexpected error {err=}, {type(err)=}")
43+
sys.exit(1)
44+
45+
time.sleep(30)
46+
47+
# Poll build status
48+
failed_requests = 0
49+
FAILED_REQUEST_LIMIT = 10
50+
51+
while failed_requests < FAILED_REQUEST_LIMIT:
52+
try:
53+
resp = requests.get(args.URL, headers=headers, params={ 'id': workflow_id })
54+
resp.raise_for_status()
55+
56+
status = resp.json().status
57+
if status == "errored":
58+
sys.exit(1)
59+
elif status == "complete":
60+
break
61+
62+
except Exception as err:
63+
print(f"Unexpected error {err=}, {type(err)=}")
64+
failed_requests = failed_requests + 1
65+
time.sleep(30)
66+
67+
if failed_requests == FAILED_REQUEST_LIMIT:
68+
sys.exit(1)
69+
70+
print("Internal build succeeded")
71+

0 commit comments

Comments
 (0)