Skip to content

Commit

Permalink
fix: copyAssets (#512)
Browse files Browse the repository at this point in the history
* deps: Add shelljs @types/shelljs
* fix: copyAssets

use shelljs.cp instead of actions/core/io/cp (io.cp)

- https://github.com/shelljs/shelljs
  • Loading branch information
peaceiris authored Oct 14, 2020
1 parent 46b269e commit 725f7db
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 32 deletions.
43 changes: 28 additions & 15 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
30 changes: 14 additions & 16 deletions src/git-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> {
await exec.exec('git', ['init']);
Expand Down Expand Up @@ -37,24 +38,21 @@ export async function copyAssets(
excludeAssets: string
): Promise<void> {
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;
Expand Down

0 comments on commit 725f7db

Please sign in to comment.