Skip to content

Commit 875112b

Browse files
authored
Merge pull request #3395 from cloudflare/ketan/internal-build-workflow
Setup internal CI workflow
2 parents 2c2b2d0 + 59d13bd commit 875112b

File tree

2 files changed

+113
-0
lines changed

2 files changed

+113
-0
lines changed

.github/workflows/internal-build.yml

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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+
if: "! ${{github.event.pull_request.head.repo.fork}}" # Don't run on forks
17+
runs-on: ubuntu-latest
18+
steps:
19+
- uses: actions/checkout@v4
20+
with:
21+
show-progress: false
22+
- name: Run internal build
23+
env:
24+
CI_URL: ${{ secrets.CI_URL }}
25+
CI_CLIENT_ID: ${{ secrets.CI_CF_ACCESS_CLIENT_ID }}
26+
CI_CLIENT_SECRET: ${{ secrets.CI_CF_ACCESS_CLIENT_SECRET }}
27+
run: |
28+
python3 ./tools/cross/internal_build.py \
29+
${{github.event.pull_request.number}} \
30+
${{github.event.pull_request.head.sha}} \
31+
${{github.run_attempt}} \
32+
"${{github.event.pull_request.head.ref}}" \
33+
$CI_URL \
34+
$CI_CLIENT_ID \
35+
$CI_CLIENT_SECRET

tools/cross/internal_build.py

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

0 commit comments

Comments
 (0)