gh-actions-build-trigger
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseGH Actions build trigger
GH Actions 构建触发
When a repo has several workflows (e.g. an APK workflow and an AAB workflow),
they do not behave the same. Know each one's auto-trigger and paths
filter before pushing:
| Workflow | Auto-trigger on push | Paths filter |
|---|---|---|
| ✅ every push to | often none |
| ✅ push to | often only app source paths (app/, components/, db/, hooks/, lib/, plugins/, types/, assets/, app.json, package*.json, patches/) — NOT |
Check the actual / in each workflow file — don't
assume.
paths:paths-ignore:当仓库拥有多个工作流(例如APK工作流和AAB工作流)时,它们的行为并不一致。推送代码前,请了解每个工作流的自动触发规则和路径过滤设置:
| 工作流 | 推送至main时自动触发 | 路径过滤 |
|---|---|---|
| ✅ 每次推送至 | 通常无过滤 |
| ✅ 推送至 | 通常仅包含应用源码路径(app/, components/, db/, hooks/, lib/, plugins/, types/, assets/, app.json, package*.json, patches/)——不包含 |
请查看每个工作流文件中的实际 / 配置,不要凭假设判断。
paths:paths-ignore:Steps
操作步骤
1. Decide which workflow(s) the request needs
1. 确定需求对应的工作流
APK for sideloading/testing, AAB for Play Store. If the user asks for one,
cancel the other — pushing to may trigger both (the no-filter
workflow always runs). Never let a build the user did not ask for burn runner
time.
mainAPK用于侧载/测试,AAB用于Google Play商店。如果用户只需要其中一种,取消另一种——推送至分支可能会同时触发两个工作流(无路径过滤的工作流总会运行)。不要让用户不需要的构建占用运行器资源。
main2. Check whether a push will trigger the workflow
2. 检查推送是否会触发工作流
A push that touches only (workflow files, etc.) does NOT
trigger a workflow whose paths filter omits . Pushing a
workflow-file-only commit will still trigger a workflow with no filter.
For the filtered workflow in that case, use a manual dispatch (step 3)
instead of expecting the push to fire it.
.github/**.github/**如果推送仅修改了**目录(如工作流文件等),那么路径过滤中排除的工作流不会被触发**。仅修改工作流文件的提交仍会触发无路径过滤的工作流。对于有路径过滤的工作流,这种情况下需要使用手动调度(步骤3),而不是等待推送触发。
.github/**.github/**3. Trigger (manual dispatch when needed)
3. 触发工作流(必要时手动调度)
bash
curl -s -o /dev/null -w "dispatch: HTTP %{http_code}\n" -X POST \
-H "Authorization: Bearer $GH_TOKEN" -H "Accept: application/vnd.github+json" \
"https://api.github.com/repos/<owner>/<repo>/actions/workflows/<workflow-file>.yml/dispatches" \
-d '{"ref":"main"}'204bash
curl -s -o /dev/null -w "dispatch: HTTP %{http_code}\n" -X POST \
-H "Authorization: Bearer $GH_TOKEN" -H "Accept: application/vnd.github+json" \
"https://api.github.com/repos/<owner>/<repo>/actions/workflows/<workflow-file>.yml/dispatches" \
-d '{"ref":"main"}'返回表示请求已接受。调度(或推送)后,运行任务可能需要几秒才会出现在API中——推送后立即查询可能返回空列表。请等待约5-10秒后重新查询,再判断“未触发任何任务”(这是典型的竞态条件问题)。
2044. Monitor the run
4. 监控运行状态
bash
curl -s -H "Authorization: Bearer $GH_TOKEN" -H "Accept: application/vnd.github+json" \
"https://api.github.com/repos/<owner>/<repo>/actions/runs?per_page=5" \
| node -e "const d=JSON.parse(require('fs').readFileSync(0,'utf8')); for (const r of d.workflow_runs||[]) console.log(r.id, r.name, r.head_sha.slice(0,7), r.status, r.conclusion, r.event)"conclusion: nullbash
JOB_ID=$(curl -s -H "Authorization: Bearer $GH_TOKEN" -H "Accept: application/vnd.github+json" \
"https://api.github.com/repos/<owner>/<repo>/actions/runs/$RUN_ID/jobs" \
| node -e "console.log(JSON.parse(require('fs').readFileSync(0,'utf8')).jobs[0].id)")
curl -sL -H "Authorization: Bearer $GH_TOKEN" \
"https://api.github.com/repos/<owner>/<repo>/actions/jobs/$JOB_ID/logs" -o /tmp/job.logThen grep the log for the failing step (e.g. or look
for / ).
grep -B2 -A12 "error"##[error]Process completed with exit code 1bash
curl -s -H "Authorization: Bearer $GH_TOKEN" -H "Accept: application/vnd.github+json" \
"https://api.github.com/repos/<owner>/<repo>/actions/runs?per_page=5" \
| node -e "const d=JSON.parse(require('fs').readFileSync(0,'utf8')); for (const r of d.workflow_runs||[]) console.log(r.id, r.name, r.head_sha.slice(0,7), r.status, r.conclusion, r.event)"运行中时的值为。如果运行失败,拉取作业日志:
conclusionnullbash
JOB_ID=$(curl -s -H "Authorization: Bearer $GH_TOKEN" -H "Accept: application/vnd.github+json" \
"https://api.github.com/repos/<owner>/<repo>/actions/runs/$RUN_ID/jobs" \
| node -e "console.log(JSON.parse(require('fs').readFileSync(0,'utf8')).jobs[0].id)")
curl -sL -H "Authorization: Bearer $GH_TOKEN" \
"https://api.github.com/repos/<owner>/<repo>/actions/jobs/$JOB_ID/logs" -o /tmp/job.log然后在日志中搜索失败步骤(例如使用,或查找 / )。
grep -B2 -A12 "error"##[error]Process completed with exit code 15. Cancel an unneeded parallel run
5. 取消不需要的并行运行任务
bash
curl -s -o /dev/null -w "cancel: HTTP %{http_code}\n" -X POST \
-H "Authorization: Bearer $GH_TOKEN" -H "Accept: application/vnd.github+json" \
"https://api.github.com/repos/<owner>/<repo>/actions/runs/$RUN_ID/cancel"202Completion criterion: the correct workflow(s) for the request are running on
the intended commit, unneeded parallel runs are cancelled, and you know the
run ID + URL to report. If a build failed, you can name the failing step and
the error.
bash
curl -s -o /dev/null -w "cancel: HTTP %{http_code}\n" -X POST \
-H "Authorization: Bearer $GH_TOKEN" -H "Accept: application/vnd.github+json" \
"https://api.github.com/repos/<owner>/<repo>/actions/runs/$RUN_ID/cancel"返回表示请求已接受。注意:取消操作是异步的——运行任务可能要等运行器检测到后才会显示为“已取消”。
202完成标准:需求对应的工作流在指定提交上运行,不需要的并行任务已取消,并且你已获取运行ID和报告链接。如果构建失败,你能指出失败步骤和错误信息。
Reference
参考信息
- Token: a is provided per session; export it as
gh_tokenand never write it into files/commits.GH_TOKEN - Artifacts are uploaded by ; the artifact name and path are declared in the workflow's upload step.
actions/upload-artifact@v4 - First build on a fresh runner takes ~15–25 min; cached ones are faster.
- 令牌:每个会话会提供;请将其导出为
gh_token,切勿写入文件或提交中。GH_TOKEN - 产物由上传;产物名称和路径在工作流的上传步骤中声明。
actions/upload-artifact@v4 - 全新运行器上的首次构建需约15-25分钟;使用缓存的构建速度更快。