fix(ci): merge origin/updates before push to avoid fetch-first rejection
Release / release (push) Failing after 6m2s

Shallow clone depth 40 (DND_UPDATES_CLONE_DEPTH); fetch+merge before each push attempt.
Release 1.0.9.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Ivan Fontosh
2026-05-12 11:15:33 +08:00
parent 07641be2d2
commit e923de350d
4 changed files with 33 additions and 6 deletions
+24 -3
View File
@@ -14,6 +14,7 @@
* ARTIFACT_LINUX — каталог с файлами Linux (AppImage и т.д.)
* GIT_COMMIT_TAG — опционально, для сообщения коммита
* DND_GIT_PUSH_RETRIES — опционально, число попыток git push (1–5, по умолчанию 3)
* DND_UPDATES_CLONE_DEPTH — опционально, глубина shallow clone (2200, по умолчанию 40), чтобы merge с remote был надёжнее
*/
import { execFileSync } from 'node:child_process';
import fs from 'node:fs';
@@ -76,16 +77,23 @@ function sleepSyncSeconds(seconds) {
}
}
function mergeOriginUpdates(work) {
runGit(['fetch', 'origin', 'updates'], work);
runGit(['merge', '--no-edit', 'origin/updates'], work);
}
function pushUpdatesBranch(work) {
const retries = Math.max(1, Math.min(5, Number.parseInt(process.env.DND_GIT_PUSH_RETRIES || '3', 10) || 3));
let lastError;
for (let attempt = 1; attempt <= retries; attempt += 1) {
try {
console.log(`[sync-update-feed] merge origin/updates before push (attempt ${attempt}/${retries})`);
mergeOriginUpdates(work);
runGit(['push', '-u', 'origin', 'updates'], work);
return;
} catch (err) {
lastError = err;
console.warn(`[sync-update-feed] git push failed (attempt ${attempt}/${retries})`);
console.warn(`[sync-update-feed] merge/push failed (attempt ${attempt}/${retries})`);
if (attempt < retries) {
sleepSyncSeconds(20);
}
@@ -109,10 +117,17 @@ function main() {
const tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'dnd-feed-'));
const work = path.join(tmp, 'repo');
const cloneDepth = Math.max(
2,
Math.min(200, Number.parseInt(process.env.DND_UPDATES_CLONE_DEPTH || '40', 10) || 40),
);
try {
execFileSync('git', ['clone', '--depth', '1', '-b', 'updates', cloneUrl, work], { stdio: 'inherit' });
execFileSync('git', ['clone', `--depth=${String(cloneDepth)}`, '-b', 'updates', cloneUrl, work], {
stdio: 'inherit',
});
} catch {
execFileSync('git', ['clone', '--depth', '1', cloneUrl, work], { stdio: 'inherit' });
execFileSync('git', ['clone', `--depth=${String(cloneDepth)}`, cloneUrl, work], { stdio: 'inherit' });
runGit(['checkout', '-B', 'updates'], work);
}
@@ -120,6 +135,12 @@ function main() {
runGit(['config', 'user.name', 'gitea-actions'], work);
configureGitHttpForLargePush(work);
try {
mergeOriginUpdates(work);
} catch {
console.warn('[sync-update-feed] initial merge skipped (новая ветка или пустой remote)');
}
const copied =
copyFlatReleaseFiles(winDir, work) +
copyFlatReleaseFiles(macDir, work) +