Skip to content

Commit

Permalink
Merge pull request #300 from shivammathur/develop
Browse files Browse the repository at this point in the history
2.6.0
  • Loading branch information
shivammathur committed Oct 15, 2020
2 parents 0ca827a + 465e63b commit 073c2e6
Show file tree
Hide file tree
Showing 26 changed files with 1,226 additions and 1,171 deletions.
2 changes: 1 addition & 1 deletion .github/CONTRIBUTING.md
Expand Up @@ -8,7 +8,7 @@ Please note that this project is released with a [Contributor Code of Conduct](C

* Fork the project.
* Make your bug fix or feature addition.
* Add tests for it. This is important so we don't break it in a future version unintentionally.
* Add tests for it, so we don't break it in a future version unintentionally.
* If editing the scripts, create a demo integration test.
* Send a pull request to the develop branch with all the details.

Expand Down
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/bug_report.md
Expand Up @@ -11,7 +11,7 @@ assignees: 'shivammathur'
<!-- Please describe the bug concisely. -->

**Version**
- [ ] I have checked releases and the bug exists in the latest patch version of `v1` or `v2`.
- [ ] I have checked releases, and the bug exists in the latest patch version of `v1` or `v2`.
- [ ] `v2`
- [ ] `v1`

Expand Down
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/feature_request.md
Expand Up @@ -11,7 +11,7 @@ assignees: 'shivammathur'
<!-- Please describe concisely the feature you want to add. -->

**Version**
- [ ] I have checked releases and the feature is missing in the latest patch version of `v2`.
- [ ] I have checked releases, and the feature is missing in the latest patch version of `v2`.

**Underlying issue**
<!-- Please describe the issue this would solve. -->
Expand Down
6 changes: 3 additions & 3 deletions .github/PULL_REQUEST_TEMPLATE.md
Expand Up @@ -5,12 +5,12 @@ labels: bug or enhancement

---

## A Pull Request should be associated with an Issue.
## A Pull Request should be associated with a Discussion.

> If you're fixing a bug, adding a new feature or improving something please provide the details in Issues,
> If you're fixing a bug, adding a new feature or improving something please provide the details in discussions,
> so that the development can be pointed in the intended direction.
Related issue: <!-- Please link the related issue -->
Related discussion: <!-- Please link the related discussion -->

> Further notes in [Contribution Guidelines](.github/CONTRIBUTING.md)
> Thank you for your contribution.
Expand Down
2 changes: 1 addition & 1 deletion .github/SECURITY.md
Expand Up @@ -7,7 +7,7 @@ The following versions of this project are supported for security updates.
| Version | Supported |
| ------- | ------------------ |
| 1.9.x | :white_check_mark: |
| 2.5.x | :white_check_mark: |
| 2.6.x | :white_check_mark: |

## Supported PHP Versions

Expand Down
54 changes: 44 additions & 10 deletions README.md
Expand Up @@ -8,7 +8,7 @@

<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://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?logo=open%20source%20initiative&logoColor=white&labelColor=555555"></a>
<a href="#tada-php-support" title="PHP Versions Supported"><img alt="PHP Versions Supported" src="https://img.shields.io/badge/php-5.3%20to%208.0-777bb3.svg?logo=php&logoColor=white&labelColor=555555"></a>
</p>
Expand Down Expand Up @@ -168,7 +168,7 @@ Both `GitHub-hosted` runners and `self-hosted` runners are supported on the foll

These tools can be setup globally using the `tools` input.

`blackfire`, `blackfire-player`, `codeception`, `composer`, `composer-normalize`, `composer-prefetcher`, `composer-require-checker`, `composer-unused`, `cs2pr`, `deployer`, `flex`, `grpc_php_plugin`, `infection`, `pecl`, `phan`, `phing`, `phinx`, `phive`, `phpcbf`, `phpcpd`, `php-config`, `php-cs-fixer`, `phpcs`, `phpize`, `phpmd`, `phpstan`, `phpunit`, `prestissimo`, `protoc`, `psalm`, `symfony`, `vapor-cli`
`behat`, `blackfire`, `blackfire-player`, `codeception`, `composer`, `composer-normalize`, `composer-prefetcher`, `composer-require-checker`, `composer-unused`, `cs2pr`, `deployer`, `flex`, `grpc_php_plugin`, `infection`, `pecl`, `phan`, `phing`, `phinx`, `phive`, `phpcbf`, `phpcpd`, `php-config`, `php-cs-fixer`, `phpcs`, `phpize`, `phpmd`, `phpspec`, `phpstan`, `phpunit`, `prestissimo`, `protoc`, `psalm`, `symfony`, `vapor-cli`

```yaml
- name: Setup PHP with tools
Expand Down Expand Up @@ -204,6 +204,7 @@ For example to setup `PHPUnit` on `PHP 7.2`.
```

**Notes**
- This is useful to set up tools which you only use in GitHub Actions, thus keeping your `composer.json` tidy.
- If you have a tool in your `composer.json`, do not setup it globally using this action as the two instances of the tool might conflict.
- Tools which cannot be setup gracefully leave an error message in the logs, the action is not interrupted.

Expand Down Expand Up @@ -275,6 +276,7 @@ Consider disabling the coverage using this PHP action for these reasons.

- Specify the PHP version you want to setup.
- Accepts a `string`. For example `'7.4'`.
- Accepts `latest` to set up the latest stable PHP version.
- See [PHP support](#tada-php-support) for supported PHP versions.

#### `extensions` (optional)
Expand Down Expand Up @@ -564,9 +566,11 @@ If you have a number of workflows which setup multiple tools or have many compos

### Problem Matchers

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.

#### PHP

Setup problem matchers for your `PHP` output by adding this step after the `setup-php` step. This will scan the logs for PHP errors and warnings, and surface them prominently in the GitHub Actions UI by creating annotations and log file decorations.
Setup problem matchers for your `PHP` output by adding this step after the `setup-php` step.

```yaml
- name: Setup problem matchers for PHP
Expand All @@ -575,29 +579,59 @@ Setup problem matchers for your `PHP` output by adding this step after the `setu

#### PHPUnit

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.
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"
```

#### Other Tools
#### PHPStan

PHPStan supports error reporting in GitHub Actions, so no problem matchers are required.

```yaml
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '7.4'
tools: phpstan

- name: Run PHPStan
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).
For examples refer to [cs2pr documentation](https://github.com/staabm/annotate-pull-request-from-checkstyle).

> Here is an example with `phpstan`.
> Here is an example with `phpcs`.
```yaml
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '7.4'
tools: cs2pr, phpstan
tools: cs2pr, phpcs

- name: PHPStan
run: phpstan analyse src --error-format=checkstyle | cs2pr
- name: Run phpcs
run: phpcs -q --report=checkstyle src | cs2pr
```

### Examples
Expand Down
59 changes: 30 additions & 29 deletions __tests__/install.test.ts
@@ -1,10 +1,11 @@
import * as install from '../src/install';
import * as utils from '../src/utils';

/**
* Mock install.ts
*/
jest.mock('../src/install', () => ({
build: jest.fn().mockImplementation(
getScript: jest.fn().mockImplementation(
async (
filename: string,
version: string,
Expand Down Expand Up @@ -39,24 +40,18 @@ jest.mock('../src/install', () => ({
run: jest.fn().mockImplementation(
async (): Promise<string> => {
const os_version: string = process.env['RUNNER_OS'] || '';
let version: string = process.env['php-version'] || '';
version = version.length > 1 ? version.slice(0, 3) : version + '.0';
let script = '';
switch (os_version) {
case 'darwin':
case 'linux':
script = await install.build(os_version + '.sh', version, os_version);
script += 'bash script.sh ' + version + ' ' + __dirname;
break;
case 'win32':
script = await install.build(os_version + '.sh', version, os_version);
script += 'pwsh script.ps1 ' + version + ' ' + __dirname;
break;
default:
script += os_version + ' is not supported';
}

return script;
const version: string = await utils.parseVersion(
await utils.getInput('php-version', true)
);
const tool = await utils.scriptTool(os_version);
const filename = os_version + (await utils.scriptExtension(os_version));
return [
await install.getScript(filename, version, os_version),
tool,
filename,
version,
__dirname
].join(' ');
}
)
}));
Expand Down Expand Up @@ -93,13 +88,13 @@ describe('Install', () => {

let script: string = '' + (await install.run());
expect(script).toContain('initial script');
expect(script).toContain('pwsh script.ps1 7.0 ' + __dirname);
expect(script).toContain('pwsh win32.ps1 7.0 ' + __dirname);

setEnv('7.3', 'win32', '', '', '', '');

script = '' + (await install.run());
expect(script).toContain('initial script');
expect(script).toContain('pwsh script.ps1 7.3 ' + __dirname);
expect(script).toContain('pwsh win32.ps1 7.3 ' + __dirname);

setEnv('7.3', 'win32', 'a, b', 'a=b', 'x', '');

Expand All @@ -108,15 +103,21 @@ describe('Install', () => {
expect(script).toContain('install extensions');
expect(script).toContain('edit php.ini');
expect(script).toContain('set coverage driver');
expect(script).toContain('pwsh script.ps1 7.3 ' + __dirname);
expect(script).toContain('pwsh win32.ps1 7.3 ' + __dirname);
});

it('Test install on linux', async () => {
setEnv('7.3', 'linux', '', '', '', '');

let script: string = '' + (await install.run());
expect(script).toContain('initial script');
expect(script).toContain('bash script.sh 7.3 ');
expect(script).toContain('bash linux.sh 7.3 ');

setEnv('latest', 'linux', '', '', '', '');

script = '' + (await install.run());
expect(script).toContain('initial script');
expect(script).toContain('bash linux.sh 7.4 ');

setEnv('7.3', 'linux', 'a, b', 'a=b', 'x', 'phpunit');

Expand All @@ -125,7 +126,7 @@ describe('Install', () => {
expect(script).toContain('install extensions');
expect(script).toContain('edit php.ini');
expect(script).toContain('set coverage driver');
expect(script).toContain('bash script.sh 7.3');
expect(script).toContain('bash linux.sh 7.3');
expect(script).toContain('add_tool');
});

Expand All @@ -134,7 +135,7 @@ describe('Install', () => {

let script: string = '' + (await install.run());
expect(script).toContain('initial script');
expect(script).toContain('bash script.sh 7.3 ' + __dirname);
expect(script).toContain('bash darwin.sh 7.3 ' + __dirname);

setEnv('7.3', 'darwin', 'a, b', 'a=b', 'x', '');

Expand All @@ -143,26 +144,26 @@ describe('Install', () => {
expect(script).toContain('install extensions');
expect(script).toContain('edit php.ini');
expect(script).toContain('set coverage driver');
expect(script).toContain('bash script.sh 7.3 ' + __dirname);
expect(script).toContain('bash darwin.sh 7.3 ' + __dirname);
});

it('Test malformed version inputs', async () => {
setEnv('7.4.1', 'darwin', '', '', '', '');

let script: string = '' + '' + (await install.run());
expect(script).toContain('initial script');
expect(script).toContain('bash script.sh 7.4 ' + __dirname);
expect(script).toContain('bash darwin.sh 7.4 ' + __dirname);

setEnv(8.0, 'darwin', '', '', '', '');

script = '' + (await install.run());
expect(script).toContain('initial script');
expect(script).toContain('bash script.sh 8.0 ' + __dirname);
expect(script).toContain('bash darwin.sh 8.0 ' + __dirname);

setEnv(8, 'darwin', '', '', '', '');

script = '' + (await install.run());
expect(script).toContain('initial script');
expect(script).toContain('bash script.sh 8.0 ' + __dirname);
expect(script).toContain('bash darwin.sh 8.0 ' + __dirname);
});
});
41 changes: 0 additions & 41 deletions __tests__/matchers.test.ts

This file was deleted.

0 comments on commit 073c2e6

Please sign in to comment.