1
1
import * as core from '@actions/core' ;
2
2
import * as exec from '@actions/exec' ;
3
3
import * as io from '@actions/io' ;
4
+ import * as glob from '@actions/glob' ;
4
5
import path from 'path' ;
5
6
import fs from 'fs' ;
6
7
import { Inputs , CmdResult } from './interfaces' ;
@@ -12,28 +13,38 @@ export async function createBranchForce(branch: string): Promise<void> {
12
13
return ;
13
14
}
14
15
16
+ export async function deleteExcludedAssets ( destDir : string , excludeAssets : string ) : Promise < void > {
17
+ core . info ( `[INFO] delete excluded assets` ) ;
18
+ const excludedAssetNames : Array < string > = excludeAssets . split ( ',' ) ;
19
+ const excludedAssetPaths = ( ( ) : Array < string > => {
20
+ const paths : Array < string > = [ ] ;
21
+ for ( const pattern of excludedAssetNames ) {
22
+ paths . push ( path . join ( destDir , pattern ) ) ;
23
+ }
24
+ return paths ;
25
+ } ) ( ) ;
26
+ const globber = await glob . create ( excludedAssetPaths . join ( '\n' ) ) ;
27
+ for await ( const asset of globber . globGenerator ( ) ) {
28
+ io . rmRF ( asset ) ;
29
+ core . info ( `[INFO] delete ${ asset } ` ) ;
30
+ }
31
+ return ;
32
+ }
33
+
15
34
export async function copyAssets (
16
35
publishDir : string ,
17
36
destDir : string ,
18
37
excludeAssets : string
19
38
) : Promise < void > {
39
+ core . info ( `[INFO] prepare publishing assets` ) ;
20
40
const copyOpts = { recursive : true , force : true } ;
21
41
const files = fs . readdirSync ( publishDir ) ;
22
42
core . debug ( `${ files } ` ) ;
23
43
for await ( const file of files ) {
24
- const isExcludeFile = ( ( ) : boolean => {
25
- const excludedAssetNames : Array < string > = excludeAssets . split ( ',' ) ;
26
- for ( const excludedAssetName of excludedAssetNames ) {
27
- if ( file === excludedAssetName ) {
28
- return true ;
29
- }
30
- }
31
- return false ;
32
- } ) ( ) ;
33
- if ( isExcludeFile || file === '.git' ) {
44
+ if ( file === '.git' ) {
45
+ core . info ( `[INFO] skip ${ file } ` ) ;
34
46
continue ;
35
47
}
36
-
37
48
const filePublishPath = path . join ( publishDir , file ) ;
38
49
const fileDestPath = path . join ( destDir , file ) ;
39
50
const destPath = path . dirname ( fileDestPath ) ;
@@ -44,6 +55,8 @@ export async function copyAssets(
44
55
core . info ( `[INFO] copy ${ file } ` ) ;
45
56
}
46
57
58
+ await deleteExcludedAssets ( destDir , excludeAssets ) ;
59
+
47
60
return ;
48
61
}
49
62
0 commit comments