Compare commits

...

7 Commits
1.9.8 ... 1.9.7

14 changed files with 802 additions and 563 deletions

5
.github/FUNDING.yml vendored
View File

@ -1,6 +1,7 @@
# These are supported funding model platforms # These are supported funding model platforms
github: shivammathur open_collective: setup-php
tidelift: "npm/setup-php"
community_bridge: setup-php community_bridge: setup-php
patreon: shivammathur patreon: shivammathur
custom: https://www.paypal.me/shivammathur custom: https://www.paypal.me/shivammathur

2
.github/SECURITY.md vendored
View File

@ -7,7 +7,7 @@ The following versions of this project are supported for security updates.
| Version | Supported | | Version | Supported |
| ------- | ------------------ | | ------- | ------------------ |
| 1.9.x | :white_check_mark: | | 1.9.x | :white_check_mark: |
| 2.4.x | :white_check_mark: | | 2.6.x | :white_check_mark: |
## Supported PHP Versions ## Supported PHP Versions

View File

@ -8,7 +8,7 @@
<p align="center"> <p align="center">
<a href="https://github.com/shivammathur/setup-php" title="GitHub action to setup PHP"><img alt="GitHub Actions status" src="https://github.com/shivammathur/setup-php/workflows/Main%20workflow/badge.svg"></a> <a href="https://github.com/shivammathur/setup-php" title="GitHub action to setup PHP"><img alt="GitHub Actions status" src="https://github.com/shivammathur/setup-php/workflows/Main%20workflow/badge.svg"></a>
<a href="https://codecov.io/gh/shivammathur/setup-php" title="Code coverage"><img alt="Codecov Code Coverage" src="https://codecov.io/gh/shivammathur/setup-php/branch/master/graph/badge.svg"></a> <a href="https://codecov.io/gh/shivammathur/setup-php" title="Code coverage"><img alt="Codecov Code Coverage" src="https://img.shields.io/codecov/c/github/shivammathur/setup-php?logo=codecov"></a>
<a href="https://github.com/shivammathur/setup-php/blob/master/LICENSE" title="license"><img alt="LICENSE" src="https://img.shields.io/badge/license-MIT-428f7e.svg"></a> <a href="https://github.com/shivammathur/setup-php/blob/master/LICENSE" title="license"><img alt="LICENSE" src="https://img.shields.io/badge/license-MIT-428f7e.svg"></a>
<a href="#tada-php-support" title="PHP Versions Supported"><img alt="PHP Versions Supported" src="https://img.shields.io/badge/php-%3E%3D%205.6-8892BF.svg"></a> <a href="#tada-php-support" title="PHP Versions Supported"><img alt="PHP Versions Supported" src="https://img.shields.io/badge/php-%3E%3D%205.6-8892BF.svg"></a>
</p> </p>
@ -300,31 +300,72 @@ If you have a number of workflows which setup multiple tools or have many compos
### Problem Matchers ### Problem Matchers
#### PHPUnit Problem matchers are `json` configurations which identify errors and warnings in your logs and surface that information prominently in the GitHub Actions UI by highlighting them and creating code annotations.
You can setup problem matchers for your `PHPUnit` output by adding this step after the `setup-php` step. This will scan the logs for failing tests and surface that information prominently in the GitHub Actions UI by creating annotations and log file decorations. #### PHP
Setup problem matchers for your `PHP` output by adding this step after the `setup-php` step.
```yaml ```yaml
- name: Setup Problem Matchers for PHPUnit - name: Setup problem matchers for PHP
run: echo "::add-matcher::${{ runner.tool_cache }}/php.json"
```
#### PHPUnit
Setup problem matchers for your `PHPUnit` output by adding this step after the `setup-php` step.
```yaml
- name: Setup problem matchers for PHPUnit
run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json" run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"
``` ```
#### Other Tools #### PHPStan
For tools that support `checkstyle` reporting like `phpstan`, `psalm`, `php-cs-fixer` and `phpcs` you can use `cs2pr` to annotate your code. PHPStan supports error reporting in GitHub Actions, so no problem matchers are required.
For examples refer to [cs2pr documentation](https://github.com/staabm/annotate-pull-request-from-checkstyle).
> Here is an example with `phpstan`.
```yaml ```yaml
- name: Setup PHP - name: Setup PHP
uses: shivammathur/setup-php@v1 uses: shivammathur/setup-php@v2
with: with:
php-version: '7.4' php-version: '7.4'
tools: cs2pr, phpstan tools: phpstan
- name: PHPStan - name: Run PHPStan
run: phpstan analyse src --error-format=checkstyle | cs2pr run: phpstan analyse src
```
#### Psalm
Psalm supports error reporting in GitHub Actions with an output format `github`.
```yaml
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '7.4'
tools: psalm
- name: Run Psalm
run: psalm --output-format=github
```
#### Tools with checkstyle support
For tools that support `checkstyle` reporting like `phpstan`, `psalm`, `php-cs-fixer` and `phpcs` you can use `cs2pr` to annotate your code.
For examples refer to [cs2pr documentation](https://github.com/staabm/annotate-pull-request-from-checkstyle).
> Here is an example with `phpcs`.
```yaml
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '7.4'
tools: cs2pr, phpcs
- name: Run phpcs
run: phpcs -q --report=checkstyle src | cs2pr
``` ```
### Examples ### Examples

View File

@ -1,24 +0,0 @@
import * as io from '@actions/io';
import * as matchers from '../src/matchers';
jest.mock('@actions/io');
describe('Matchers', () => {
it('Add matchers', async () => {
process.env['RUNNER_TOOL_CACHE'] = __dirname;
await matchers.addMatchers();
const spy = jest.spyOn(io, 'cp');
expect(spy).toHaveBeenCalledTimes(1);
});
it('Test Regex', async () => {
const regex1 = /^\d+\)\s.*$/;
const regex2 = /^(.*Failed\sasserting\sthat.*)$/;
const regex3 = /^\s*$/;
const regex4 = /^(.*):(\d+)$/;
expect(regex1.test('1) Tests\\Test::it_tests')).toBe(true);
expect(regex2.test('Failed asserting that false is true')).toBe(true);
expect(regex3.test('\n')).toBe(true);
expect(regex4.test('/path/to/file.php:42')).toBe(true);
});
});

View File

@ -17,13 +17,19 @@ async function cleanup(path: string): Promise<void> {
} }
describe('Utils tests', () => { describe('Utils tests', () => {
it('checking getInput', async () => { it('checking readEnv', async () => {
process.env['test'] = 'setup-php'; process.env['test'] = 'setup-php';
process.env['undefined'] = ''; expect(await utils.readEnv('test')).toBe('setup-php');
expect(await utils.readEnv('undefined')).toBe('');
});
it('checking getInput', async () => {
expect(await utils.getInput('test', false)).toBe('setup-php'); expect(await utils.getInput('test', false)).toBe('setup-php');
expect(await utils.getInput('undefined', false)).toBe('');
expect(await utils.getInput('setup-php', false)).toBe('setup-php'); expect(await utils.getInput('setup-php', false)).toBe('setup-php');
expect(await utils.getInput('DoesNotExist', false)).toBe(''); expect(await utils.getInput('DoesNotExist', false)).toBe('');
expect(async () => {
await utils.getInput('DoesNotExist', true);
}).rejects.toThrow('Input required and not supplied: DoesNotExist');
}); });
it('checking asyncForEach', async () => { it('checking asyncForEach', async () => {

162
dist/index.js vendored
View File

@ -953,45 +953,29 @@ class ExecState extends events.EventEmitter {
/***/ }), /***/ }),
/***/ 86: /***/ 82:
/***/ (function(__unusedmodule, exports, __webpack_require__) { /***/ (function(__unusedmodule, exports) {
"use strict"; "use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { // We use any as a valid input type
if (k2 === undefined) k2 = k; /* eslint-disable @typescript-eslint/no-explicit-any */
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, "__esModule", { value: true });
exports.addMatchers = void 0;
const path = __importStar(__webpack_require__(622));
const utils = __importStar(__webpack_require__(163));
const io = __importStar(__webpack_require__(1));
/** /**
* Cache json files for problem matchers * Sanitizes an input into a string so it can be passed into issueCommand safely
* @param input input to sanitize into a string
*/ */
async function addMatchers() { function toCommandValue(input) {
const config_path = path.join(__dirname, '..', 'src', 'configs', 'phpunit.json'); if (input === null || input === undefined) {
const runner_dir = await utils.getInput('RUNNER_TOOL_CACHE', false); return '';
await io.cp(config_path, runner_dir); }
else if (typeof input === 'string' || input instanceof String) {
return input;
}
return JSON.stringify(input);
} }
exports.addMatchers = addMatchers; exports.toCommandValue = toCommandValue;
//# sourceMappingURL=utils.js.map
/***/ }), /***/ }),
@ -1002,6 +986,42 @@ module.exports = require("os");
/***/ }), /***/ }),
/***/ 102:
/***/ (function(__unusedmodule, exports, __webpack_require__) {
"use strict";
// For internal use, subject to change.
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
// We use any as a valid input type
/* eslint-disable @typescript-eslint/no-explicit-any */
const fs = __importStar(__webpack_require__(747));
const os = __importStar(__webpack_require__(87));
const utils_1 = __webpack_require__(82);
function issueCommand(command, message) {
const filePath = process.env[`GITHUB_${command}`];
if (!filePath) {
throw new Error(`Unable to find environment variable for file command ${command}`);
}
if (!fs.existsSync(filePath)) {
throw new Error(`Missing file at path: ${filePath}`);
}
fs.appendFileSync(filePath, `${utils_1.toCommandValue(message)}${os.EOL}`, {
encoding: 'utf8'
});
}
exports.issueCommand = issueCommand;
//# sourceMappingURL=file-command.js.map
/***/ }),
/***/ 129: /***/ 129:
/***/ (function(module) { /***/ (function(module) {
@ -1034,10 +1054,25 @@ var __importStar = (this && this.__importStar) || function (mod) {
return result; return result;
}; };
Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, "__esModule", { value: true });
exports.suppressOutput = exports.getExtensionPrefix = exports.CSVArray = exports.extensionArray = exports.writeScript = exports.readScript = exports.addLog = exports.stepLog = exports.log = exports.color = exports.asyncForEach = exports.getInput = void 0; exports.suppressOutput = exports.getExtensionPrefix = exports.CSVArray = exports.extensionArray = exports.writeScript = exports.readScript = exports.addLog = exports.stepLog = exports.log = exports.color = exports.asyncForEach = exports.getInput = exports.readEnv = void 0;
const fs = __importStar(__webpack_require__(747)); const fs = __importStar(__webpack_require__(747));
const path = __importStar(__webpack_require__(622)); const path = __importStar(__webpack_require__(622));
const core = __importStar(__webpack_require__(470)); const core = __importStar(__webpack_require__(470));
/**
* Function to read environment variable and return a string value.
*
* @param property
*/
async function readEnv(property) {
const value = process.env[property];
switch (value) {
case undefined:
return '';
default:
return value;
}
}
exports.readEnv = readEnv;
/** /**
* Function to get inputs from both with and env annotations. * Function to get inputs from both with and env annotations.
* *
@ -1045,13 +1080,17 @@ const core = __importStar(__webpack_require__(470));
* @param mandatory * @param mandatory
*/ */
async function getInput(name, mandatory) { async function getInput(name, mandatory) {
const input = process.env[name]; const input = core.getInput(name);
switch (input) { const env_input = await readEnv(name);
case '': switch (true) {
case undefined: case input != '':
return core.getInput(name, { required: mandatory });
default:
return input; return input;
case input == '' && env_input != '':
return env_input;
case input == '' && env_input == '' && mandatory:
throw new Error(`Input required and not supplied: ${name}`);
default:
return '';
} }
} }
exports.getInput = getInput; exports.getInput = getInput;
@ -1270,6 +1309,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
}; };
Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, "__esModule", { value: true });
const os = __importStar(__webpack_require__(87)); const os = __importStar(__webpack_require__(87));
const utils_1 = __webpack_require__(82);
/** /**
* Commands * Commands
* *
@ -1323,28 +1363,14 @@ class Command {
return cmdStr; return cmdStr;
} }
} }
/**
* Sanitizes an input into a string so it can be passed into issueCommand safely
* @param input input to sanitize into a string
*/
function toCommandValue(input) {
if (input === null || input === undefined) {
return '';
}
else if (typeof input === 'string' || input instanceof String) {
return input;
}
return JSON.stringify(input);
}
exports.toCommandValue = toCommandValue;
function escapeData(s) { function escapeData(s) {
return toCommandValue(s) return utils_1.toCommandValue(s)
.replace(/%/g, '%25') .replace(/%/g, '%25')
.replace(/\r/g, '%0D') .replace(/\r/g, '%0D')
.replace(/\n/g, '%0A'); .replace(/\n/g, '%0A');
} }
function escapeProperty(s) { function escapeProperty(s) {
return toCommandValue(s) return utils_1.toCommandValue(s)
.replace(/%/g, '%25') .replace(/%/g, '%25')
.replace(/\r/g, '%0D') .replace(/\r/g, '%0D')
.replace(/\n/g, '%0A') .replace(/\n/g, '%0A')
@ -1378,6 +1404,8 @@ var __importStar = (this && this.__importStar) || function (mod) {
}; };
Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, "__esModule", { value: true });
const command_1 = __webpack_require__(431); const command_1 = __webpack_require__(431);
const file_command_1 = __webpack_require__(102);
const utils_1 = __webpack_require__(82);
const os = __importStar(__webpack_require__(87)); const os = __importStar(__webpack_require__(87));
const path = __importStar(__webpack_require__(622)); const path = __importStar(__webpack_require__(622));
/** /**
@ -1404,9 +1432,17 @@ var ExitCode;
*/ */
// eslint-disable-next-line @typescript-eslint/no-explicit-any // eslint-disable-next-line @typescript-eslint/no-explicit-any
function exportVariable(name, val) { function exportVariable(name, val) {
const convertedVal = command_1.toCommandValue(val); const convertedVal = utils_1.toCommandValue(val);
process.env[name] = convertedVal; process.env[name] = convertedVal;
command_1.issueCommand('set-env', { name }, convertedVal); const filePath = process.env['GITHUB_ENV'] || '';
if (filePath) {
const delimiter = '_GitHubActionsFileCommandDelimeter_';
const commandValue = `${name}<<${delimiter}${os.EOL}${convertedVal}${os.EOL}${delimiter}`;
file_command_1.issueCommand('ENV', commandValue);
}
else {
command_1.issueCommand('set-env', { name }, convertedVal);
}
} }
exports.exportVariable = exportVariable; exports.exportVariable = exportVariable;
/** /**
@ -1422,7 +1458,13 @@ exports.setSecret = setSecret;
* @param inputPath * @param inputPath
*/ */
function addPath(inputPath) { function addPath(inputPath) {
command_1.issueCommand('add-path', {}, inputPath); const filePath = process.env['GITHUB_PATH'] || '';
if (filePath) {
file_command_1.issueCommand('PATH', inputPath);
}
else {
command_1.issueCommand('add-path', {}, inputPath);
}
process.env['PATH'] = `${inputPath}${path.delimiter}${process.env['PATH']}`; process.env['PATH'] = `${inputPath}${path.delimiter}${process.env['PATH']}`;
} }
exports.addPath = addPath; exports.addPath = addPath;
@ -2335,7 +2377,6 @@ const coverage = __importStar(__webpack_require__(635));
const extensions = __importStar(__webpack_require__(911)); const extensions = __importStar(__webpack_require__(911));
const tools = __importStar(__webpack_require__(534)); const tools = __importStar(__webpack_require__(534));
const utils = __importStar(__webpack_require__(163)); const utils = __importStar(__webpack_require__(163));
const matchers = __importStar(__webpack_require__(86));
/** /**
* Build the script * Build the script
* *
@ -2346,7 +2387,7 @@ const matchers = __importStar(__webpack_require__(86));
async function build(filename, version, os_version) { async function build(filename, version, os_version) {
// taking inputs // taking inputs
const name = 'setup-php'; const name = 'setup-php';
const url = 'setup-php.com/support'; const url = 'https://setup-php.com/support';
const extension_csv = (await utils.getInput('extensions', false)) || const extension_csv = (await utils.getInput('extensions', false)) ||
(await utils.getInput('extension', false)) || (await utils.getInput('extension', false)) ||
(await utils.getInput('extension-csv', false)); (await utils.getInput('extension-csv', false));
@ -2396,7 +2437,6 @@ async function run() {
await exec_1.exec('pwsh ' + script_path + ' ' + version + ' ' + __dirname); await exec_1.exec('pwsh ' + script_path + ' ' + version + ' ' + __dirname);
break; break;
} }
await matchers.addMatchers();
} }
catch (error) { catch (error) {
core.setFailed(error.message); core.setFailed(error.message);

981
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
{ {
"name": "setup-php", "name": "setup-php",
"version": "1.9.5", "version": "1.9.7",
"private": false, "private": false,
"description": "Setup PHP for use with GitHub Actions", "description": "Setup PHP for use with GitHub Actions",
"main": "dist/index.js", "main": "dist/index.js",
@ -24,28 +24,28 @@
"author": "shivammathur", "author": "shivammathur",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"@actions/core": "^1.2.4", "@actions/core": "^1.2.6",
"@actions/exec": "^1.0.4", "@actions/exec": "^1.0.4",
"@actions/io": "^1.0.2", "@actions/io": "^1.0.2",
"fs": "0.0.1-security" "fs": "0.0.1-security"
}, },
"devDependencies": { "devDependencies": {
"@types/jest": "^26.0.10", "@types/jest": "^26.0.14",
"@types/node": "^14.0.27", "@types/node": "^14.11.2",
"@typescript-eslint/eslint-plugin": "^3.9.0", "@typescript-eslint/eslint-plugin": "^4.3.0",
"@typescript-eslint/parser": "^3.9.0", "@typescript-eslint/parser": "^4.3.0",
"@zeit/ncc": "^0.22.3", "@zeit/ncc": "^0.22.3",
"eslint": "^7.7.0", "eslint": "^7.10.0",
"eslint-config-prettier": "^6.11.0", "eslint-config-prettier": "^6.12.0",
"eslint-plugin-import": "^2.22.0", "eslint-plugin-import": "^2.22.1",
"eslint-plugin-jest": "^23.20.0", "eslint-plugin-jest": "^24.0.2",
"eslint-plugin-prettier": "^3.1.4", "eslint-plugin-prettier": "^3.1.4",
"husky": "^4.2.5", "husky": "^4.3.0",
"jest": "^26.4.0", "jest": "^26.4.2",
"jest-circus": "^26.4.0", "jest-circus": "^26.4.2",
"prettier": "^2.0.5", "prettier": "^2.1.2",
"ts-jest": "^26.2.0", "ts-jest": "^26.4.1",
"typescript": "^3.9.7" "typescript": "^4.0.3"
}, },
"husky": { "husky": {
"skipCI": true, "skipCI": true,

View File

@ -5,7 +5,6 @@ import * as coverage from './coverage';
import * as extensions from './extensions'; import * as extensions from './extensions';
import * as tools from './tools'; import * as tools from './tools';
import * as utils from './utils'; import * as utils from './utils';
import * as matchers from './matchers';
/** /**
* Build the script * Build the script
@ -21,7 +20,7 @@ export async function build(
): Promise<string> { ): Promise<string> {
// taking inputs // taking inputs
const name = 'setup-php'; const name = 'setup-php';
const url = 'setup-php.com/support'; const url = 'https://setup-php.com/support';
const extension_csv: string = const extension_csv: string =
(await utils.getInput('extensions', false)) || (await utils.getInput('extensions', false)) ||
(await utils.getInput('extension', false)) || (await utils.getInput('extension', false)) ||
@ -79,7 +78,6 @@ export async function run(): Promise<void> {
await exec('pwsh ' + script_path + ' ' + version + ' ' + __dirname); await exec('pwsh ' + script_path + ' ' + version + ' ' + __dirname);
break; break;
} }
await matchers.addMatchers();
} catch (error) { } catch (error) {
core.setFailed(error.message); core.setFailed(error.message);
} }

View File

@ -1,18 +0,0 @@
import * as path from 'path';
import * as utils from './utils';
import * as io from '@actions/io';
/**
* Cache json files for problem matchers
*/
export async function addMatchers(): Promise<void> {
const config_path = path.join(
__dirname,
'..',
'src',
'configs',
'phpunit.json'
);
const runner_dir: string = await utils.getInput('RUNNER_TOOL_CACHE', false);
await io.cp(config_path, runner_dir);
}

View File

@ -124,7 +124,7 @@ configure_composer() {
exit 1; exit 1;
fi fi
composer -q global config process-timeout 0 composer -q global config process-timeout 0
echo "::add-path::/Users/$USER/.composer/vendor/bin" echo "/Users/$USER/.composer/vendor/bin" >> "$GITHUB_PATH"
if [ -n "$COMPOSER_TOKEN" ]; then if [ -n "$COMPOSER_TOKEN" ]; then
composer -q global config github-oauth.github.com "$COMPOSER_TOKEN" composer -q global config github-oauth.github.com "$COMPOSER_TOKEN"
fi fi
@ -204,6 +204,7 @@ setup_php() {
tick="✓" tick="✓"
cross="✗" cross="✗"
version=$1 version=$1
dist=$2
tool_path_dir="/usr/local/bin" tool_path_dir="/usr/local/bin"
curl_opts=(-sL) curl_opts=(-sL)
existing_version=$(php-config --version 2>/dev/null | cut -c 1-3) existing_version=$(php-config --version 2>/dev/null | cut -c 1-3)
@ -224,4 +225,5 @@ scan_dir=$(php --ini | grep additional | sed -e "s|.*: s*||")
sudo mkdir -p "$ext_dir" sudo mkdir -p "$ext_dir"
semver=$(php -v | head -n 1 | cut -f 2 -d ' ') semver=$(php -v | head -n 1 | cut -f 2 -d ' ')
configure_pecl configure_pecl
sudo mv "$dist"/../src/configs/*.json "$RUNNER_TOOL_CACHE/"
add_log "$tick" "PHP" "$status PHP $semver" add_log "$tick" "PHP" "$status PHP $semver"

View File

@ -155,7 +155,7 @@ configure_composer() {
exit 1; exit 1;
fi fi
composer -q global config process-timeout 0 composer -q global config process-timeout 0
echo "::add-path::/home/$USER/.composer/vendor/bin" echo "/home/$USER/.composer/vendor/bin" >> "$GITHUB_PATH"
if [ -n "$COMPOSER_TOKEN" ]; then if [ -n "$COMPOSER_TOKEN" ]; then
composer -q global config github-oauth.github.com "$COMPOSER_TOKEN" composer -q global config github-oauth.github.com "$COMPOSER_TOKEN"
fi fi
@ -254,6 +254,7 @@ cross="✗"
lists_updated="false" lists_updated="false"
pecl_config="false" pecl_config="false"
version=$1 version=$1
dist=$2
debconf_fix="DEBIAN_FRONTEND=noninteractive" debconf_fix="DEBIAN_FRONTEND=noninteractive"
apt_install="sudo $debconf_fix apt-fast install -y" apt_install="sudo $debconf_fix apt-fast install -y"
tool_path_dir="/usr/local/bin" tool_path_dir="/usr/local/bin"
@ -298,4 +299,5 @@ pecl_file="$scan_dir"/99-pecl.ini
echo '' | sudo tee "$pecl_file" >/dev/null 2>&1 echo '' | sudo tee "$pecl_file" >/dev/null 2>&1
sudo rm -rf /usr/local/bin/phpunit >/dev/null 2>&1 sudo rm -rf /usr/local/bin/phpunit >/dev/null 2>&1
sudo chmod 777 "$ini_file" "$pecl_file" "$tool_path_dir" sudo chmod 777 "$ini_file" "$pecl_file" "$tool_path_dir"
sudo mv "$dist"/../src/configs/*.json "$RUNNER_TOOL_CACHE/"
add_log "$tick" "PHP" "$status PHP $semver" add_log "$tick" "PHP" "$status PHP $semver"

View File

@ -8,7 +8,7 @@ param (
[ValidateNotNull()] [ValidateNotNull()]
[ValidateLength(1, [int]::MaxValue)] [ValidateLength(1, [int]::MaxValue)]
[string] [string]
$dir $dist
) )
Function Step-Log($message) { Function Step-Log($message) {
@ -43,6 +43,19 @@ Function Add-ToProfile {
} }
} }
Function Add-Printf {
if (-not(Test-Path "C:\Program Files\Git\usr\bin\printf.exe")) {
if(Test-Path "C:\msys64\usr\bin\printf.exe") {
New-Item -Path $php_dir\printf.exe -ItemType SymbolicLink -Value C:\msys64\usr\bin\printf.exe
} else {
Invoke-WebRequest -UseBasicParsing -Uri "https://github.com/shivammathur/printf/releases/latest/download/printf-x64.zip" -OutFile "$php_dir\printf.zip"
Expand-Archive -Path $php_dir\printf.zip -DestinationPath $php_dir -Force
}
} else {
New-Item -Path $php_dir\printf.exe -ItemType SymbolicLink -Value "C:\Program Files\Git\usr\bin\printf.exe"
}
}
Function Install-PhpManager() { Function Install-PhpManager() {
$module_path = "$php_dir\PhpManager\PhpManager.psm1" $module_path = "$php_dir\PhpManager\PhpManager.psm1"
if(-not (Test-Path $module_path -PathType Leaf)) { if(-not (Test-Path $module_path -PathType Leaf)) {
@ -136,7 +149,7 @@ Function Edit-ComposerConfig() {
exit 1; exit 1;
} }
composer -q global config process-timeout 0 composer -q global config process-timeout 0
Write-Output "::add-path::$env:APPDATA\Composer\vendor\bin" Write-Output "$env:APPDATA\Composer\vendor\bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8
if (Test-Path env:COMPOSER_TOKEN) { if (Test-Path env:COMPOSER_TOKEN) {
composer -q global config github-oauth.github.com $env:COMPOSER_TOKEN composer -q global config github-oauth.github.com $env:COMPOSER_TOKEN
} }
@ -238,6 +251,7 @@ if(-not(Test-Path -LiteralPath $current_profile)) {
New-Item -Path $current_profile -ItemType "file" -Force >$null 2>&1 New-Item -Path $current_profile -ItemType "file" -Force >$null 2>&1
} }
Add-Printf >$null 2>&1
Step-Log "Setup PhpManager" Step-Log "Setup PhpManager"
Install-PhpManager >$null 2>&1 Install-PhpManager >$null 2>&1
Add-Log $tick "PhpManager" "Installed" Add-Log $tick "PhpManager" "Installed"
@ -271,4 +285,5 @@ Set-PhpIniKey -Key 'date.timezone' -Value 'UTC' -Path $php_dir
Set-PhpIniKey -Key 'memory_limit' -Value '-1' -Path $php_dir Set-PhpIniKey -Key 'memory_limit' -Value '-1' -Path $php_dir
Enable-PhpExtension -Extension openssl, curl, opcache, mbstring -Path $php_dir Enable-PhpExtension -Extension openssl, curl, opcache, mbstring -Path $php_dir
Update-PhpCAInfo -Path $php_dir -Source CurrentUser Update-PhpCAInfo -Path $php_dir -Source CurrentUser
Move-Item -path $dist\..\src\configs\*.json -Destination $env:RUNNER_TOOL_CACHE
Add-Log $tick "PHP" "$status PHP $($installed.FullVersion)" Add-Log $tick "PHP" "$status PHP $($installed.FullVersion)"

View File

@ -2,6 +2,21 @@ import * as fs from 'fs';
import * as path from 'path'; import * as path from 'path';
import * as core from '@actions/core'; import * as core from '@actions/core';
/**
* Function to read environment variable and return a string value.
*
* @param property
*/
export async function readEnv(property: string): Promise<string> {
const value = process.env[property];
switch (value) {
case undefined:
return '';
default:
return value;
}
}
/** /**
* Function to get inputs from both with and env annotations. * Function to get inputs from both with and env annotations.
* *
@ -12,13 +27,17 @@ export async function getInput(
name: string, name: string,
mandatory: boolean mandatory: boolean
): Promise<string> { ): Promise<string> {
const input = process.env[name]; const input = core.getInput(name);
switch (input) { const env_input = await readEnv(name);
case '': switch (true) {
case undefined: case input != '':
return core.getInput(name, {required: mandatory});
default:
return input; return input;
case input == '' && env_input != '':
return env_input;
case input == '' && env_input == '' && mandatory:
throw new Error(`Input required and not supplied: ${name}`);
default:
return '';
} }
} }