@cleartrip/frontguard 0.2.7 → 0.2.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.js +141 -41
- package/dist/cli.js.map +1 -1
- package/package.json +1 -1
- package/templates/bitbucket-pipelines.yml +29 -17
- package/templates/freekit-ci-setup.md +2 -2
package/package.json
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
# FrontGuard — PR comment: checks screenshot
|
|
1
|
+
# FrontGuard — PR comment: checks screenshot + FreeKit full report
|
|
2
2
|
#
|
|
3
|
-
# •
|
|
4
|
-
#
|
|
5
|
-
# •
|
|
3
|
+
# • Bitbucket’s PR renderer does NOT load data:image/... (base64) — it shows “Preview unavailable”.
|
|
4
|
+
# This pipeline uploads the PNG to Repository → Downloads, then uses an https://bitbucket.org/.../downloads/... URL in Markdown.
|
|
5
|
+
# • Token must allow: pull request comments AND POST …/downloads (Repositories: write / equivalent API scope).
|
|
6
|
+
# • Raster: @resvg/resvg-js (no browser). Full HTML report → FreeKit; comment links there for details.
|
|
6
7
|
#
|
|
7
|
-
# Secured variable: BITBUCKET_ACCESS_TOKEN —
|
|
8
|
+
# Secured variable: BITBUCKET_ACCESS_TOKEN — comments + downloads upload (see above).
|
|
8
9
|
#
|
|
9
10
|
# Optional: FREEKIT_BASE_URL — override FreeKit API host (default https://freekit.dev).
|
|
10
11
|
#
|
|
@@ -29,7 +30,7 @@ pipelines:
|
|
|
29
30
|
- frontguard-checks.png
|
|
30
31
|
script:
|
|
31
32
|
- corepack enable
|
|
32
|
-
- apt-get update && apt-get install -y --no-install-recommends fonts-dejavu-core
|
|
33
|
+
- apt-get update && apt-get install -y --no-install-recommends fonts-dejavu-core fonts-liberation
|
|
33
34
|
- yarn install --immutable || yarn install
|
|
34
35
|
- |
|
|
35
36
|
yarn frontguard run --markdown \
|
|
@@ -38,16 +39,26 @@ pipelines:
|
|
|
38
39
|
--checksPngOut frontguard-checks.png \
|
|
39
40
|
> frontguard-report.md
|
|
40
41
|
- |
|
|
42
|
+
test -n "${BITBUCKET_ACCESS_TOKEN:-}" || { echo "Missing secured var BITBUCKET_ACCESS_TOKEN"; exit 1; }
|
|
43
|
+
BB_PNG_NAME="frontguard-checks-pipeline-${BITBUCKET_BUILD_NUMBER}-pr-${BITBUCKET_PR_ID}.png"
|
|
44
|
+
cp frontguard-checks.png "${BB_PNG_NAME}"
|
|
45
|
+
if curl --silent --show-error --fail --request POST \
|
|
46
|
+
--url "https://api.bitbucket.org/2.0/repositories/${BITBUCKET_REPO_FULL_NAME}/downloads" \
|
|
47
|
+
--header "Authorization: Bearer ${BITBUCKET_ACCESS_TOKEN}" \
|
|
48
|
+
--form "files=@${BB_PNG_NAME}"; then
|
|
49
|
+
export FRONTGUARD_CHECKS_IMAGE_URL="https://bitbucket.org/${BITBUCKET_REPO_FULL_NAME}/downloads/${BB_PNG_NAME}"
|
|
50
|
+
echo "Uploaded checks PNG to Downloads; image URL set for PR comment."
|
|
51
|
+
else
|
|
52
|
+
echo "WARNING: Downloads upload failed (token needs repository write for uploads). PR comment will not include an inline image."
|
|
53
|
+
export FRONTGUARD_CHECKS_IMAGE_URL=""
|
|
54
|
+
fi
|
|
41
55
|
python3 << 'PY'
|
|
42
|
-
import base64
|
|
43
56
|
import json
|
|
44
57
|
import os
|
|
45
58
|
from urllib.error import HTTPError
|
|
46
59
|
from urllib.request import Request, urlopen
|
|
47
60
|
|
|
48
61
|
DETAILED = "For detailed check analysis, please open the full interactive report:"
|
|
49
|
-
# Keep in sync with src/lib/bitbucket-checks-image-md.ts (markdown line length cap).
|
|
50
|
-
MAX_IMAGE_LINE = 300_000
|
|
51
62
|
PNG_SIG = bytes([0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A])
|
|
52
63
|
|
|
53
64
|
base = os.environ.get("FREEKIT_BASE_URL", "https://freekit.dev").rstrip("/")
|
|
@@ -80,13 +91,15 @@ pipelines:
|
|
|
80
91
|
raw = f.read()
|
|
81
92
|
if len(raw) < 8 or raw[:8] != PNG_SIG:
|
|
82
93
|
raise SystemExit("frontguard-checks.png is missing or not a valid PNG file.")
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
94
|
+
|
|
95
|
+
img_url = (os.environ.get("FRONTGUARD_CHECKS_IMAGE_URL") or "").strip()
|
|
96
|
+
if img_url:
|
|
97
|
+
# Bitbucket PR comments: only normal https:// URLs render; data: URIs show “Preview unavailable”.
|
|
98
|
+
img_line = f""
|
|
99
|
+
else:
|
|
100
|
+
img_line = (
|
|
101
|
+
"_Checks summary image: open **Pipeline artifacts** (`frontguard-checks.png`) "
|
|
102
|
+
"or grant the pipeline token permission to **upload to Repository → Downloads**._"
|
|
90
103
|
)
|
|
91
104
|
|
|
92
105
|
body = f"{img_line}\n\n{DETAILED}\n{report_url}\n"
|
|
@@ -96,7 +109,6 @@ pipelines:
|
|
|
96
109
|
json.dump({"content": {"raw": body}}, out, ensure_ascii=False)
|
|
97
110
|
PY
|
|
98
111
|
- |
|
|
99
|
-
test -n "${BITBUCKET_ACCESS_TOKEN:-}" || { echo "Missing secured var BITBUCKET_ACCESS_TOKEN"; exit 1; }
|
|
100
112
|
curl --silent --show-error --fail --request POST \
|
|
101
113
|
--url "https://api.bitbucket.org/2.0/repositories/${BITBUCKET_REPO_FULL_NAME}/pullrequests/${BITBUCKET_PR_ID}/comments" \
|
|
102
114
|
--header 'Accept: application/json' \
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# FreeKit.dev + FrontGuard (Bitbucket Pipelines)
|
|
2
2
|
|
|
3
|
-
The Bitbucket template
|
|
3
|
+
The Bitbucket template runs FrontGuard with **`--checksPngOut`** (SVG → PNG via **`@resvg/resvg-js`**), uploads the full HTML to **FreeKit**, **uploads the checks PNG to Repository → Downloads**, and posts a PR comment with **``** plus the FreeKit URL. Bitbucket does **not** render `data:image/...` in PR comments (you get “Preview unavailable”), so the template uses an HTTPS Downloads link instead. **`BITBUCKET_ACCESS_TOKEN`** must allow **PR comments** and **POST** to **`/2.0/repositories/{workspace}/{repo}/downloads`** (Repositories write / equivalent).
|
|
4
4
|
|
|
5
5
|
The same step uploads `frontguard-report.html` to FreeKit’s public API:
|
|
6
6
|
|
|
@@ -26,7 +26,7 @@ On **Bitbucket Pipelines** pull-request builds, FrontGuard reads **`BITBUCKET_PR
|
|
|
26
26
|
|
|
27
27
|
## Checks table image in PR comments
|
|
28
28
|
|
|
29
|
-
The
|
|
29
|
+
The pipeline writes **`frontguard-checks.png`**, uploads it via the Downloads API, and references that **HTTPS** URL in Markdown. If the upload fails (token scope), the comment falls back to text pointing at pipeline artifacts. You can still set **`FRONTGUARD_CHECKS_IMAGE_URL`** before a custom comment step if you host the PNG elsewhere.
|
|
30
30
|
|
|
31
31
|
## Compared to Surge
|
|
32
32
|
|