|
1 | 1 | #!/usr/bin/env python3 |
2 | 2 | """Post (or update) a sticky preview comment on the GitHub PR for this pipeline. |
3 | 3 |
|
4 | | -Runs in GitLab CI after the preview/upload jobs so every link it posts is already |
5 | | -live. Currently surfaces the per-branch mobile Dev Tool OTA preview (QR + deep |
6 | | -link); each preview is a section, so web/coverage/etc. can be appended as the |
7 | | -pipeline grows. No-ops (exit 0) when there is no token or no open PR, so it never |
8 | | -turns a pipeline red. |
| 4 | +Runs in GitLab CI after the upload jobs so every link it posts is already live. |
| 5 | +Each preview is a section, so web/coverage/etc. can be appended as the pipeline |
| 6 | +grows. The mobile QR PNG is generated and uploaded by the OTA build/upload jobs; |
| 7 | +this script only assembles markdown and talks to the GitHub API. No-ops (exit 0) |
| 8 | +when there is no token or no open PR, so it never turns a pipeline red. |
9 | 9 | """ |
10 | 10 |
|
11 | | -import io |
12 | 11 | import os |
13 | 12 | import sys |
14 | 13 | import urllib.parse |
15 | 14 |
|
16 | | -import boto3 |
17 | | -import qrcode |
18 | 15 | import requests |
19 | 16 |
|
20 | 17 | MARKER = "<!-- couchers-preview-bot -->" |
@@ -42,39 +39,21 @@ def deep_link(manifest_url): |
42 | 39 | ) |
43 | 40 |
|
44 | 41 |
|
45 | | -def make_qr_png(data): |
46 | | - qr = qrcode.QRCode( |
47 | | - border=2, box_size=8, error_correction=qrcode.constants.ERROR_CORRECT_M |
48 | | - ) |
49 | | - qr.add_data(data) |
50 | | - qr.make(fit=True) |
51 | | - buf = io.BytesIO() |
52 | | - qr.make_image(fill_color="black", back_color="white").save(buf, format="PNG") |
53 | | - return buf.getvalue() |
54 | | - |
55 | | - |
56 | | -def mobile_ota_section(s3, bucket, short_sha, domain, platforms): |
| 42 | +def mobile_ota_section(short_sha, domain, platforms): |
57 | 43 | lines = [ |
58 | 44 | "### Mobile Dev Tool preview", |
59 | 45 | "", |
60 | 46 | "Scan with your phone camera (or tap the deep link on the device) to open this " |
61 | 47 | "branch in the installed **Dev Tool** dev client.", |
62 | 48 | ] |
63 | 49 | for platform in platforms: |
64 | | - manifest_url = f"https://{short_sha}--ota.{domain}/{platform}/manifest" |
65 | | - link = deep_link(manifest_url) |
66 | | - s3.put_object( |
67 | | - Bucket=bucket, |
68 | | - Key=f"ota/{short_sha}/{platform}/qr.png", |
69 | | - Body=make_qr_png(link), |
70 | | - ContentType="image/png", |
71 | | - ) |
72 | | - qr_url = f"https://{short_sha}--ota.{domain}/{platform}/qr.png" |
| 50 | + base = f"https://{short_sha}--ota.{domain}/{platform}" |
| 51 | + link = deep_link(f"{base}/manifest") |
73 | 52 | lines += [ |
74 | 53 | "", |
75 | 54 | f"**{platform}**", |
76 | 55 | "", |
77 | | - f'<img src="{qr_url}" alt="QR to open the {platform} build" width="180" height="180" />', |
| 56 | + f'<img src="{base}/qr.png" alt="QR to open the {platform} build" width="180" height="180" />', |
78 | 57 | "", |
79 | 58 | "<details><summary>Deep link</summary>", |
80 | 59 | "", |
@@ -154,10 +133,7 @@ def main(): |
154 | 133 | print(f"No open PR for {sha} - skipping preview comment.") |
155 | 134 | return |
156 | 135 |
|
157 | | - s3 = boto3.client("s3") |
158 | | - bucket = env("AWS_PREVIEW_BUCKET", required=True) |
159 | | - |
160 | | - sections = [mobile_ota_section(s3, bucket, short_sha, domain, platforms)] |
| 136 | + sections = [mobile_ota_section(short_sha, domain, platforms)] |
161 | 137 | url = upsert_comment(repo, pr, build_body(sections, sha, pipeline_url), token) |
162 | 138 | print(f"Posted preview comment to PR #{pr}: {url}") |
163 | 139 |
|
|
0 commit comments