@@ -9,158 +9,158 @@ const os = require("os");
9
9
let PERL ;
10
10
11
11
async function install_cpm_location ( ) {
12
- let out = "" ;
12
+ let out = "" ;
13
13
14
- const options = { } ;
15
- options . listeners = {
16
- stdout : ( data ) => {
17
- out += data . toString ( ) ;
18
- } ,
19
- } ;
14
+ const options = { } ;
15
+ options . listeners = {
16
+ stdout : ( data ) => {
17
+ out += data . toString ( ) ;
18
+ } ,
19
+ } ;
20
20
21
- let p = core . getInput ( "path" ) ;
22
- p . replace ( "\\" , "\\\\" ) ;
23
- await exec . exec ( PERL , [ "-MConfig" , "-e" , `print "${ p } "` ] , options ) ;
21
+ let p = core . getInput ( "path" ) ;
22
+ p . replace ( "\\" , "\\\\" ) ;
23
+ await exec . exec ( PERL , [ "-MConfig" , "-e" , `print "${ p } "` ] , options ) ;
24
24
25
- return path . resolve ( out ) ;
25
+ return path . resolve ( out ) ;
26
26
}
27
27
28
28
async function install_cpm ( install_to ) {
29
- const version = core . getInput ( "version" ) ;
30
- const url = `https://raw.githubusercontent.com/skaji/cpm/${ version } /cpm` ;
29
+ const version = core . getInput ( "version" ) ;
30
+ const url = `https://raw.githubusercontent.com/skaji/cpm/${ version } /cpm` ;
31
31
32
- core . info ( `Get cpm from URL: ${ url } ` ) ;
32
+ core . info ( `Get cpm from URL: ${ url } ` ) ;
33
33
34
- const cpmScript = await tc . downloadTool ( url ) ;
34
+ const cpmScript = await tc . downloadTool ( url ) ;
35
35
36
- core . info ( `Install cpm to: ${ install_to } ` ) ;
36
+ core . info ( `Install cpm to: ${ install_to } ` ) ;
37
37
38
- const platform = os . platform ( ) ;
38
+ const platform = os . platform ( ) ;
39
39
40
- if ( platform == "win32" ) {
41
- await io . cp ( cpmScript , install_to ) ;
42
- } else {
43
- await do_exec ( [
44
- PERL ,
45
- "-MFile::Copy=cp" ,
46
- "-e" ,
47
- `cp("${ cpmScript } ", "${ install_to } "); chmod(0755, "${ install_to } ")` ,
48
- ] ) ;
49
- }
40
+ if ( platform == "win32" ) {
41
+ await io . cp ( cpmScript , install_to ) ;
42
+ } else {
43
+ await do_exec ( [
44
+ PERL ,
45
+ "-MFile::Copy=cp" ,
46
+ "-e" ,
47
+ `cp("${ cpmScript } ", "${ install_to } "); chmod(0755, "${ install_to } ")` ,
48
+ ] ) ;
49
+ }
50
50
51
- return install_to ;
51
+ return install_to ;
52
52
}
53
53
54
54
async function which_perl ( ) {
55
- const perl = core . getInput ( "perl" ) ;
56
- if ( perl == "perl" ) {
57
- return await io . which ( "perl" , true ) ;
58
- }
59
- return perl ;
55
+ const perl = core . getInput ( "perl" ) ;
56
+ if ( perl == "perl" ) {
57
+ return await io . which ( "perl" , true ) ;
58
+ }
59
+ return perl ;
60
60
}
61
61
62
62
function is_true ( b ) {
63
- if ( b !== null && ( b === true || b == "true" || b == "1" || b == "ok" ) ) {
64
- return true ;
65
- }
63
+ if ( b !== null && ( b === true || b == "true" || b == "1" || b == "ok" ) ) {
64
+ return true ;
65
+ }
66
66
67
- return false ;
67
+ return false ;
68
68
}
69
69
70
70
async function do_exec ( cmd ) {
71
- const sudo = is_true ( core . getInput ( "sudo" ) ) ;
72
- const platform = os . platform ( ) ;
73
- const bin = sudo && platform != "win32" ? "sudo" : cmd . shift ( ) ;
71
+ const sudo = is_true ( core . getInput ( "sudo" ) ) ;
72
+ const platform = os . platform ( ) ;
73
+ const bin = sudo && platform != "win32" ? "sudo" : cmd . shift ( ) ;
74
74
75
- core . info ( `do_exec: ${ bin } ` ) ;
75
+ core . info ( `do_exec: ${ bin } ` ) ;
76
76
77
- await exec . exec ( bin , cmd ) ;
77
+ await exec . exec ( bin , cmd ) ;
78
78
}
79
79
80
80
async function run ( ) {
81
- PERL = await which_perl ( ) ;
82
-
83
- const cpm_location = await install_cpm_location ( ) ;
84
-
85
- await install_cpm ( cpm_location ) ;
86
-
87
- // input arguments
88
- const install = core . getInput ( "install" ) ;
89
- const cpanfile = core . getInput ( "cpanfile" ) ;
90
- const tests = core . getInput ( "tests" ) ;
91
- const dash_g = core . getInput ( "global" ) ;
92
- const args = core . getInput ( "args" ) ;
93
- const verbose = core . getInput ( "verbose" ) ;
94
-
95
- const w_tests = is_true ( tests ) ? "--test" : "--no-test" ;
96
- let w_args = [ ] ;
97
-
98
- if ( args !== null && args . length ) {
99
- w_args = args . split ( / \s + / ) ;
100
- }
101
-
102
- /* base CMD_install command */
103
- let CMD_install = [
104
- PERL ,
105
- cpm_location ,
106
- "install" ,
107
- "--show-build-log-on-failure" ,
108
- w_tests ,
109
- ] ;
110
-
111
- if ( is_true ( verbose ) ) {
112
- CMD_install . push ( "-v" ) ;
113
- }
114
- if ( is_true ( dash_g ) ) {
115
- CMD_install . push ( "-g" ) ;
116
- }
117
- if ( w_args . length ) {
118
- CMD_install = CMD_install . concat ( w_args ) ;
119
- }
120
-
121
- let has_run = false ;
122
-
123
- /* install one ore more modules */
124
- if ( install !== null && install . length ) {
125
- // install one or more modules
126
- core . info ( `install: ${ install } !` ) ;
127
- const list = install . split ( "\n" ) ;
128
-
129
- let cmd = [ ...CMD_install ] ; /* clone array */
130
- cmd = cmd . concat ( list ) ;
131
-
132
- has_run = true ;
133
- await do_exec ( cmd ) ;
134
- }
135
-
136
- /* install from cpanfile */
137
- if ( cpanfile !== null && cpanfile . length ) {
138
- // install one or more modules
139
- core . info ( `cpanfile: ${ cpanfile } !` ) ;
140
- const cpanfile_full_path = path . resolve ( cpanfile ) ;
141
- core . info ( `cpanfile: ${ cpanfile_full_path } ! [resolved]` ) ;
142
-
143
- let cmd = [ ...CMD_install ] ;
144
- cmd . push ( "--cpanfile" , cpanfile_full_path ) ;
145
-
146
- has_run = true ;
147
- await do_exec ( cmd ) ;
148
- }
149
-
150
- /* custom run with args */
151
- if ( has_run === false && w_args . length ) {
152
- core . info ( `custom run with args` ) ;
153
- let cmd = [ ...CMD_install ] ;
154
- has_run = true ;
155
- await do_exec ( cmd ) ;
156
- }
81
+ PERL = await which_perl ( ) ;
82
+
83
+ const cpm_location = await install_cpm_location ( ) ;
84
+
85
+ await install_cpm ( cpm_location ) ;
86
+
87
+ // input arguments
88
+ const install = core . getInput ( "install" ) ;
89
+ const cpanfile = core . getInput ( "cpanfile" ) ;
90
+ const tests = core . getInput ( "tests" ) ;
91
+ const dash_g = core . getInput ( "global" ) ;
92
+ const args = core . getInput ( "args" ) ;
93
+ const verbose = core . getInput ( "verbose" ) ;
94
+
95
+ const w_tests = is_true ( tests ) ? "--test" : "--no-test" ;
96
+ let w_args = [ ] ;
97
+
98
+ if ( args !== null && args . length ) {
99
+ w_args = args . split ( / \s + / ) ;
100
+ }
101
+
102
+ /* base CMD_install command */
103
+ let CMD_install = [
104
+ PERL ,
105
+ cpm_location ,
106
+ "install" ,
107
+ "--show-build-log-on-failure" ,
108
+ w_tests ,
109
+ ] ;
110
+
111
+ if ( is_true ( verbose ) ) {
112
+ CMD_install . push ( "-v" ) ;
113
+ }
114
+ if ( is_true ( dash_g ) ) {
115
+ CMD_install . push ( "-g" ) ;
116
+ }
117
+ if ( w_args . length ) {
118
+ CMD_install = CMD_install . concat ( w_args ) ;
119
+ }
120
+
121
+ let has_run = false ;
122
+
123
+ /* install one ore more modules */
124
+ if ( install !== null && install . length ) {
125
+ // install one or more modules
126
+ core . info ( `install: ${ install } !` ) ;
127
+ const list = install . split ( "\n" ) ;
128
+
129
+ let cmd = [ ...CMD_install ] ; /* clone array */
130
+ cmd = cmd . concat ( list ) ;
131
+
132
+ has_run = true ;
133
+ await do_exec ( cmd ) ;
134
+ }
135
+
136
+ /* install from cpanfile */
137
+ if ( cpanfile !== null && cpanfile . length ) {
138
+ // install one or more modules
139
+ core . info ( `cpanfile: ${ cpanfile } !` ) ;
140
+ const cpanfile_full_path = path . resolve ( cpanfile ) ;
141
+ core . info ( `cpanfile: ${ cpanfile_full_path } ! [resolved]` ) ;
142
+
143
+ let cmd = [ ...CMD_install ] ;
144
+ cmd . push ( "--cpanfile" , cpanfile_full_path ) ;
145
+
146
+ has_run = true ;
147
+ await do_exec ( cmd ) ;
148
+ }
149
+
150
+ /* custom run with args */
151
+ if ( has_run === false && w_args . length ) {
152
+ core . info ( `custom run with args` ) ;
153
+ let cmd = [ ...CMD_install ] ;
154
+ has_run = true ;
155
+ await do_exec ( cmd ) ;
156
+ }
157
157
}
158
158
159
159
// Call run
160
160
( async ( ) => {
161
- try {
162
- await run ( ) ;
163
- } catch ( error ) {
164
- core . setFailed ( error . message ) ;
165
- }
166
- } ) ( ) ;
161
+ try {
162
+ await run ( ) ;
163
+ } catch ( error ) {
164
+ core . setFailed ( error . message ) ;
165
+ }
166
+ } ) ( ) ;
0 commit comments