website-ci-gate
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseWebsite CI Gate
网站 CI 质量门禁
Add a squirrelscan check to CI so a pull request, a preview deploy or a release fails when the site gets worse: a score below a threshold, an error-severity finding, or findings that are new since the last audit.
This skill writes pipeline config and picks thresholds from a real baseline. It does not fix findings; use for that.
audit-website将 squirrelscan 检查添加到 CI,使 pull request、预览部署或发布在网站状况变差时失败:评分低于阈值、出现错误严重级别的发现项,或出现相较上次审计新增的发现项。
此 skill 负责编写流水线配置,并基于真实基线选择阈值。它不会修复发现项;如需修复,请使用 。
audit-websiteBefore the first audit
首次审计之前
Run . If it fails, install the CLI from squirrelscan.com/download (the skill has ). Then run :
squirrel --versionsquirrelscanreferences/install.mdsquirrel auth status- Signed out, or : the audit runs on this machine, is free, and nothing is published.
--offline - Signed in: the audit is billed in credits (50 plus 2 per audited page, plus 1 per distinct external link the cloud verifies), adds the site to the user's dashboard, can turn on recurring audits and publishes an unlisted report. Tell the user the cost () and get a yes. Offer
squirrel creditsor--offline. For a site the user does not own, add--no-publish: nothing is added to the dashboard, scheduled or published.--ephemeral
Every flag below is checked against the squirrel CLI docs (https://docs.squirrelscan.com/cli/audit). Rule docs: .
https://docs.squirrelscan.com/rules/{category}/{rule_id}CI runners are signed out unless is set. A signed-out audit runs deterministic rules for free; an audit signed in with an org API key pays no audit or page charge, checks external links from the runner for free, and bills only cloud renders (2 credits per rendered page; renders nothing). Keep the key in the CI secret store, never in the repo.
SQUIRRELSCAN_API_KEY--http运行 。如果运行失败,请从 squirrelscan.com/download 安装 CLI( skill 中提供了 )。然后运行 :
squirrel --versionsquirrelscanreferences/install.mdsquirrel auth status- 未登录或使用 :审计将在本机运行,免费执行,且不会发布任何内容。
--offline - 已登录:审计将按 credits 计费(基础费用 50 credits,每个受审页面 2 credits,云端验证的每个不同外部链接再加 1 credits),并会将站点添加到用户的 dashboard,可能启用定期审计,还会发布一份非公开报告。告知用户费用()并获得用户确认。可以提供
squirrel credits或--offline作为替代方案。对于用户不拥有的站点,请添加--no-publish:不会将站点添加到 dashboard、建立定期审计或发布报告。--ephemeral
以下每个 flag 均已根据 squirrel CLI 文档(https://docs.squirrelscan.com/cli/audit)进行核对。规则文档:`https://docs.squirrelscan.com/rules/{category}/{rule_id}`。
除非设置了 ,否则 CI runner 处于未登录状态。未登录的审计会免费运行确定性规则;使用组织 API key 登录的审计不收取审计或页面费用,可从 runner 免费检查外部链接,仅对云端渲染计费(每个渲染页面 2 credits; 不会进行任何渲染)。请将 key 保存在 CI secret store 中,切勿放入仓库。
SQUIRRELSCAN_API_KEY--httpStep 1: find the baseline
第 1 步:查找基线
Run once locally and read the scores:
bash
squirrel audit https://staging.example.com --level quick --format json -o baseline.jsonChoose thresholds the site passes today. A gate that is red on day one gets turned off. Tighten later.
在本地运行一次并查看评分:
bash
squirrel audit https://staging.example.com --level quick --format json -o baseline.json选择网站当前能够通过的阈值。第一天就显示为红色的门禁很快会被关闭。之后可以逐步收紧阈值。
Step 2: pick the gate
第 2 步:选择门禁规则
--fail-on<>bash
squirrel audit "$URL" --level quick --format json -o report.json \
--fail-on 'score<85' --fail-on 'score:perf<70' --fail-on 'severity>=error'| Expression | Trips when |
|---|---|
| overall health score is below N |
| a category score is below N, for example |
| any error-severity finding |
| any warning-severity finding (also counts a security rule that timed out) |
To fail only on findings that are new since the last audit, use a cloud audit of the website: (needs an org API key with and scopes in ; the first audit of a website exits 0 with no baseline).
squirrel ci <url> --website <id> --fail-on-new erroraudits:readaudits:writeSQUIRRELSCAN_API_KEYNarrow what runs with (for example ) and silence a rule that does not apply with or a waived in . A narrowed run is partial and its score is not comparable to a full audit's.
--rule-includesecurity,links--rule-exclude[[ignore]]squirrel.toml--fail-on<>bash
squirrel audit "$URL" --level quick --format json -o report.json \
--fail-on 'score<85' --fail-on 'score:perf<70' --fail-on 'severity>=error'| 表达式 | 触发条件 |
|---|---|
| 总体健康评分低于 N |
| 某个分类的评分低于 N,例如 |
| 存在任意错误严重级别的发现项 |
| 存在任意警告严重级别的发现项(也包括超时的安全规则) |
如果只想在相较上次审计新增的发现项上失败,请使用网站的云审计:(需要在 中使用具备 和 权限范围的组织 API key;网站的首次审计会以 0 退出,此时尚无基线)。
squirrel ci <url> --website <id> --fail-on-new errorSQUIRRELSCAN_API_KEYaudits:readaudits:write使用 缩小运行范围(例如 ),并使用 或 中被豁免的 忽略不适用的规则。缩小范围后的运行属于部分审计,其评分不能与完整审计的评分直接比较。
--rule-includesecurity,links--rule-excludesquirrel.toml[[ignore]]Step 3: exit codes
第 3 步:退出码
| Code | Meaning | Pipeline |
|---|---|---|
| Ran, every threshold passed | pass |
| A threshold tripped | fail the job |
| Operational error: bad flags, a crash, a site that answered with an error | fail, and read the message |
| The page was blocked by a WAF or bot manager: nothing was audited | fail or alert, never pass |
| The start URL redirected to another site | fail: fix the URL |
| The start URL could not be reached | fail: the preview may not be up yet |
A step that only treats as failure will pass on , and . Let the job fail on any non-zero exit.
2345| 代码 | 含义 | 流水线处理 |
|---|---|---|
| 已运行,所有阈值均通过 | 通过 |
| 触发了某个阈值 | 令 job 失败 |
| 操作错误:flag 无效、程序崩溃或站点返回错误 | 失败,并查看错误信息 |
| 页面被 WAF 或 bot manager 拦截,未执行任何审计 | 失败或告警,绝不能通过 |
| 起始 URL 重定向到了其他站点 | 失败:修复 URL |
| 无法访问起始 URL | 失败:预览环境可能尚未启动 |
如果某个步骤仅将 视为失败,那么退出码为 、 和 时仍会通过。应让 job 在任何非零退出码下都失败。
2345Step 4: write the workflow (show the diff first)
第 4 步:编写工作流(先展示 diff)
Prefer the official action on GitHub:
yaml
name: Site audit
on: [pull_request]
jobs:
audit:
runs-on: ubuntu-latest
steps:
- uses: squirrelscan/audit-action@v1
with:
url: https://staging.example.com
fail-on: "score<85,severity>=error"
token: ${{ secrets.SQUIRRELSCAN_API_KEY }} # optionalWithout the action:
yaml
- run: |
curl -fsSL --connect-timeout 10 --max-time 120 https://install.squirrelscan.com | bash
echo "$HOME/.local/bin" >> "$GITHUB_PATH"
- run: squirrel audit "$URL" --level quick --fail-on 'score<85' --fail-on 'severity>=error'
env:
URL: https://staging.example.com
SQUIRRELSCAN_API_KEY: ${{ secrets.SQUIRRELSCAN_API_KEY }}GitLab: the same two commands in with as a masked variable. Preview deploys (Vercel, Netlify, Cloudflare Pages): audit the preview URL the platform gives the job (for example on a trigger), after the deploy is ready. For a deploy-time audit of the deployed URL, avoids a cached crawl.
script:SQUIRRELSCAN_API_KEYgithub.event.deployment_status.environment_urldeployment_status--refreshDo not edit existing workflow files without showing the user the diff, and do not add secrets yourself: tell the user which secret to create.
在 GitHub 上优先使用官方 Action:
yaml
name: Site audit
on: [pull_request]
jobs:
audit:
runs-on: ubuntu-latest
steps:
- uses: squirrelscan/audit-action@v1
with:
url: https://staging.example.com
fail-on: "score<85,severity>=error"
token: ${{ secrets.SQUIRRELSCAN_API_KEY }} # optional不使用 Action 时:
yaml
- run: |
curl -fsSL --connect-timeout 10 --max-time 120 https://install.squirrelscan.com | bash
echo "$HOME/.local/bin" >> "$GITHUB_PATH"
- run: squirrel audit "$URL" --level quick --fail-on 'score<85' --fail-on 'severity>=error'
env:
URL: https://staging.example.com
SQUIRRELSCAN_API_KEY: ${{ secrets.SQUIRRELSCAN_API_KEY }}GitLab:将同样的两条命令放入 ,并将 设置为 masked variable。预览部署(Vercel、Netlify、Cloudflare Pages):在部署就绪后,审计平台提供给 job 的预览 URL(例如在 触发器中使用 )。如果要在部署时审计已部署的 URL,使用 可避免使用缓存的抓取结果。
script:SQUIRRELSCAN_API_KEYdeployment_statusgithub.event.deployment_status.environment_url--refresh未经展示 diff,不要直接修改现有工作流文件;也不要自行添加 secret:请告知用户需要创建哪个 secret。
Stop condition
停止条件
Stop when the job is green on the current main, and the user has seen it go red on a deliberate regression (ask before pushing a throwaway branch). Document the thresholds and why in the repo, next to the workflow.
当当前 main 分支上的 job 为绿色,并且用户已看到任务在故意引入回归后变红时停止(推送临时分支前先询问用户)。在仓库中、工作流旁边记录阈值及其设置原因。
Hand off
后续处理
Fixing what the gate finds: , or the topic skills (, , , ).
audit-websitesecurity-auditseo-auditperformance-auditaccessibility-audit修复门禁发现的问题:使用 ,或相关主题 skill(、、、)。
audit-websitesecurity-auditseo-auditperformance-auditaccessibility-audit