Skip to content

Commit 725f7db

Browse files
authored
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
1 parent 46b269e commit 725f7db

File tree

3 files changed

+45
-32
lines changed

3 files changed

+45
-32
lines changed

package-lock.json

Lines changed: 28 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,9 @@
5858
"@actions/exec": "^1.0.4",
5959
"@actions/github": "^4.0.0",
6060
"@actions/glob": "^0.1.0",
61-
"@actions/io": "^1.0.2"
61+
"@actions/io": "^1.0.2",
62+
"@types/shelljs": "^0.8.8",
63+
"shelljs": "^0.8.4"
6264
},
6365
"devDependencies": {
6466
"@types/jest": "^26.0.14",

src/git-utils.ts

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import path from 'path';
66
import fs from 'fs';
77
import {Inputs, CmdResult} from './interfaces';
88
import {createDir} from './utils';
9+
import {cp} from 'shelljs';
910

1011
export async function createBranchForce(branch: string): Promise<void> {
1112
await exec.exec('git', ['init']);
@@ -37,24 +38,21 @@ export async function copyAssets(
3738
excludeAssets: string
3839
): Promise<void> {
3940
core.info(`[INFO] prepare publishing assets`);
40-
const copyOpts = {recursive: true, force: true};
41-
const files = fs.readdirSync(publishDir);
42-
core.debug(`${files}`);
43-
for await (const file of files) {
44-
if (file === '.git') {
45-
core.info(`[INFO] skip ${file}`);
46-
continue;
47-
}
48-
const filePublishPath = path.join(publishDir, file);
49-
const fileDestPath = path.join(destDir, file);
50-
const destPath = path.dirname(fileDestPath);
51-
if (fs.existsSync(destPath) === false) {
52-
await createDir(destPath);
53-
}
54-
core.info(`[INFO] copy ${file}`);
55-
await io.cp(filePublishPath, fileDestPath, copyOpts);
41+
42+
if (fs.existsSync(destDir) === false) {
43+
core.info(`[INFO] create ${destDir}`);
44+
await createDir(destDir);
5645
}
5746

47+
const dotGitPath = path.join(publishDir, '.git');
48+
if (fs.existsSync(dotGitPath)) {
49+
core.info(`[INFO] delete .git`);
50+
io.rmRF(dotGitPath);
51+
}
52+
53+
core.info(`[INFO] copy ${publishDir} to ${destDir}`);
54+
cp('-RfL', [`${publishDir}/*`], destDir);
55+
5856
await deleteExcludedAssets(destDir, excludeAssets);
5957

6058
return;

0 commit comments

Comments
 (0)