|
1 | 1 | name: TMP Watch Assist screenshots publish |
2 | 2 |
|
3 | 3 | on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - watch-assist-push-to-talk-screenshots |
| 7 | + paths: |
| 8 | + - .github/workflows/tmp_watch_assist_publish.yml |
4 | 9 | workflow_dispatch: |
5 | | - inputs: |
6 | | - run_id: |
7 | | - description: Run id holding the watch-assist-screenshots-2 artifact |
8 | | - required: true |
9 | | - artifact: |
10 | | - description: Artifact name |
11 | | - required: false |
12 | | - default: watch-assist-screenshots-2 |
13 | 10 |
|
14 | 11 | permissions: |
15 | 12 | contents: read |
16 | 13 | actions: read |
17 | 14 |
|
| 15 | +env: |
| 16 | + SOURCE_RUN_ID: "37156491365" |
| 17 | + SOURCE_ARTIFACT: watch-assist-screenshots-2 |
| 18 | + |
18 | 19 | jobs: |
19 | 20 | publish: |
20 | 21 | runs-on: ubuntu-latest |
21 | 22 | timeout-minutes: 10 |
22 | 23 | steps: |
23 | 24 | - uses: actions/download-artifact@v4 |
24 | 25 | with: |
25 | | - name: ${{ inputs.artifact }} |
26 | | - run-id: ${{ inputs.run_id }} |
| 26 | + name: ${{ env.SOURCE_ARTIFACT }} |
| 27 | + run-id: ${{ env.SOURCE_RUN_ID }} |
27 | 28 | github-token: ${{ secrets.GITHUB_TOKEN }} |
28 | 29 | path: artifact |
29 | 30 |
|
30 | 31 | - name: Encode screenshots |
31 | 32 | run: | |
32 | | - ls -laR artifact/screenshots |
33 | | - python3 -c "import PIL" 2>/dev/null || pip install --quiet pillow |
| 33 | + ls -laR artifact |
| 34 | + pip install --quiet pillow |
34 | 35 | python3 - <<'PY' |
35 | | - import base64, hashlib, pathlib, io |
| 36 | + import base64, hashlib, io, pathlib |
36 | 37 | from PIL import Image |
37 | 38 | out = pathlib.Path("encoded"); out.mkdir(exist_ok=True) |
| 39 | + summary = [] |
38 | 40 | for png in sorted(pathlib.Path("artifact/screenshots").glob("*.png")): |
| 41 | + raw = png.read_bytes() |
39 | 42 | im = Image.open(png).convert("RGB") |
40 | | - buf = io.BytesIO(); im.save(buf, "JPEG", quality=80, optimize=True) |
41 | | - data = buf.getvalue() |
42 | | - b64 = base64.b64encode(data).decode() |
| 43 | + for quality in (85, 75, 65, 55, 45): |
| 44 | + buf = io.BytesIO(); im.save(buf, "JPEG", quality=quality, optimize=True) |
| 45 | + b64 = base64.b64encode(buf.getvalue()).decode() |
| 46 | + if len(b64) <= 72000: |
| 47 | + break |
43 | 48 | (out / f"{png.stem}.b64").write_text(b64) |
44 | | - print(png.stem, im.size, len(data), "bytes jpeg", len(b64), "b64", hashlib.sha256(data).hexdigest()[:16]) |
| 49 | + colors = len(set(im.getdata())) |
| 50 | + summary.append(f"{png.stem} size={im.size} png={len(raw)} pngsha={hashlib.sha256(raw).hexdigest()[:12]} colors={colors} jpegq={quality} b64={len(b64)}") |
| 51 | + text = " | ".join(summary) |
| 52 | + print(text) |
| 53 | + print(f"::notice title=img-summary::{text}") |
45 | 54 | PY |
46 | 55 |
|
| 56 | + - name: App logs |
| 57 | + run: | |
| 58 | + for f in artifact/logs/*.log; do |
| 59 | + [ -s "$f" ] || continue |
| 60 | + body=$(tail -c 3000 "$f" | tr '\n' ' ' | tr -d '\r') |
| 61 | + echo "::notice title=applog $(basename "$f")::$body" |
| 62 | + done |
| 63 | +
|
47 | 64 | - name: Annotate idle |
48 | 65 | run: | |
49 | | - f=encoded/idle.b64; [ -e "$f" ] || exit 0 |
50 | | - python3 - "$f" <<'PY' |
| 66 | + python3 - encoded/idle.b64 <<'PY' |
51 | 67 | import sys, zlib, pathlib |
52 | | - p = pathlib.Path(sys.argv[1]); s = p.read_text(); n = 3800 |
| 68 | + p = pathlib.Path(sys.argv[1]) |
| 69 | + if not p.exists(): sys.exit(0) |
| 70 | + s = p.read_text(); n = 8000 |
53 | 71 | chunks = [s[i:i+n] for i in range(0, len(s), n)] |
54 | 72 | for i, c in enumerate(chunks, 1): |
55 | 73 | print(f"::notice title=img {p.stem} {i}/{len(chunks)} crc={zlib.crc32(c.encode()):08x}::{c}") |
56 | 74 | PY |
57 | 75 |
|
58 | 76 | - name: Annotate recording-tap |
59 | 77 | run: | |
60 | | - f=encoded/recording-tap.b64; [ -e "$f" ] || exit 0 |
61 | | - python3 - "$f" <<'PY' |
| 78 | + python3 - encoded/recording-tap.b64 <<'PY' |
62 | 79 | import sys, zlib, pathlib |
63 | | - p = pathlib.Path(sys.argv[1]); s = p.read_text(); n = 3800 |
| 80 | + p = pathlib.Path(sys.argv[1]) |
| 81 | + if not p.exists(): sys.exit(0) |
| 82 | + s = p.read_text(); n = 8000 |
64 | 83 | chunks = [s[i:i+n] for i in range(0, len(s), n)] |
65 | 84 | for i, c in enumerate(chunks, 1): |
66 | 85 | print(f"::notice title=img {p.stem} {i}/{len(chunks)} crc={zlib.crc32(c.encode()):08x}::{c}") |
67 | 86 | PY |
68 | 87 |
|
69 | 88 | - name: Annotate recording-release |
70 | 89 | run: | |
71 | | - f=encoded/recording-release.b64; [ -e "$f" ] || exit 0 |
72 | | - python3 - "$f" <<'PY' |
| 90 | + python3 - encoded/recording-release.b64 <<'PY' |
73 | 91 | import sys, zlib, pathlib |
74 | | - p = pathlib.Path(sys.argv[1]); s = p.read_text(); n = 3800 |
| 92 | + p = pathlib.Path(sys.argv[1]) |
| 93 | + if not p.exists(): sys.exit(0) |
| 94 | + s = p.read_text(); n = 8000 |
75 | 95 | chunks = [s[i:i+n] for i in range(0, len(s), n)] |
76 | 96 | for i, c in enumerate(chunks, 1): |
77 | 97 | print(f"::notice title=img {p.stem} {i}/{len(chunks)} crc={zlib.crc32(c.encode()):08x}::{c}") |
|
0 commit comments