fix(推送觸發 CI): 合併 push-token 進 token,findings 一律以 token 認證推送觸發 CI
- 移除 push-token input,token 兼作 Gitea API 認證與 findings 推送
- commitAndPushFindings 一律以 token 明確認證推送(不走 origin 自動 token);
只要 token 為能觸發 CI 的 PAT,結果 commit 即再觸發 PR 的 CI,避免新 head 缺檢查卡合併
- ci.yaml 三個 job 移除 push-token,保留 token: ${{ secrets.TOKEN }}
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.8
parent
9e6e8bb793
commit
05178be520
+8
-18
@@ -223,9 +223,9 @@ function fileLastUpdatedIso(cwd, file) {
|
||||
* 若目前 HEAD 不在 PR head commit(例如 checkout 停在 merge commit),
|
||||
* 會先 `git checkout --detach <headSha>` 站上 head,避免把 merge 內容推回來源分支。
|
||||
* commit 以 `-c` 臨時覆寫 user.name / user.email,不改動 repo 的 git 設定。
|
||||
* push 策略:提供 `pushToken`(PAT)時直接以該 token 的 URL 推送(略過 origin)——因為 origin
|
||||
* 帶的是不會再觸發 CI 的自動 token,改以 PAT 身分推送才會讓 PR 的 synchronize 事件再觸發 CI;
|
||||
* 未提供 `pushToken` 時先走 origin,失敗(遠端未帶認證)再改用帶 `token` 的 URL 重試。
|
||||
* push 策略:一律以 `token` 的身分明確認證推送({@link pushWithCredential},不走 runner 的
|
||||
* origin 自動 token)——origin 帶的自動 token(gitea.token / GITHUB_TOKEN)推送不會再觸發 CI,
|
||||
* 改以呼叫端提供的 `token`(建議為 PAT)身分推送,才會讓 PR 的 synchronize 事件再觸發 CI。
|
||||
*
|
||||
* @param {string} cwd - git 工作目錄(repo 的 checkout 路徑)。
|
||||
* @param {object} options - 提交與推送設定。
|
||||
@@ -233,8 +233,7 @@ function fileLastUpdatedIso(cwd, file) {
|
||||
* @param {string} [options.headSha] - PR head 的 commit SHA;有提供且與目前 HEAD 不同時會先 detach 到此 commit。可省略(falsy 時不 detach,直接於目前 HEAD 上 commit)。
|
||||
* @param {string} options.message - commit 訊息。
|
||||
* @param {string[]} options.files - 要加入 commit 的檔案路徑清單(相對 repo 根目錄);全數無實際變更時不 commit、回傳 false。
|
||||
* @param {string} options.token - 具該 repo push 權限的 Gitea access token;未提供 pushToken 時,於 origin push 失敗才用於組出帶認證的重試 URL。
|
||||
* @param {string} [options.pushToken] - 專用推送 token(PAT);提供時直接以此 token 的 URL 推送(略過 origin),使 push 以 PAT 身分進行以再觸發 CI;未提供時走 origin、失敗再退回 `token`。
|
||||
* @param {string} options.token - 具該 repo push 權限的 Gitea access token(建議為能觸發 CI 的 PAT);用於 findings commit 的認證推送。
|
||||
* @param {string} options.serverUrl - Gitea 伺服器根網址(例如 https://gitea.example.com),須為合法 URL。
|
||||
* @param {string} options.repository - repo 完整名稱(owner/repo 格式),與 serverUrl 組成 clone URL。
|
||||
* @returns {boolean} true=有變更且已 commit 並 push 到來源分支;false=暫存區與 HEAD 無差異,略過 commit/push。
|
||||
@@ -249,7 +248,7 @@ function fileLastUpdatedIso(cwd, file) {
|
||||
* 推送目標 URL 本身不含帳密;且 push 失敗時改拋固定訊息,避免 `execFileSync`
|
||||
* 例外把命令列(含 token)回顯到 CI log 或程序清單。
|
||||
*/
|
||||
function commitAndPushFindings(cwd, { headRef, headSha, message, files, token, pushToken, serverUrl, repository }) {
|
||||
function commitAndPushFindings(cwd, { headRef, headSha, message, files, token, serverUrl, repository }) {
|
||||
const current = gitTrim(cwd, 'rev-parse', 'HEAD');
|
||||
if (headSha && current !== headSha) {
|
||||
git(cwd, 'checkout', '--detach', headSha);
|
||||
@@ -269,18 +268,9 @@ function commitAndPushFindings(cwd, { headRef, headSha, message, files, token, p
|
||||
);
|
||||
const refspec = `HEAD:refs/heads/${headRef}`;
|
||||
const remoteUrl = `${serverUrl}/${repository}.git`;
|
||||
if (pushToken) {
|
||||
// 有專用 PAT → 以 PAT 推送(略過 origin,因 origin 帶的是不會再觸發 CI 的自動 token);
|
||||
// 以 PAT 身分推送才會讓 PR 的 synchronize 事件再觸發 CI。
|
||||
pushWithCredential(cwd, remoteUrl, pushToken, refspec);
|
||||
} else {
|
||||
try {
|
||||
git(cwd, 'push', 'origin', refspec);
|
||||
} catch {
|
||||
// 遠端未帶認證(checkout 未保留 credentials)時,改用帶認證的推送重試。
|
||||
pushWithCredential(cwd, remoteUrl, token, refspec);
|
||||
}
|
||||
}
|
||||
// 一律以 token 的身分明確認證推送(不走 origin 的自動 token)——只要 token 是能觸發 CI 的 PAT,
|
||||
// 結果 commit 就會讓 PR 的 synchronize 事件再觸發 CI,由步驟 1 快速回報把結果蓋到新 head。
|
||||
pushWithCredential(cwd, remoteUrl, token, refspec);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user