@@ -15,19 +15,21 @@ const path_1 = require("path");
15
15
const github_action_helper_1 = require ( "@technote-space/github-action-helper" ) ;
16
16
const github_action_log_helper_1 = require ( "@technote-space/github-action-log-helper" ) ;
17
17
const misc_1 = require ( "./misc" ) ;
18
- exports . replaceDirectory = ( context ) => ( message ) => {
18
+ const replaceDirectory = ( context ) => ( message ) => {
19
19
const directories = misc_1 . getReplaceDirectory ( context ) ;
20
20
return Object . keys ( directories ) . reduce ( ( value , directory ) => github_action_helper_1 . Utils . replaceAll ( github_action_helper_1 . Utils . replaceAll ( value , ` -C ${ directory } ` , '' ) , directory , directories [ directory ] ) , message ) ;
21
21
} ;
22
- exports . prepareFiles = ( logger , helper , context ) => __awaiter ( void 0 , void 0 , void 0 , function * ( ) {
22
+ exports . replaceDirectory = replaceDirectory ;
23
+ const prepareFiles = ( logger , helper , context ) => __awaiter ( void 0 , void 0 , void 0 , function * ( ) {
23
24
const { buildDir, pushDir } = misc_1 . getParams ( context ) ;
24
25
fs_1 . mkdirSync ( buildDir , { recursive : true } ) ;
25
26
logger . startProcess ( 'Cloning the remote repo for build...' ) ;
26
27
yield helper . checkout ( buildDir , context ) ;
27
28
logger . startProcess ( 'Running build for release...' ) ;
28
29
yield helper . runCommand ( buildDir , misc_1 . getBuildCommands ( buildDir , pushDir ) ) ;
29
30
} ) ;
30
- exports . createBuildInfoFile = ( logger , context ) => __awaiter ( void 0 , void 0 , void 0 , function * ( ) {
31
+ exports . prepareFiles = prepareFiles ;
32
+ const createBuildInfoFile = ( logger , context ) => __awaiter ( void 0 , void 0 , void 0 , function * ( ) {
31
33
const filename = misc_1 . getOutputBuildInfoFilename ( ) ;
32
34
if ( ! filename ) {
33
35
return ;
@@ -50,14 +52,16 @@ exports.createBuildInfoFile = (logger, context) => __awaiter(void 0, void 0, voi
50
52
'updated_at' : ( new Date ) . toISOString ( ) ,
51
53
} ) ) ;
52
54
} ) ;
53
- exports . clone = ( logger , helper , context ) => __awaiter ( void 0 , void 0 , void 0 , function * ( ) {
55
+ exports . createBuildInfoFile = createBuildInfoFile ;
56
+ const clone = ( logger , helper , context ) => __awaiter ( void 0 , void 0 , void 0 , function * ( ) {
54
57
const { pushDir, branchName } = misc_1 . getParams ( context ) ;
55
58
logger . startProcess ( 'Fetching...' ) ;
56
59
yield helper . fetchOrigin ( pushDir , context , [ '--no-tags' ] , [ github_action_helper_1 . Utils . getRefspec ( branchName ) ] ) ;
57
60
logger . startProcess ( 'Switching branch to [%s]...' , branchName ) ;
58
61
yield helper . switchBranch ( pushDir , branchName ) ;
59
62
} ) ;
60
- exports . checkBranch = ( clonedBranch , logger , helper , context ) => __awaiter ( void 0 , void 0 , void 0 , function * ( ) {
63
+ exports . clone = clone ;
64
+ const checkBranch = ( clonedBranch , logger , helper , context ) => __awaiter ( void 0 , void 0 , void 0 , function * ( ) {
61
65
const { pushDir, branchName } = misc_1 . getParams ( context ) ;
62
66
if ( branchName !== clonedBranch ) {
63
67
logger . info ( 'remote branch %s not found.' , branchName ) ;
@@ -66,22 +70,26 @@ exports.checkBranch = (clonedBranch, logger, helper, context) => __awaiter(void
66
70
yield helper . gitInit ( pushDir , branchName ) ;
67
71
}
68
72
} ) ;
69
- exports . config = ( logger , helper , context ) => __awaiter ( void 0 , void 0 , void 0 , function * ( ) {
73
+ exports . checkBranch = checkBranch ;
74
+ const config = ( logger , helper , context ) => __awaiter ( void 0 , void 0 , void 0 , function * ( ) {
70
75
const { pushDir } = misc_1 . getParams ( context ) ;
71
76
const name = misc_1 . getCommitName ( ) ;
72
77
const email = misc_1 . getCommitEmail ( ) ;
73
78
logger . startProcess ( 'Configuring git committer to be %s <%s>...' , name , email ) ;
74
79
yield helper . config ( pushDir , name , email ) ;
75
80
} ) ;
76
- exports . commit = ( helper , context ) => __awaiter ( void 0 , void 0 , void 0 , function * ( ) { return helper . commit ( misc_1 . getParams ( context ) . pushDir , misc_1 . getCommitMessage ( ) , { allowEmpty : true } ) ; } ) ;
77
- exports . getDeleteTestTag = ( tagName , prefix , helper , context ) => __awaiter ( void 0 , void 0 , void 0 , function * ( ) {
81
+ exports . config = config ;
82
+ const commit = ( helper , context ) => __awaiter ( void 0 , void 0 , void 0 , function * ( ) { return helper . commit ( misc_1 . getParams ( context ) . pushDir , misc_1 . getCommitMessage ( ) , { allowEmpty : true } ) ; } ) ;
83
+ exports . commit = commit ;
84
+ const getDeleteTestTag = ( tagName , prefix , helper , context ) => __awaiter ( void 0 , void 0 , void 0 , function * ( ) {
78
85
return ( yield helper . getTags ( misc_1 . getParams ( context ) . pushDir , { quiet : true } ) )
79
86
. filter ( tag => github_action_helper_1 . Utils . getPrefixRegExp ( prefix ) . test ( tag ) )
80
87
. map ( tag => tag . replace ( github_action_helper_1 . Utils . getPrefixRegExp ( prefix ) , '' ) )
81
88
. filter ( tag => github_action_helper_1 . Utils . versionCompare ( tag , tagName , false ) < 0 ) // eslint-disable-line no-magic-numbers
82
89
. map ( tag => `${ prefix } ${ tag } ` ) ;
83
90
} ) ;
84
- exports . deleteTestTags = ( helper , context ) => __awaiter ( void 0 , void 0 , void 0 , function * ( ) {
91
+ exports . getDeleteTestTag = getDeleteTestTag ;
92
+ const deleteTestTags = ( helper , context ) => __awaiter ( void 0 , void 0 , void 0 , function * ( ) {
85
93
const { pushDir, tagName } = misc_1 . getParams ( context ) ;
86
94
if ( ! misc_1 . isTestTag ( tagName ) && misc_1 . isEnabledCleanTestTag ( ) ) {
87
95
const prefixForTestTag = misc_1 . getTestTagPrefix ( ) ;
@@ -94,7 +102,8 @@ exports.deleteTestTags = (helper, context) => __awaiter(void 0, void 0, void 0,
94
102
}
95
103
}
96
104
} ) ;
97
- exports . push = ( logger , helper , context ) => __awaiter ( void 0 , void 0 , void 0 , function * ( ) {
105
+ exports . deleteTestTags = deleteTestTags ;
106
+ const push = ( logger , helper , context ) => __awaiter ( void 0 , void 0 , void 0 , function * ( ) {
98
107
const { pushDir, branchName, tagName, branchNames } = misc_1 . getParams ( context ) ;
99
108
logger . startProcess ( 'Pushing to %s@%s (tag: %s)...' , github_action_helper_1 . ContextHelper . getRepository ( context ) , branchName , tagName ) ;
100
109
const prefixForOriginalTag = misc_1 . getOriginalTagPrefix ( ) ;
@@ -115,6 +124,7 @@ exports.push = (logger, helper, context) => __awaiter(void 0, void 0, void 0, fu
115
124
yield helper . forcePush ( pushDir , branch , context ) ;
116
125
} ) , Promise . resolve ( ) ) ;
117
126
} ) ;
127
+ exports . push = push ;
118
128
const findRelease = ( octokit , context ) => __awaiter ( void 0 , void 0 , void 0 , function * ( ) {
119
129
const { tagName } = misc_1 . getParams ( context ) ;
120
130
const releases = yield octokit . repos . listReleases ( {
@@ -123,7 +133,7 @@ const findRelease = (octokit, context) => __awaiter(void 0, void 0, void 0, func
123
133
} ) ;
124
134
return releases . data . find ( release => release . tag_name === tagName ) ;
125
135
} ) ;
126
- exports . updateRelease = ( release , logger , octokit , context ) => __awaiter ( void 0 , void 0 , void 0 , function * ( ) {
136
+ const updateRelease = ( release , logger , octokit , context ) => __awaiter ( void 0 , void 0 , void 0 , function * ( ) {
127
137
if ( ! release || release . draft ) {
128
138
return ;
129
139
}
@@ -135,29 +145,32 @@ exports.updateRelease = (release, logger, octokit, context) => __awaiter(void 0,
135
145
draft : false ,
136
146
} ) ;
137
147
} ) ;
138
- exports . copyFiles = ( logger , command , context ) => __awaiter ( void 0 , void 0 , void 0 , function * ( ) {
148
+ exports . updateRelease = updateRelease ;
149
+ const copyFiles = ( logger , command , context ) => __awaiter ( void 0 , void 0 , void 0 , function * ( ) {
139
150
const { buildDir, pushDir } = misc_1 . getParams ( context ) ;
140
151
logger . startProcess ( 'Copying %s contents to %s...' , buildDir , pushDir ) ;
141
152
yield command . execAsync ( {
142
153
command : 'rsync' ,
143
154
args : [ '-rl' , '--exclude' , '.git' , '--delete' , `${ buildDir } /` , pushDir ] ,
144
155
} ) ;
145
156
} ) ;
146
- exports . prepareCommit = ( logger , command , helper , context ) => __awaiter ( void 0 , void 0 , void 0 , function * ( ) {
157
+ exports . copyFiles = copyFiles ;
158
+ const prepareCommit = ( logger , command , helper , context ) => __awaiter ( void 0 , void 0 , void 0 , function * ( ) {
147
159
yield exports . clone ( logger , helper , context ) ;
148
160
yield exports . checkBranch ( yield helper . getCurrentBranchName ( misc_1 . getParams ( context ) . pushDir ) , logger , helper , context ) ;
149
161
yield exports . prepareFiles ( logger , helper , context ) ;
150
162
yield exports . createBuildInfoFile ( logger , context ) ;
151
163
yield exports . copyFiles ( logger , command , context ) ;
152
164
} ) ;
165
+ exports . prepareCommit = prepareCommit ;
153
166
const executeCommit = ( release , logger , helper , octokit , context ) => __awaiter ( void 0 , void 0 , void 0 , function * ( ) {
154
167
yield exports . config ( logger , helper , context ) ;
155
168
yield exports . commit ( helper , context ) ;
156
169
yield exports . push ( logger , helper , context ) ;
157
170
yield exports . updateRelease ( release , logger , octokit , context ) ;
158
171
return true ;
159
172
} ) ;
160
- exports . deploy = ( octokit , context ) => __awaiter ( void 0 , void 0 , void 0 , function * ( ) {
173
+ const deploy = ( octokit , context ) => __awaiter ( void 0 , void 0 , void 0 , function * ( ) {
161
174
const logger = new github_action_log_helper_1 . Logger ( exports . replaceDirectory ( context ) ) ;
162
175
const command = new github_action_helper_1 . Command ( logger ) ;
163
176
const { branchName } = misc_1 . getParams ( context ) ;
@@ -167,3 +180,4 @@ exports.deploy = (octokit, context) => __awaiter(void 0, void 0, void 0, functio
167
180
yield exports . prepareCommit ( logger , command , helper , context ) ;
168
181
yield executeCommit ( release , logger , helper , octokit , context ) ;
169
182
} ) ;
183
+ exports . deploy = deploy ;
0 commit comments