diff --git a/package-lock.json b/package-lock.json index 812a868..d893f2a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -28,6 +28,15 @@ "@octokit/plugin-rest-endpoint-methods": "^4.0.0" } }, + "@actions/glob": { + "version": "0.1.0", + "resolved": "https://registry.npmjs.org/@actions/glob/-/glob-0.1.0.tgz", + "integrity": "sha512-lx8SzyQ2FE9+UUvjqY1f28QbTJv+w8qP7kHHbfQRhphrlcx0Mdmm1tZdGJzfxv1jxREa/sLW4Oy8CbGQKCJySA==", + "requires": { + "@actions/core": "^1.2.0", + "minimatch": "^3.0.4" + } + }, "@actions/http-client": { "version": "1.0.8", "resolved": "https://registry.npmjs.org/@actions/http-client/-/http-client-1.0.8.tgz", @@ -1560,8 +1569,7 @@ "balanced-match": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz", - "integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c=", - "dev": true + "integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c=" }, "base": { "version": "0.11.2", @@ -1642,7 +1650,6 @@ "version": "1.1.11", "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", - "dev": true, "requires": { "balanced-match": "^1.0.0", "concat-map": "0.0.1" @@ -1967,8 +1974,7 @@ "concat-map": { "version": "0.0.1", "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", - "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=", - "dev": true + "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=" }, "concat-stream": { "version": "2.0.0", @@ -6752,7 +6758,6 @@ "version": "3.0.4", "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz", "integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==", - "dev": true, "requires": { "brace-expansion": "^1.1.7" } diff --git a/package.json b/package.json index 9139a00..c758545 100644 --- a/package.json +++ b/package.json @@ -57,6 +57,7 @@ "@actions/core": "^1.2.4", "@actions/exec": "^1.0.4", "@actions/github": "^4.0.0", + "@actions/glob": "^0.1.0", "@actions/io": "^1.0.2" }, "devDependencies": { diff --git a/src/git-utils.ts b/src/git-utils.ts index 2769194..0d9b515 100644 --- a/src/git-utils.ts +++ b/src/git-utils.ts @@ -1,6 +1,7 @@ import * as core from '@actions/core'; import * as exec from '@actions/exec'; import * as io from '@actions/io'; +import * as glob from '@actions/glob'; import path from 'path'; import fs from 'fs'; import {Inputs, CmdResult} from './interfaces'; @@ -12,28 +13,38 @@ export async function createBranchForce(branch: string): Promise { return; } +export async function deleteExcludedAssets(destDir: string, excludeAssets: string): Promise { + core.info(`[INFO] delete excluded assets`); + const excludedAssetNames: Array = excludeAssets.split(','); + const excludedAssetPaths = ((): Array => { + const paths: Array = []; + for (const pattern of excludedAssetNames) { + paths.push(path.join(destDir, pattern)); + } + return paths; + })(); + const globber = await glob.create(excludedAssetPaths.join('\n')); + for await (const asset of globber.globGenerator()) { + io.rmRF(asset); + core.info(`[INFO] delete ${asset}`); + } + return; +} + export async function copyAssets( publishDir: string, destDir: string, 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) { - const isExcludeFile = ((): boolean => { - const excludedAssetNames: Array = excludeAssets.split(','); - for (const excludedAssetName of excludedAssetNames) { - if (file === excludedAssetName) { - return true; - } - } - return false; - })(); - if (isExcludeFile || file === '.git') { + 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); @@ -44,6 +55,8 @@ export async function copyAssets( core.info(`[INFO] copy ${file}`); } + await deleteExcludedAssets(destDir, excludeAssets); + return; }