From 91ab82c4e6d05931ab63e2098f903f226e6088f7 Mon Sep 17 00:00:00 2001 From: Kei Okada Date: Wed, 29 Jan 2025 17:39:01 +0900 Subject: [PATCH] git add/commit/push every 500M file, to cope with 2.0G limit of ssh git push --- action/dist/index.js | 85 ++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 78 insertions(+), 7 deletions(-) diff --git a/action/dist/index.js b/action/dist/index.js index 1ee824c5..b3347245 100644 --- a/action/dist/index.js +++ b/action/dist/index.js @@ -414,18 +414,89 @@ const main = async ({ env = process.env, log, }) => { recursive: true, copySourceDirectory: false, }); - await (0, exports.exec)(`git add -A .`, { log, env: childEnv, cwd: REPO_TEMP }); - const message = config.message - .replace(/\{target\-branch\}/g, config.branch) - .replace(/\{sha\}/g, gitInfo.sha.substr(0, 7)) - .replace(/\{long\-sha\}/g, gitInfo.sha) - .replace(/\{msg\}/g, gitInfo.commitMessage); + + // Get all files + const Path = require("path"); + const FS = require("fs"); + let Files = []; + function ThroughDirectory(Directory) { + FS.readdirSync(Directory).forEach(File => { + const Absolute = Path.join(Directory, File); + const Stat = FS.statSync(Absolute); + if (Directory === '.git') return Files; + else if (Stat.isDirectory()) return ThroughDirectory(Absolute); + else return Files.push({filename: Absolute, size: Stat.size}); + }); + } + ThroughDirectory(REPO_TEMP); + // Sort by size + Files.sort(function(first, second) { + if ( first.size > second.size ){ + return -1; + }else{ + return 1; + } + }); + // add, commit and push every 500M + let FilesSplitted = []; + let filesSize = 0; + let filesTmp = []; + while ( Files.length ) { + let file = Files.pop(); + await (0, exports.exec)(`git add -A ${file.filename}`, { log, env: childEnv, cwd: REPO_TEMP }); + if ( filesSize + file.size < 500000000 ) { + filesSize += file.size; + filesTmp.push(file.filename); + } else { + let files_length = filesTmp.length; + let files_size = (filesSize + file.size)/1000000; + log.log("##[into] %d files are selected, total size is %d M", files_length, files_size); + const message = 'Update {target-branch} to output generated at {sha}, add {length} files with a total size of {size} MB.' + .replace(/\{target\-branch\}/g, config.branch) + .replace(/\{sha\}/g, gitInfo.sha.substr(0, 7)) + .replace(/\{long\-sha\}/g, gitInfo.sha) + .replace(/\{msg\}/g, gitInfo.commitMessage) + .replace(/\{length\}/g, files_length) + .replace(/\{size\}/g, files_size); + await isomorphic_git_1.default.commit({ + fs: fs_1.default, + dir: REPO_TEMP, + message, + author: { email, name }, + }); + if ( FilesSplitted.length > 0) { + const forceArg = config.squashHistory ? '-f' : ''; + const push = await (0, exports.exec)(`git push ${forceArg} origin "${config.branch}"`, { log, env: childEnv, cwd: REPO_TEMP }); + log.log(push.stdout); + } + // update FilesSplitted + FilesSplitted.push(filesTmp); + filesTmp = [file.filename]; + filesSize = file.size; + } + } + FilesSplitted.push(filesTmp); + let files_length = filesTmp.length; + let files_size = (filesSize)/1000000; + log.log("##[into] %d files are selected, total size is %d M", files_length, files_size); + const message = 'Update {target-branch} to output generated at {sha}, add {length} files with a total size of {size} MB.' + .replace(/\{target\-branch\}/g, config.branch) + .replace(/\{sha\}/g, gitInfo.sha.substr(0, 7)) + .replace(/\{long\-sha\}/g, gitInfo.sha) + .replace(/\{msg\}/g, gitInfo.commitMessage) + .replace(/\{length\}/g, files_length) + .replace(/\{size\}/g, files_size); await isomorphic_git_1.default.commit({ fs: fs_1.default, dir: REPO_TEMP, message, author: { email, name }, }); + if ( FilesSplitted.length > 0) { + const forceArg = config.squashHistory ? '-f' : ''; + const push = await (0, exports.exec)(`git push ${forceArg} origin "${config.branch}"`, { log, env: childEnv, cwd: REPO_TEMP }); + log.log(push.stdout); + } if (tag) { log.log(`##[info] Tagging commit with ${tag}`); await isomorphic_git_1.default.tag({ @@ -32175,4 +32246,4 @@ const _1 = __nccwpck_require__(9726); module.exports = __webpack_exports__; /******/ })() -; \ No newline at end of file +;