From 725f7db867bb4bb443f5d8bdffb18297aab5e5a3 Mon Sep 17 00:00:00 2001 From: Shohei Ueda <30958501+peaceiris@users.noreply.github.com> Date: Wed, 14 Oct 2020 18:13:17 +0900 Subject: [PATCH] fix: copyAssets (#512) * deps: Add shelljs @types/shelljs * fix: copyAssets use shelljs.cp instead of actions/core/io/cp (io.cp) - https://github.com/shelljs/shelljs --- package-lock.json | 43 ++++++++++++++++++++++++++++--------------- package.json | 4 +++- src/git-utils.ts | 30 ++++++++++++++---------------- 3 files changed, 45 insertions(+), 32 deletions(-) diff --git a/package-lock.json b/package-lock.json index bfd22e2..f1d5ec1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1212,6 +1212,15 @@ "integrity": "sha512-rr+OQyAjxze7GgWrSaJwydHStIhHq2lvY3BOC2Mj7KnzI7XK0Uw1TOOdI9lDoajEbSWLiYgoo4f1R51erQfhPQ==", "dev": true }, + "@types/glob": { + "version": "7.1.3", + "resolved": "https://registry.npmjs.org/@types/glob/-/glob-7.1.3.tgz", + "integrity": "sha512-SEYeGAIQIQX8NN6LDKprLjbrd5dARM5EXsd8GI/A5l0apYI1fGMWgPHSe4ZKL4eozlAyI+doUE9XbYS4xCkQ1w==", + "requires": { + "@types/minimatch": "*", + "@types/node": "*" + } + }, "@types/graceful-fs": { "version": "4.1.3", "resolved": "https://registry.npmjs.org/@types/graceful-fs/-/graceful-fs-4.1.3.tgz", @@ -1268,6 +1277,11 @@ "integrity": "sha512-8+KAKzEvSUdeo+kmqnKrqgeE+LcA0tjYWFY7RPProVYwnqDjukzO+3b6dLD56rYX5TdWejnEOLJYOIeh4CXKuA==", "dev": true }, + "@types/minimatch": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/@types/minimatch/-/minimatch-3.0.3.tgz", + "integrity": "sha512-tHq6qdbT9U1IRSGf14CL0pUlULksvY9OZ+5eEgl1N7t+OA3tGvNpxJCzuKQlsNgCVwbAs670L1vcVQi8j9HjnA==" + }, "@types/minimist": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/@types/minimist/-/minimist-1.2.0.tgz", @@ -1297,6 +1311,15 @@ "integrity": "sha512-IkVfat549ggtkZUthUzEX49562eGikhSYeVGX97SkMFn+sTZrgRewXjQ4tPKFPCykZHkX1Zfd9OoELGqKU2jJA==", "dev": true }, + "@types/shelljs": { + "version": "0.8.8", + "resolved": "https://registry.npmjs.org/@types/shelljs/-/shelljs-0.8.8.tgz", + "integrity": "sha512-lD3LWdg6j8r0VRBFahJVaxoW0SIcswxKaFUrmKl33RJVeeoNYQAz4uqCJ5Z6v4oIBOsC5GozX+I5SorIKiTcQA==", + "requires": { + "@types/glob": "*", + "@types/node": "*" + } + }, "@types/stack-utils": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/@types/stack-utils/-/stack-utils-2.0.0.tgz", @@ -3500,8 +3523,7 @@ "fs.realpath": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", - "integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=", - "dev": true + "integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=" }, "fsevents": { "version": "2.1.2", @@ -3911,7 +3933,6 @@ "version": "7.1.6", "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.6.tgz", "integrity": "sha512-LwaxwyZ72Lk7vZINtNNrywX0ZuLyStrdDtabefZKAY5ZGJhVtgdznluResxNmPitE0SAO+O26sWTHeKSI2wMBA==", - "dev": true, "requires": { "fs.realpath": "^1.0.0", "inflight": "^1.0.4", @@ -4194,7 +4215,6 @@ "version": "1.0.6", "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", "integrity": "sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk=", - "dev": true, "requires": { "once": "^1.3.0", "wrappy": "1" @@ -4203,8 +4223,7 @@ "inherits": { "version": "2.0.4", "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", - "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==", - "dev": true + "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==" }, "ini": { "version": "1.3.5", @@ -4215,8 +4234,7 @@ "interpret": { "version": "1.4.0", "resolved": "https://registry.npmjs.org/interpret/-/interpret-1.4.0.tgz", - "integrity": "sha512-agE4QfB2Lkp9uICn7BAqoscw4SZP9kTE2hxiFI3jBPmXJfdqiahTbUuKGsMoN2GtqL9AxhYioAcVvgsb1HvRbA==", - "dev": true + "integrity": "sha512-agE4QfB2Lkp9uICn7BAqoscw4SZP9kTE2hxiFI3jBPmXJfdqiahTbUuKGsMoN2GtqL9AxhYioAcVvgsb1HvRbA==" }, "ip-regex": { "version": "2.1.0", @@ -7368,8 +7386,7 @@ "path-is-absolute": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz", - "integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=", - "dev": true + "integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=" }, "path-key": { "version": "2.0.1", @@ -7379,8 +7396,7 @@ "path-parse": { "version": "1.0.6", "resolved": "https://registry.npmjs.org/path-parse/-/path-parse-1.0.6.tgz", - "integrity": "sha512-GSmOT2EbHrINBf9SR7CDELwlJ8AENk3Qn7OikK4nFYAu3Ote2+JYNVvkpAEQm3/TLNEJFD/xZJjzyxg3KBWOzw==", - "dev": true + "integrity": "sha512-GSmOT2EbHrINBf9SR7CDELwlJ8AENk3Qn7OikK4nFYAu3Ote2+JYNVvkpAEQm3/TLNEJFD/xZJjzyxg3KBWOzw==" }, "path-type": { "version": "4.0.0", @@ -7686,7 +7702,6 @@ "version": "0.6.2", "resolved": "https://registry.npmjs.org/rechoir/-/rechoir-0.6.2.tgz", "integrity": "sha1-hSBLVNuoLVdC4oyWdW70OvUOM4Q=", - "dev": true, "requires": { "resolve": "^1.1.6" } @@ -7832,7 +7847,6 @@ "version": "1.15.0", "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.15.0.tgz", "integrity": "sha512-+hTmAldEGE80U2wJJDC1lebb5jWqvTYAfm3YZ1ckk1gBr0MnCqUKlwK1e+anaFljIl+F5tR5IoZcm4ZDA1zMQw==", - "dev": true, "requires": { "path-parse": "^1.0.6" } @@ -8170,7 +8184,6 @@ "version": "0.8.4", "resolved": "https://registry.npmjs.org/shelljs/-/shelljs-0.8.4.tgz", "integrity": "sha512-7gk3UZ9kOfPLIAbslLzyWeGiEqx9e3rxwZM0KE6EL8GlGwjym9Mrlx5/p33bWTu9YG6vcS4MBxYZDHYr5lr8BQ==", - "dev": true, "requires": { "glob": "^7.0.0", "interpret": "^1.0.0", diff --git a/package.json b/package.json index 1783e22..08af6da 100644 --- a/package.json +++ b/package.json @@ -58,7 +58,9 @@ "@actions/exec": "^1.0.4", "@actions/github": "^4.0.0", "@actions/glob": "^0.1.0", - "@actions/io": "^1.0.2" + "@actions/io": "^1.0.2", + "@types/shelljs": "^0.8.8", + "shelljs": "^0.8.4" }, "devDependencies": { "@types/jest": "^26.0.14", diff --git a/src/git-utils.ts b/src/git-utils.ts index 6d417e9..115035f 100644 --- a/src/git-utils.ts +++ b/src/git-utils.ts @@ -6,6 +6,7 @@ import path from 'path'; import fs from 'fs'; import {Inputs, CmdResult} from './interfaces'; import {createDir} from './utils'; +import {cp} from 'shelljs'; export async function createBranchForce(branch: string): Promise { await exec.exec('git', ['init']); @@ -37,24 +38,21 @@ export async function copyAssets( excludeAssets: string ): Promise { core.info(`[INFO] prepare publishing assets`); - const copyOpts = {recursive: true, force: true}; - const files = fs.readdirSync(publishDir); - core.debug(`${files}`); - for await (const file of files) { - if (file === '.git') { - core.info(`[INFO] skip ${file}`); - continue; - } - const filePublishPath = path.join(publishDir, file); - const fileDestPath = path.join(destDir, file); - const destPath = path.dirname(fileDestPath); - if (fs.existsSync(destPath) === false) { - await createDir(destPath); - } - core.info(`[INFO] copy ${file}`); - await io.cp(filePublishPath, fileDestPath, copyOpts); + + if (fs.existsSync(destDir) === false) { + core.info(`[INFO] create ${destDir}`); + await createDir(destDir); } + const dotGitPath = path.join(publishDir, '.git'); + if (fs.existsSync(dotGitPath)) { + core.info(`[INFO] delete .git`); + io.rmRF(dotGitPath); + } + + core.info(`[INFO] copy ${publishDir} to ${destDir}`); + cp('-RfL', [`${publishDir}/*`], destDir); + await deleteExcludedAssets(destDir, excludeAssets); return;