feat: exclude_assets supports glob patterns (#417)

Related to #163

https://github.com/actions/toolkit/tree/main/packages/glob
This commit is contained in:
Shohei Ueda 2020-07-25 21:54:06 +09:00 committed by GitHub
parent bf46251210
commit 6f45501409
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 36 additions and 17 deletions

17
package-lock.json generated
View File

@ -28,6 +28,15 @@
"@octokit/plugin-rest-endpoint-methods": "^4.0.0" "@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": { "@actions/http-client": {
"version": "1.0.8", "version": "1.0.8",
"resolved": "https://registry.npmjs.org/@actions/http-client/-/http-client-1.0.8.tgz", "resolved": "https://registry.npmjs.org/@actions/http-client/-/http-client-1.0.8.tgz",
@ -1560,8 +1569,7 @@
"balanced-match": { "balanced-match": {
"version": "1.0.0", "version": "1.0.0",
"resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz", "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz",
"integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c=", "integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c="
"dev": true
}, },
"base": { "base": {
"version": "0.11.2", "version": "0.11.2",
@ -1642,7 +1650,6 @@
"version": "1.1.11", "version": "1.1.11",
"resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz",
"integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==",
"dev": true,
"requires": { "requires": {
"balanced-match": "^1.0.0", "balanced-match": "^1.0.0",
"concat-map": "0.0.1" "concat-map": "0.0.1"
@ -1967,8 +1974,7 @@
"concat-map": { "concat-map": {
"version": "0.0.1", "version": "0.0.1",
"resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz",
"integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=", "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s="
"dev": true
}, },
"concat-stream": { "concat-stream": {
"version": "2.0.0", "version": "2.0.0",
@ -6752,7 +6758,6 @@
"version": "3.0.4", "version": "3.0.4",
"resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz", "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz",
"integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==", "integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==",
"dev": true,
"requires": { "requires": {
"brace-expansion": "^1.1.7" "brace-expansion": "^1.1.7"
} }

View File

@ -57,6 +57,7 @@
"@actions/core": "^1.2.4", "@actions/core": "^1.2.4",
"@actions/exec": "^1.0.4", "@actions/exec": "^1.0.4",
"@actions/github": "^4.0.0", "@actions/github": "^4.0.0",
"@actions/glob": "^0.1.0",
"@actions/io": "^1.0.2" "@actions/io": "^1.0.2"
}, },
"devDependencies": { "devDependencies": {

View File

@ -1,6 +1,7 @@
import * as core from '@actions/core'; import * as core from '@actions/core';
import * as exec from '@actions/exec'; import * as exec from '@actions/exec';
import * as io from '@actions/io'; import * as io from '@actions/io';
import * as glob from '@actions/glob';
import path from 'path'; import path from 'path';
import fs from 'fs'; import fs from 'fs';
import {Inputs, CmdResult} from './interfaces'; import {Inputs, CmdResult} from './interfaces';
@ -12,28 +13,38 @@ export async function createBranchForce(branch: string): Promise<void> {
return; return;
} }
export async function deleteExcludedAssets(destDir: string, excludeAssets: string): Promise<void> {
core.info(`[INFO] delete excluded assets`);
const excludedAssetNames: Array<string> = excludeAssets.split(',');
const excludedAssetPaths = ((): Array<string> => {
const paths: Array<string> = [];
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( export async function copyAssets(
publishDir: string, publishDir: string,
destDir: string, destDir: string,
excludeAssets: string excludeAssets: string
): Promise<void> { ): Promise<void> {
core.info(`[INFO] prepare publishing assets`);
const copyOpts = {recursive: true, force: true}; const copyOpts = {recursive: true, force: true};
const files = fs.readdirSync(publishDir); const files = fs.readdirSync(publishDir);
core.debug(`${files}`); core.debug(`${files}`);
for await (const file of files) { for await (const file of files) {
const isExcludeFile = ((): boolean => { if (file === '.git') {
const excludedAssetNames: Array<string> = excludeAssets.split(','); core.info(`[INFO] skip ${file}`);
for (const excludedAssetName of excludedAssetNames) {
if (file === excludedAssetName) {
return true;
}
}
return false;
})();
if (isExcludeFile || file === '.git') {
continue; continue;
} }
const filePublishPath = path.join(publishDir, file); const filePublishPath = path.join(publishDir, file);
const fileDestPath = path.join(destDir, file); const fileDestPath = path.join(destDir, file);
const destPath = path.dirname(fileDestPath); const destPath = path.dirname(fileDestPath);
@ -44,6 +55,8 @@ export async function copyAssets(
core.info(`[INFO] copy ${file}`); core.info(`[INFO] copy ${file}`);
} }
await deleteExcludedAssets(destDir, excludeAssets);
return; return;
} }