setup-php 2.12.0 → 2.16.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (113) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +977 -936
  3. package/package.json +66 -56
  4. package/src/config.ts +82 -82
  5. package/src/configs/brew_extensions +30 -0
  6. package/src/configs/os_releases.csv +17 -0
  7. package/src/configs/php-versions.json +6 -5
  8. package/src/configs/{php.json → pm/php.json} +29 -29
  9. package/src/configs/{phpunit.json → pm/phpunit.json} +24 -24
  10. package/src/configs/tools.json +256 -234
  11. package/src/configs/tools_schema.json +114 -103
  12. package/src/coverage.ts +169 -142
  13. package/src/extensions.ts +363 -349
  14. package/src/install.ts +79 -82
  15. package/src/scripts/common.sh +366 -314
  16. package/src/scripts/darwin.sh +257 -248
  17. package/src/scripts/ext/blackfire.ps1 +32 -32
  18. package/src/scripts/ext/blackfire.sh +22 -21
  19. package/src/scripts/ext/couchbase.sh +43 -43
  20. package/src/scripts/ext/cubrid.sh +60 -60
  21. package/src/scripts/ext/extension_map.php +109 -0
  22. package/src/scripts/ext/firebird.ps1 +19 -19
  23. package/src/scripts/ext/firebird.sh +39 -35
  24. package/src/scripts/ext/gearman.sh +22 -22
  25. package/src/scripts/ext/geos.sh +17 -17
  26. package/src/scripts/ext/http.ps1 +54 -54
  27. package/src/scripts/ext/http.sh +120 -120
  28. package/src/scripts/ext/intl.sh +23 -23
  29. package/src/scripts/ext/ioncube.ps1 +33 -32
  30. package/src/scripts/ext/ioncube.sh +21 -19
  31. package/src/scripts/ext/oci.ps1 +60 -60
  32. package/src/scripts/ext/oci.sh +65 -63
  33. package/src/scripts/ext/patches/firebird.sh +11 -11
  34. package/src/scripts/ext/patches/geos.sh +7 -7
  35. package/src/scripts/ext/patches/http.sh +11 -11
  36. package/src/scripts/ext/patches/pdo_oci.sh +6 -6
  37. package/src/scripts/ext/patches/phpize.sh +26 -26
  38. package/src/scripts/ext/patches/protobuf.sh +4 -4
  39. package/src/scripts/ext/phalcon.ps1 +54 -55
  40. package/src/scripts/ext/phalcon.sh +59 -59
  41. package/src/scripts/ext/source.sh +144 -144
  42. package/src/scripts/linux.sh +239 -280
  43. package/src/scripts/tools/add_tools.ps1 +28 -25
  44. package/src/scripts/tools/add_tools.sh +27 -19
  45. package/src/scripts/tools/blackfire.ps1 +19 -21
  46. package/src/scripts/tools/blackfire.sh +40 -35
  47. package/src/scripts/tools/grpc_php_plugin.ps1 +21 -21
  48. package/src/scripts/tools/grpc_php_plugin.sh +58 -61
  49. package/src/scripts/tools/ppa.sh +189 -0
  50. package/src/scripts/tools/protoc.ps1 +38 -38
  51. package/src/scripts/tools/protoc.sh +28 -28
  52. package/src/scripts/win32.ps1 +566 -471
  53. package/src/tools.ts +538 -509
  54. package/src/utils.ts +503 -497
  55. package/.eslintrc.json +0 -16
  56. package/.github/CODE_OF_CONDUCT.md +0 -76
  57. package/.github/CONTRIBUTING.md +0 -70
  58. package/.github/FUNDING.yml +0 -7
  59. package/.github/ISSUE_TEMPLATE/bug_report.md +0 -42
  60. package/.github/ISSUE_TEMPLATE/feature_request.md +0 -26
  61. package/.github/PULL_REQUEST_TEMPLATE.md +0 -37
  62. package/.github/SECURITY.md +0 -29
  63. package/.github/workflows/docs.yml +0 -77
  64. package/.github/workflows/node-workflow.yml +0 -51
  65. package/.github/workflows/workflow.yml +0 -78
  66. package/.idea/workspace.xml +0 -113
  67. package/.prettierrc.json +0 -12
  68. package/__tests__/config.test.ts +0 -52
  69. package/__tests__/coverage.test.ts +0 -110
  70. package/__tests__/extensions.test.ts +0 -261
  71. package/__tests__/install.test.ts +0 -175
  72. package/__tests__/tools.test.ts +0 -490
  73. package/__tests__/utils.test.ts +0 -303
  74. package/action.yml +0 -29
  75. package/dist/index.js +0 -3001
  76. package/examples/bedrock.yml +0 -32
  77. package/examples/blackfire-player.yml +0 -31
  78. package/examples/blackfire.yml +0 -31
  79. package/examples/cakephp-mysql.yml +0 -114
  80. package/examples/cakephp-postgres.yml +0 -112
  81. package/examples/cakephp.yml +0 -92
  82. package/examples/codeigniter.yml +0 -34
  83. package/examples/laravel-mysql.yml +0 -74
  84. package/examples/laravel-postgres.yml +0 -74
  85. package/examples/laravel.yml +0 -42
  86. package/examples/lumen-mysql.yml +0 -74
  87. package/examples/lumen-postgres.yml +0 -74
  88. package/examples/lumen.yml +0 -38
  89. package/examples/phalcon-mysql.yml +0 -74
  90. package/examples/phalcon-postgres.yml +0 -73
  91. package/examples/sage.yml +0 -57
  92. package/examples/slim-framework.yml +0 -34
  93. package/examples/symfony-mysql.yml +0 -57
  94. package/examples/symfony-postgres.yml +0 -55
  95. package/examples/symfony.yml +0 -39
  96. package/examples/yii2-mysql.yml +0 -73
  97. package/examples/yii2-postgres.yml +0 -71
  98. package/examples/zend-framework.yml +0 -36
  99. package/jest.config.js +0 -12
  100. package/lib/config.js +0 -72
  101. package/lib/config.js.map +0 -1
  102. package/lib/coverage.js +0 -88
  103. package/lib/coverage.js.map +0 -1
  104. package/lib/extensions.js +0 -201
  105. package/lib/extensions.js.map +0 -1
  106. package/lib/install.js +0 -82
  107. package/lib/install.js.map +0 -1
  108. package/lib/sapi.js +0 -64
  109. package/lib/tools.js +0 -387
  110. package/lib/tools.js.map +0 -1
  111. package/lib/utils.js +0 -292
  112. package/lib/utils.js.map +0 -1
  113. package/tsconfig.json +0 -18
package/src/utils.ts CHANGED
@@ -1,497 +1,503 @@
1
- import {IncomingMessage, OutgoingHttpHeaders} from 'http';
2
- import * as fs from 'fs';
3
- import * as https from 'https';
4
- import * as path from 'path';
5
- import * as url from 'url';
6
- import * as core from '@actions/core';
7
-
8
- /**
9
- * Function to read environment variable and return a string value.
10
- *
11
- * @param property
12
- */
13
- export async function readEnv(property: string): Promise<string> {
14
- const value = process.env[property];
15
- switch (value) {
16
- case undefined:
17
- return '';
18
- default:
19
- return value;
20
- }
21
- }
22
-
23
- /**
24
- * Function to get inputs from both with and env annotations.
25
- *
26
- * @param name
27
- * @param mandatory
28
- */
29
- export async function getInput(
30
- name: string,
31
- mandatory: boolean
32
- ): Promise<string> {
33
- const input = core.getInput(name);
34
- const env_input = await readEnv(name);
35
- switch (true) {
36
- case input != '':
37
- return input;
38
- case input == '' && env_input != '':
39
- return env_input;
40
- case input == '' && env_input == '' && mandatory:
41
- throw new Error(`Input required and not supplied: ${name}`);
42
- default:
43
- return '';
44
- }
45
- }
46
-
47
- /**
48
- * Function to fetch an URL
49
- *
50
- * @param input_url
51
- * @param auth_token
52
- */
53
- export async function fetch(
54
- input_url: string,
55
- auth_token?: string
56
- ): Promise<Record<string, string>> {
57
- const fetch_promise: Promise<Record<string, string>> = new Promise(
58
- resolve => {
59
- const url_object: url.UrlObject = new url.URL(input_url);
60
- const headers: OutgoingHttpHeaders = {
61
- 'User-Agent': `Mozilla/5.0 (${process.platform} ${process.arch}) setup-php`
62
- };
63
- if (auth_token) {
64
- headers.authorization = 'Bearer ' + auth_token;
65
- }
66
- const options: https.RequestOptions = {
67
- hostname: url_object.hostname,
68
- path: url_object.pathname,
69
- headers: headers
70
- };
71
- const req = https.get(options, (res: IncomingMessage) => {
72
- if (res.statusCode != 200) {
73
- resolve({error: `${res.statusCode}: ${res.statusMessage}`});
74
- } else {
75
- let body = '';
76
- res.setEncoding('utf8');
77
- res.on('data', chunk => (body += chunk));
78
- res.on('end', () => resolve({data: `${body}`}));
79
- }
80
- });
81
- req.end();
82
- }
83
- );
84
- return await fetch_promise;
85
- }
86
-
87
- /** Function to get manifest URL
88
- *
89
- */
90
- export async function getManifestURL(): Promise<string> {
91
- return 'https://raw.githubusercontent.com/shivammathur/setup-php/develop/src/configs/php-versions.json';
92
- }
93
-
94
- /**
95
- * Function to parse PHP version.
96
- *
97
- * @param version
98
- */
99
- export async function parseVersion(version: string): Promise<string> {
100
- const manifest = await getManifestURL();
101
- switch (true) {
102
- case /^(latest|\d+\.x)$/.test(version):
103
- return JSON.parse((await fetch(manifest))['data'])[version];
104
- default:
105
- switch (true) {
106
- case version.length > 1:
107
- return version.slice(0, 3);
108
- default:
109
- return version + '.0';
110
- }
111
- }
112
- }
113
-
114
- /**
115
- * Async foreach loop
116
- *
117
- * @author https://github.com/Atinux
118
- * @param array
119
- * @param callback
120
- */
121
- export async function asyncForEach(
122
- array: Array<string>,
123
- callback: (
124
- element: string,
125
- index: number,
126
- array: Array<string>
127
- ) => Promise<void>
128
- ): Promise<void> {
129
- for (let index = 0; index < array.length; index++) {
130
- await callback(array[index], index, array);
131
- }
132
- }
133
-
134
- /**
135
- * Get color index
136
- *
137
- * @param type
138
- */
139
- export async function color(type: string): Promise<string> {
140
- switch (type) {
141
- case 'error':
142
- return '31';
143
- default:
144
- case 'success':
145
- return '32';
146
- case 'warning':
147
- return '33';
148
- }
149
- }
150
-
151
- /**
152
- * Log to console
153
- *
154
- * @param message
155
- * @param os_version
156
- * @param log_type
157
- */
158
- export async function log(
159
- message: string,
160
- os_version: string,
161
- log_type: string
162
- ): Promise<string> {
163
- switch (os_version) {
164
- case 'win32':
165
- return (
166
- 'printf "\\033[' +
167
- (await color(log_type)) +
168
- ';1m' +
169
- message +
170
- ' \\033[0m"'
171
- );
172
-
173
- case 'linux':
174
- case 'darwin':
175
- default:
176
- return (
177
- 'echo "\\033[' + (await color(log_type)) + ';1m' + message + '\\033[0m"'
178
- );
179
- }
180
- }
181
-
182
- /**
183
- * Function to log a step
184
- *
185
- * @param message
186
- * @param os_version
187
- */
188
- export async function stepLog(
189
- message: string,
190
- os_version: string
191
- ): Promise<string> {
192
- switch (os_version) {
193
- case 'win32':
194
- return 'Step-Log "' + message + '"';
195
- case 'linux':
196
- case 'darwin':
197
- return 'step_log "' + message + '"';
198
- default:
199
- return await log(
200
- 'Platform ' + os_version + ' is not supported',
201
- os_version,
202
- 'error'
203
- );
204
- }
205
- }
206
-
207
- /**
208
- * Function to log a result
209
- * @param mark
210
- * @param subject
211
- * @param message
212
- * @param os_version
213
- */
214
- export async function addLog(
215
- mark: string,
216
- subject: string,
217
- message: string,
218
- os_version: string
219
- ): Promise<string> {
220
- switch (os_version) {
221
- case 'win32':
222
- return 'Add-Log "' + mark + '" "' + subject + '" "' + message + '"';
223
- case 'linux':
224
- case 'darwin':
225
- return 'add_log "' + mark + '" "' + subject + '" "' + message + '"';
226
- default:
227
- return await log(
228
- 'Platform ' + os_version + ' is not supported',
229
- os_version,
230
- 'error'
231
- );
232
- }
233
- }
234
-
235
- /**
236
- * Read the scripts
237
- *
238
- * @param filename
239
- * @param directory
240
- */
241
- export async function readFile(
242
- filename: string,
243
- directory: string
244
- ): Promise<string> {
245
- return fs.readFileSync(
246
- path.join(__dirname, '../' + directory, filename),
247
- 'utf8'
248
- );
249
- }
250
-
251
- /**
252
- * Write final script which runs
253
- *
254
- * @param filename
255
- * @param script
256
- */
257
- export async function writeScript(
258
- filename: string,
259
- script: string
260
- ): Promise<string> {
261
- const runner_dir: string = await getInput('RUNNER_TOOL_CACHE', false);
262
- const script_path: string = path.join(runner_dir, filename);
263
- fs.writeFileSync(script_path, script, {mode: 0o755});
264
- return script_path;
265
- }
266
-
267
- /**
268
- * Function to break extension csv into an array
269
- *
270
- * @param extension_csv
271
- */
272
- export async function extensionArray(
273
- extension_csv: string
274
- ): Promise<Array<string>> {
275
- switch (extension_csv) {
276
- case '':
277
- case ' ':
278
- return [];
279
- default:
280
- return extension_csv
281
- .split(',')
282
- .map(function (extension: string) {
283
- if (/.+-.+\/.+@.+/.test(extension)) {
284
- return extension;
285
- }
286
- return extension
287
- .trim()
288
- .toLowerCase()
289
- .replace(/^php[-_]/, '');
290
- })
291
- .filter(Boolean);
292
- }
293
- }
294
-
295
- /**
296
- * Function to break csv into an array
297
- *
298
- * @param values_csv
299
- * @constructor
300
- */
301
- export async function CSVArray(values_csv: string): Promise<Array<string>> {
302
- switch (values_csv) {
303
- case '':
304
- case ' ':
305
- return [];
306
- default:
307
- return values_csv
308
- .split(/,(?=(?:(?:[^"']*["']){2})*[^"']*$)/)
309
- .map(function (value) {
310
- return value
311
- .trim()
312
- .replace(/^["']|["']$|(?<==)["']/g, '')
313
- .replace(/=(((?!E_).)*[?{}|&~![()^]+((?!E_).)+)/, "='$1'");
314
- })
315
- .filter(Boolean);
316
- }
317
- }
318
-
319
- /**
320
- * Function to get prefix required to load an extension.
321
- *
322
- * @param extension
323
- */
324
- export async function getExtensionPrefix(extension: string): Promise<string> {
325
- switch (true) {
326
- default:
327
- return 'extension';
328
- case /xdebug([2-3])?$|opcache|ioncube|eaccelerator/.test(extension):
329
- return 'zend_extension';
330
- }
331
- }
332
-
333
- /**
334
- * Function to get the suffix to suppress console output
335
- *
336
- * @param os_version
337
- */
338
- export async function suppressOutput(os_version: string): Promise<string> {
339
- switch (os_version) {
340
- case 'win32':
341
- return ' >$null 2>&1';
342
- case 'linux':
343
- case 'darwin':
344
- return ' >/dev/null 2>&1';
345
- default:
346
- return await log(
347
- 'Platform ' + os_version + ' is not supported',
348
- os_version,
349
- 'error'
350
- );
351
- }
352
- }
353
-
354
- /**
355
- * Function to get script to log unsupported extensions.
356
- *
357
- * @param extension
358
- * @param version
359
- * @param os_version
360
- */
361
- export async function getUnsupportedLog(
362
- extension: string,
363
- version: string,
364
- os_version: string
365
- ): Promise<string> {
366
- return (
367
- '\n' +
368
- (await addLog(
369
- '$cross',
370
- extension,
371
- [extension, 'is not supported on PHP', version].join(' '),
372
- os_version
373
- )) +
374
- '\n'
375
- );
376
- }
377
-
378
- /**
379
- * Function to get command to setup tools
380
- *
381
- * @param os_version
382
- * @param suffix
383
- */
384
- export async function getCommand(
385
- os_version: string,
386
- suffix: string
387
- ): Promise<string> {
388
- switch (os_version) {
389
- case 'linux':
390
- case 'darwin':
391
- return 'add_' + suffix + ' ';
392
- case 'win32':
393
- return 'Add-' + suffix.charAt(0).toUpperCase() + suffix.slice(1) + ' ';
394
- default:
395
- return await log(
396
- 'Platform ' + os_version + ' is not supported',
397
- os_version,
398
- 'error'
399
- );
400
- }
401
- }
402
-
403
- /**
404
- * Function to join strings with space
405
- *
406
- * @param str
407
- */
408
- export async function joins(...str: string[]): Promise<string> {
409
- return [...str].join(' ');
410
- }
411
-
412
- /**
413
- * Function to get script extensions
414
- *
415
- * @param os_version
416
- */
417
- export async function scriptExtension(os_version: string): Promise<string> {
418
- switch (os_version) {
419
- case 'win32':
420
- return '.ps1';
421
- case 'linux':
422
- case 'darwin':
423
- return '.sh';
424
- default:
425
- return await log(
426
- 'Platform ' + os_version + ' is not supported',
427
- os_version,
428
- 'error'
429
- );
430
- }
431
- }
432
-
433
- /**
434
- * Function to get script tool
435
- *
436
- * @param os_version
437
- */
438
- export async function scriptTool(os_version: string): Promise<string> {
439
- switch (os_version) {
440
- case 'win32':
441
- return 'pwsh';
442
- case 'linux':
443
- case 'darwin':
444
- return 'bash';
445
- default:
446
- return await log(
447
- 'Platform ' + os_version + ' is not supported',
448
- os_version,
449
- 'error'
450
- );
451
- }
452
- }
453
-
454
- /**
455
- * Function to get script to add tools with custom support.
456
- *
457
- * @param pkg
458
- * @param type
459
- * @param version
460
- * @param os_version
461
- */
462
- export async function customPackage(
463
- pkg: string,
464
- type: string,
465
- version: string,
466
- os_version: string
467
- ): Promise<string> {
468
- const pkg_name: string = pkg.replace(/\d+|(pdo|pecl)[_-]/, '');
469
- const script_extension: string = await scriptExtension(os_version);
470
- const script: string = path.join(
471
- __dirname,
472
- '../src/scripts/' + type + '/' + pkg_name + script_extension
473
- );
474
- const command: string = await getCommand(os_version, pkg_name);
475
- return '\n. ' + script + '\n' + command + version;
476
- }
477
-
478
- /**
479
- * Function to extension input for installation from source.
480
- *
481
- * @param extension
482
- * @param prefix
483
- */
484
- export async function parseExtensionSource(
485
- extension: string,
486
- prefix: string
487
- ): Promise<string> {
488
- // Groups: extension, domain url, org, repo, release
489
- const regex = /(\w+)-(.+:\/\/.+(?:[.:].+)+\/)?([\w.-]+)\/([\w.-]+)@(.+)/;
490
- const matches = regex.exec(extension) as RegExpExecArray;
491
- matches[2] = matches[2] ? matches[2].slice(0, -1) : 'https://github.com';
492
- return await joins(
493
- '\nadd_extension_from_source',
494
- ...matches.splice(1, matches.length),
495
- prefix
496
- );
497
- }
1
+ import {IncomingMessage, OutgoingHttpHeaders} from 'http';
2
+ import * as fs from 'fs';
3
+ import * as https from 'https';
4
+ import * as path from 'path';
5
+ import * as url from 'url';
6
+ import * as core from '@actions/core';
7
+
8
+ /**
9
+ * Function to read environment variable and return a string value.
10
+ *
11
+ * @param property
12
+ */
13
+ export async function readEnv(property: string): Promise<string> {
14
+ const property_lc: string = property.toLowerCase();
15
+ const property_uc: string = property.toUpperCase();
16
+ return (
17
+ process.env[property] ||
18
+ process.env[property_lc] ||
19
+ process.env[property_uc] ||
20
+ process.env[property_lc.replace('_', '-')] ||
21
+ process.env[property_uc.replace('_', '-')] ||
22
+ ''
23
+ );
24
+ }
25
+
26
+ /**
27
+ * Function to get inputs from both with and env annotations.
28
+ *
29
+ * @param name
30
+ * @param mandatory
31
+ */
32
+ export async function getInput(
33
+ name: string,
34
+ mandatory: boolean
35
+ ): Promise<string> {
36
+ const input = core.getInput(name);
37
+ const env_input = await readEnv(name);
38
+ switch (true) {
39
+ case input != '':
40
+ return input;
41
+ case input == '' && env_input != '':
42
+ return env_input;
43
+ case input == '' && env_input == '' && mandatory:
44
+ throw new Error(`Input required and not supplied: ${name}`);
45
+ default:
46
+ return '';
47
+ }
48
+ }
49
+
50
+ /**
51
+ * Function to fetch an URL
52
+ *
53
+ * @param input_url
54
+ * @param auth_token
55
+ */
56
+ export async function fetch(
57
+ input_url: string,
58
+ auth_token?: string
59
+ ): Promise<Record<string, string>> {
60
+ const fetch_promise: Promise<Record<string, string>> = new Promise(
61
+ resolve => {
62
+ const url_object: url.UrlObject = new url.URL(input_url);
63
+ const headers: OutgoingHttpHeaders = {
64
+ 'User-Agent': `Mozilla/5.0 (${process.platform} ${process.arch}) setup-php`
65
+ };
66
+ if (auth_token) {
67
+ headers.authorization = 'Bearer ' + auth_token;
68
+ }
69
+ const options: https.RequestOptions = {
70
+ hostname: url_object.hostname,
71
+ path: url_object.pathname,
72
+ headers: headers
73
+ };
74
+ const req = https.get(options, (res: IncomingMessage) => {
75
+ if (res.statusCode != 200) {
76
+ resolve({error: `${res.statusCode}: ${res.statusMessage}`});
77
+ } else {
78
+ let body = '';
79
+ res.setEncoding('utf8');
80
+ res.on('data', chunk => (body += chunk));
81
+ res.on('end', () => resolve({data: `${body}`}));
82
+ }
83
+ });
84
+ req.end();
85
+ }
86
+ );
87
+ return await fetch_promise;
88
+ }
89
+
90
+ /** Function to get manifest URL
91
+ *
92
+ */
93
+ export async function getManifestURL(): Promise<string> {
94
+ return 'https://raw.githubusercontent.com/shivammathur/setup-php/develop/src/configs/php-versions.json';
95
+ }
96
+
97
+ /**
98
+ * Function to parse PHP version.
99
+ *
100
+ * @param version
101
+ */
102
+ export async function parseVersion(version: string): Promise<string> {
103
+ const manifest = await getManifestURL();
104
+ switch (true) {
105
+ case /^(latest|nightly|\d+\.x)$/.test(version):
106
+ return JSON.parse((await fetch(manifest))['data'])[version];
107
+ default:
108
+ switch (true) {
109
+ case version.length > 1:
110
+ return version.slice(0, 3);
111
+ default:
112
+ return version + '.0';
113
+ }
114
+ }
115
+ }
116
+
117
+ /**
118
+ * Async foreach loop
119
+ *
120
+ * @author https://github.com/Atinux
121
+ * @param array
122
+ * @param callback
123
+ */
124
+ export async function asyncForEach(
125
+ array: Array<string>,
126
+ callback: (
127
+ element: string,
128
+ index: number,
129
+ array: Array<string>
130
+ ) => Promise<void>
131
+ ): Promise<void> {
132
+ for (let index = 0; index < array.length; index++) {
133
+ await callback(array[index], index, array);
134
+ }
135
+ }
136
+
137
+ /**
138
+ * Get color index
139
+ *
140
+ * @param type
141
+ */
142
+ export async function color(type: string): Promise<string> {
143
+ switch (type) {
144
+ case 'error':
145
+ return '31';
146
+ default:
147
+ case 'success':
148
+ return '32';
149
+ case 'warning':
150
+ return '33';
151
+ }
152
+ }
153
+
154
+ /**
155
+ * Log to console
156
+ *
157
+ * @param message
158
+ * @param os_version
159
+ * @param log_type
160
+ */
161
+ export async function log(
162
+ message: string,
163
+ os_version: string,
164
+ log_type: string
165
+ ): Promise<string> {
166
+ switch (os_version) {
167
+ case 'win32':
168
+ return (
169
+ 'printf "\\033[' +
170
+ (await color(log_type)) +
171
+ ';1m' +
172
+ message +
173
+ ' \\033[0m"'
174
+ );
175
+
176
+ case 'linux':
177
+ case 'darwin':
178
+ default:
179
+ return (
180
+ 'echo "\\033[' + (await color(log_type)) + ';1m' + message + '\\033[0m"'
181
+ );
182
+ }
183
+ }
184
+
185
+ /**
186
+ * Function to log a step
187
+ *
188
+ * @param message
189
+ * @param os_version
190
+ */
191
+ export async function stepLog(
192
+ message: string,
193
+ os_version: string
194
+ ): Promise<string> {
195
+ switch (os_version) {
196
+ case 'win32':
197
+ return 'Step-Log "' + message + '"';
198
+ case 'linux':
199
+ case 'darwin':
200
+ return 'step_log "' + message + '"';
201
+ default:
202
+ return await log(
203
+ 'Platform ' + os_version + ' is not supported',
204
+ os_version,
205
+ 'error'
206
+ );
207
+ }
208
+ }
209
+
210
+ /**
211
+ * Function to log a result
212
+ * @param mark
213
+ * @param subject
214
+ * @param message
215
+ * @param os_version
216
+ */
217
+ export async function addLog(
218
+ mark: string,
219
+ subject: string,
220
+ message: string,
221
+ os_version: string
222
+ ): Promise<string> {
223
+ switch (os_version) {
224
+ case 'win32':
225
+ return 'Add-Log "' + mark + '" "' + subject + '" "' + message + '"';
226
+ case 'linux':
227
+ case 'darwin':
228
+ return 'add_log "' + mark + '" "' + subject + '" "' + message + '"';
229
+ default:
230
+ return await log(
231
+ 'Platform ' + os_version + ' is not supported',
232
+ os_version,
233
+ 'error'
234
+ );
235
+ }
236
+ }
237
+
238
+ /**
239
+ * Read the scripts
240
+ *
241
+ * @param filename
242
+ * @param directory
243
+ */
244
+ export async function readFile(
245
+ filename: string,
246
+ directory: string
247
+ ): Promise<string> {
248
+ return fs.readFileSync(
249
+ path.join(__dirname, '../' + directory, filename),
250
+ 'utf8'
251
+ );
252
+ }
253
+
254
+ /**
255
+ * Write final script which runs
256
+ *
257
+ * @param filename
258
+ * @param script
259
+ */
260
+ export async function writeScript(
261
+ filename: string,
262
+ script: string
263
+ ): Promise<string> {
264
+ const runner_dir: string = await getInput('RUNNER_TOOL_CACHE', false);
265
+ const script_path: string = path.join(runner_dir, filename);
266
+ fs.writeFileSync(script_path, script, {mode: 0o755});
267
+ return script_path;
268
+ }
269
+
270
+ /**
271
+ * Function to break extension csv into an array
272
+ *
273
+ * @param extension_csv
274
+ */
275
+ export async function extensionArray(
276
+ extension_csv: string
277
+ ): Promise<Array<string>> {
278
+ switch (extension_csv) {
279
+ case '':
280
+ case ' ':
281
+ return [];
282
+ default:
283
+ return [
284
+ extension_csv.match(/(^|,\s?)none(\s?,|$)/) ? 'none' : '',
285
+ ...extension_csv
286
+ .split(',')
287
+
288
+ .map(function (extension: string) {
289
+ if (/.+-.+\/.+@.+/.test(extension)) {
290
+ return extension;
291
+ }
292
+ return extension
293
+ .trim()
294
+ .toLowerCase()
295
+ .replace(/^(:)?(php[-_]|none|zend )/, '$1');
296
+ })
297
+ ].filter(Boolean);
298
+ }
299
+ }
300
+
301
+ /**
302
+ * Function to break csv into an array
303
+ *
304
+ * @param values_csv
305
+ * @constructor
306
+ */
307
+ export async function CSVArray(values_csv: string): Promise<Array<string>> {
308
+ switch (values_csv) {
309
+ case '':
310
+ case ' ':
311
+ return [];
312
+ default:
313
+ return values_csv
314
+ .split(/,(?=(?:(?:[^"']*["']){2})*[^"']*$)/)
315
+ .map(function (value) {
316
+ return value
317
+ .trim()
318
+ .replace(/^["']|["']$|(?<==)["']/g, '')
319
+ .replace(/=(((?!E_).)*[?{}|&~![()^]+((?!E_).)+)/, "='$1'");
320
+ })
321
+ .filter(Boolean);
322
+ }
323
+ }
324
+
325
+ /**
326
+ * Function to get prefix required to load an extension.
327
+ *
328
+ * @param extension
329
+ */
330
+ export async function getExtensionPrefix(extension: string): Promise<string> {
331
+ switch (true) {
332
+ default:
333
+ return 'extension';
334
+ case /xdebug([2-3])?$|opcache|ioncube|eaccelerator/.test(extension):
335
+ return 'zend_extension';
336
+ }
337
+ }
338
+
339
+ /**
340
+ * Function to get the suffix to suppress console output
341
+ *
342
+ * @param os_version
343
+ */
344
+ export async function suppressOutput(os_version: string): Promise<string> {
345
+ switch (os_version) {
346
+ case 'win32':
347
+ return ' >$null 2>&1';
348
+ case 'linux':
349
+ case 'darwin':
350
+ return ' >/dev/null 2>&1';
351
+ default:
352
+ return await log(
353
+ 'Platform ' + os_version + ' is not supported',
354
+ os_version,
355
+ 'error'
356
+ );
357
+ }
358
+ }
359
+
360
+ /**
361
+ * Function to get script to log unsupported extensions.
362
+ *
363
+ * @param extension
364
+ * @param version
365
+ * @param os_version
366
+ */
367
+ export async function getUnsupportedLog(
368
+ extension: string,
369
+ version: string,
370
+ os_version: string
371
+ ): Promise<string> {
372
+ return (
373
+ '\n' +
374
+ (await addLog(
375
+ '$cross',
376
+ extension,
377
+ [extension, 'is not supported on PHP', version].join(' '),
378
+ os_version
379
+ )) +
380
+ '\n'
381
+ );
382
+ }
383
+
384
+ /**
385
+ * Function to get command to setup tools
386
+ *
387
+ * @param os_version
388
+ * @param suffix
389
+ */
390
+ export async function getCommand(
391
+ os_version: string,
392
+ suffix: string
393
+ ): Promise<string> {
394
+ switch (os_version) {
395
+ case 'linux':
396
+ case 'darwin':
397
+ return 'add_' + suffix + ' ';
398
+ case 'win32':
399
+ return 'Add-' + suffix.charAt(0).toUpperCase() + suffix.slice(1) + ' ';
400
+ default:
401
+ return await log(
402
+ 'Platform ' + os_version + ' is not supported',
403
+ os_version,
404
+ 'error'
405
+ );
406
+ }
407
+ }
408
+
409
+ /**
410
+ * Function to join strings with space
411
+ *
412
+ * @param str
413
+ */
414
+ export async function joins(...str: string[]): Promise<string> {
415
+ return [...str].join(' ');
416
+ }
417
+
418
+ /**
419
+ * Function to get script extensions
420
+ *
421
+ * @param os_version
422
+ */
423
+ export async function scriptExtension(os_version: string): Promise<string> {
424
+ switch (os_version) {
425
+ case 'win32':
426
+ return '.ps1';
427
+ case 'linux':
428
+ case 'darwin':
429
+ return '.sh';
430
+ default:
431
+ return await log(
432
+ 'Platform ' + os_version + ' is not supported',
433
+ os_version,
434
+ 'error'
435
+ );
436
+ }
437
+ }
438
+
439
+ /**
440
+ * Function to get script tool
441
+ *
442
+ * @param os_version
443
+ */
444
+ export async function scriptTool(os_version: string): Promise<string> {
445
+ switch (os_version) {
446
+ case 'win32':
447
+ return 'pwsh';
448
+ case 'linux':
449
+ case 'darwin':
450
+ return 'bash';
451
+ default:
452
+ return await log(
453
+ 'Platform ' + os_version + ' is not supported',
454
+ os_version,
455
+ 'error'
456
+ );
457
+ }
458
+ }
459
+
460
+ /**
461
+ * Function to get script to add tools with custom support.
462
+ *
463
+ * @param pkg
464
+ * @param type
465
+ * @param version
466
+ * @param os_version
467
+ */
468
+ export async function customPackage(
469
+ pkg: string,
470
+ type: string,
471
+ version: string,
472
+ os_version: string
473
+ ): Promise<string> {
474
+ const pkg_name: string = pkg.replace(/\d+|(pdo|pecl)[_-]/, '');
475
+ const script_extension: string = await scriptExtension(os_version);
476
+ const script: string = path.join(
477
+ __dirname,
478
+ '../src/scripts/' + type + '/' + pkg_name + script_extension
479
+ );
480
+ const command: string = await getCommand(os_version, pkg_name);
481
+ return '\n. ' + script + '\n' + command + version;
482
+ }
483
+
484
+ /**
485
+ * Function to extension input for installation from source.
486
+ *
487
+ * @param extension
488
+ * @param prefix
489
+ */
490
+ export async function parseExtensionSource(
491
+ extension: string,
492
+ prefix: string
493
+ ): Promise<string> {
494
+ // Groups: extension, domain url, org, repo, release
495
+ const regex = /(\w+)-(.+:\/\/.+(?:[.:].+)+\/)?([\w.-]+)\/([\w.-]+)@(.+)/;
496
+ const matches = regex.exec(extension) as RegExpExecArray;
497
+ matches[2] = matches[2] ? matches[2].slice(0, -1) : 'https://github.com';
498
+ return await joins(
499
+ '\nadd_extension_from_source',
500
+ ...matches.splice(1, matches.length),
501
+ prefix
502
+ );
503
+ }