Skip to content

Commit 7ef0a54

Browse files
authored
Merge pull request #61 from hollodotme/issue-54/selfupdate-rollback-logs-docs
issue-54/selfupdate-rollback-logs-docs
2 parents 68786c3 + d05241a commit 7ef0a54

11 files changed

+307
-42
lines changed

CHANGELOG.md

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Change Log
2+
3+
All notable changes to this project will be documented in this file.
4+
This project adheres to [Semantic Versioning](http://semver.org/) and [Keep a CHANGELOG](http://keepachangelog.com).
5+
6+
## [Unreleased]
7+
8+
### Added
9+
10+
- Executable .phar file for download
11+
- `upload` command (PHAR only) - same as calling the tool without a command when installed via composer.
12+
- `self-update` / `selfupdate` command (PHAR only)
13+
- `rollback` command (PHAR only)
14+
- [Installation / Usage](./README.md) / [Distribution instructions](./DEVELOPING.md) for the PHAR tool
15+
16+
[Unreleased]: https://github.com/codeclimate/php-test-reporter/compare/v0.3.2...HEAD

DEVELOPING.md

+32-6
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,44 @@
11
# Developing
22

3-
- Get the source
3+
## Get the source
44

55
$ git clone https://github.com/codeclimate/php-test-reporter
66

7-
- Install dependencies
7+
## Install dependencies
88

99
$ curl -sS https://getcomposer.org/installer | php
10-
$ php composer.phar install --dev
10+
$ php composer.phar update -o -v
1111

12-
- Run the tests
12+
## Run the tests
1313

1414
$ ./vendor/bin/phpunit
15+
16+
### With HTML coverage output:
1517

16-
- Submit PRs to https://github.com/codeclimate/php-test-reporter
18+
$ ./vendor/bin/phpunit --coverage-html=build/logs/coverage
1719

18-
*Note*: all changes and fixes must have appropriate test coverage.
20+
## Build the PHAR tool
21+
22+
# Create a new git tag (optional)
23+
$ git tag v1.x.x -m 'Version 1.x.x'
24+
# Build the PHAR using box project
25+
$ ./vendor/bin/box build
26+
27+
## Distribute the PHAR tool
28+
29+
### With verification and compatibility for phar.io / PhiVE
30+
31+
* [Create a GPG key](https://phar.io/howto/generate-gpg-key.html) (Should be the repositoy's maintainer one)
32+
* [Create a signature and upload to Github](https://phar.io/howto/sign-and-upload-to-github.html)
33+
34+
### Without verification
35+
36+
* Go to the [releases section on Github](https://github.com/codeclimate/php-test-reporter/releases)
37+
* Click "Edit" on the latest tag/release
38+
* Add the `codeclimate-test-reporter.phar` in the "Attach binaries..." section
39+
* Click "Update release"
40+
41+
## Contribute
42+
43+
* Submit PRs to: https://github.com/codeclimate/php-test-reporter
44+
* *Note*: all changes and fixes must have appropriate test coverage.

README.md

+19-4
Original file line numberDiff line numberDiff line change
@@ -46,16 +46,27 @@ This package requires a user, but not necessarily a paid account, on
4646
Code Climate, so if you don't have one the first step is to signup at:
4747
https://codeclimate.com.
4848

49+
### Via composer
50+
4951
To install php-test-reporter with Composer run the following command.
5052

5153
```shell
52-
composer require codeclimate/php-test-reporter --dev
54+
$ composer require codeclimate/php-test-reporter --dev
5355
```
5456

5557
This will get you the latest version of the reporter and install it. If you do want the master, untagged, version you may use the command below:
5658

5759
```shell
58-
composer require codeclimate/php-test-reporter:@dev --dev
60+
$ composer require codeclimate/php-test-reporter:@dev --dev
61+
```
62+
63+
### As PHAR tool
64+
65+
Checkout the [latest release here](https://github.com/codeclimate/php-test-reporter/releases) and replace `X.X.X` with the latest version.
66+
67+
```shell
68+
$ RELEASE=X.X.X
69+
$ wget -c "https://github.com/codeclimate/php-test-reporter/releases/download/$RELEASE/codeclimate-test-reporter.phar"
5970
```
6071

6172
## Usage
@@ -77,15 +88,19 @@ Add the following to phpunit.xml.dist:
7788

7889
Or invoke `phpunit` as follows:
7990

80-
```
91+
```shell
8192
$ phpunit --coverage-clover build/logs/clover.xml
8293
```
8394

8495
- Specifying your repo token as an environment variable, invoke the
8596
test-reporter:
8697

87-
```
98+
```shell
8899
$ CODECLIMATE_REPO_TOKEN="..." vendor/bin/test-reporter
100+
101+
# ... or via PHAR ...
102+
103+
$ CODECLIMATE_REPO_TOKEN="..." codeclimate-test-reporter.phar upload
89104
```
90105

91106
The `CODECLIMATE_REPO_TOKEN` value is provided after you add your repo

box.json

+37-21
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,39 @@
11
{
2-
"alias": "codeclimate-test-reporter.phar",
3-
"chmod": "0755",
4-
"directories": ["src"],
5-
"compactors": [
6-
"Herrera\\Box\\Compactor\\Php"
7-
],
8-
"extract": true,
9-
"files": [
10-
"LICENSE"
11-
],
12-
"finder": [
13-
{
14-
"name": ["*.php", "*.pem"],
15-
"exclude": ["tests"],
16-
"in": ["vendor"]
17-
}
18-
],
19-
"git-version": "package_version",
20-
"main": "composer/bin/test-reporter",
21-
"output": "codeclimate-test-reporter.phar",
22-
"stub": true
2+
"chmod": "0755",
3+
"compression": "GZ",
4+
"alias": "codeclimate-test-reporter.phar",
5+
"directories": [
6+
"src"
7+
],
8+
"compactors": [
9+
"Herrera\\Box\\Compactor\\Php"
10+
],
11+
"extract": false,
12+
"intercept": true,
13+
"files": [
14+
"LICENSE"
15+
],
16+
"finder": [
17+
{
18+
"name": [
19+
"*.php",
20+
"*.pem"
21+
],
22+
"exclude": [
23+
"bin",
24+
"tests",
25+
"phpunit",
26+
"tm"
27+
],
28+
"in": [
29+
"vendor"
30+
]
31+
}
32+
],
33+
"git-version": "package_version",
34+
"main": "phar/bin/main.php",
35+
"metadata": "The code climate php test reporter",
36+
"output": "build/codeclimate-test-reporter.phar",
37+
"shebang": "#!/usr/bin/env php",
38+
"stub": true
2339
}

composer.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@
1919
"php": ">=5.3",
2020
"ext-curl": "*",
2121
"satooshi/php-coveralls": "^1.0",
22-
"symfony/console": "^2.0|^3.0"
22+
"symfony/console": "^2.0|^3.0",
23+
"psr/log": "^1.0",
24+
"padraic/phar-updater": "^1.0"
2325
},
2426
"require-dev": {
2527
"phpunit/phpunit": "3.7.*@stable",

phar/bin/main.php

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
/**
3+
* @author hollodotme <[email protected]>
4+
*/
5+
6+
namespace CodeClimate\PhpTestReporter;
7+
8+
use CodeClimate\PhpTestReporter\ConsoleCommands\RollbackCommand;
9+
use CodeClimate\PhpTestReporter\ConsoleCommands\SelfUpdateCommand;
10+
use CodeClimate\PhpTestReporter\ConsoleCommands\UploadCommand;
11+
use Symfony\Component\Console\Application;
12+
13+
require(__DIR__ . '/../../vendor/autoload.php');
14+
15+
try {
16+
$app = new Application('Code Climate PHP Test Reporter', '@package_version@');
17+
$app->addCommands(
18+
[
19+
new UploadCommand('upload'),
20+
new SelfUpdateCommand('self-update'),
21+
new RollbackCommand('rollback'),
22+
]
23+
);
24+
25+
$code = $app->run();
26+
27+
exit($code);
28+
} catch (\Exception $e) {
29+
echo 'Uncaught Exception ' . get_class($e) . ' with message: ' . $e->getMessage() . PHP_EOL;
30+
echo $e->getTraceAsString();
31+
32+
exit(1);
33+
}

src/Application.php

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
namespace CodeClimate\PhpTestReporter;
33

4-
use CodeClimate\PhpTestReporter\ConsoleCommands\TestReporterCommand;
4+
use CodeClimate\PhpTestReporter\ConsoleCommands\UploadCommand;
55
use Symfony\Component\Console\Application as BaseApplication;
66
use Symfony\Component\Console\Input\InputInterface;
77

@@ -19,7 +19,7 @@ class Application extends BaseApplication
1919
*/
2020
protected function getCommandName(InputInterface $input)
2121
{
22-
return 'test-reporter';
22+
return 'upload';
2323
}
2424

2525
/**
@@ -31,18 +31,18 @@ protected function getDefaultCommands()
3131
// Keep the core default commands to have the HelpCommand
3232
// which is used when using the --help option
3333
$defaultCommands = parent::getDefaultCommands();
34-
$defaultCommands[] = $this->createTestReporterCommand();
34+
$defaultCommands[] = $this->createUploadCommand();
3535

3636
return $defaultCommands;
3737
}
3838

3939
/**
40-
* Create TestReporterCommand.
41-
* @return TestReporterCommand
40+
* Create UploadCommand.
41+
* @return UploadCommand
4242
*/
43-
protected function createTestReporterCommand()
43+
protected function createUploadCommand()
4444
{
45-
$command = new TestReporterCommand();
45+
$command = new UploadCommand('upload');
4646

4747
return $command;
4848
}
+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
/**
3+
* @author hollodotme
4+
*/
5+
6+
namespace CodeClimate\PhpTestReporter\ConsoleCommands;
7+
8+
use CodeClimate\PhpTestReporter\Constants\PharTool;
9+
use Humbug\SelfUpdate\Strategy\GithubStrategy;
10+
use Humbug\SelfUpdate\Updater;
11+
use Symfony\Component\Console\Command\Command;
12+
use Symfony\Component\Console\Input\InputInterface;
13+
use Symfony\Component\Console\Logger\ConsoleLogger;
14+
use Symfony\Component\Console\Output\OutputInterface;
15+
16+
/**
17+
* Class RollbackCommand
18+
* @package CodeClimate\PhpTestReporter\ConsoleCommands
19+
*/
20+
class RollbackCommand extends Command
21+
{
22+
protected function configure()
23+
{
24+
$this->setDescription('Rolls back this PHAR to the previous version.');
25+
}
26+
27+
/**
28+
* @param InputInterface $input
29+
* @param OutputInterface $output
30+
*
31+
* @return int
32+
*/
33+
protected function execute(InputInterface $input, OutputInterface $output)
34+
{
35+
$input->validate();
36+
$logger = new ConsoleLogger($output);
37+
$updater = new Updater(null, false, Updater::STRATEGY_GITHUB);
38+
39+
/** @var GithubStrategy $strategy */
40+
$strategy = $updater->getStrategy();
41+
42+
$strategy->setPackageName(PharTool::PACKAGE_NAME);
43+
$strategy->setPharName(PharTool::PHAR_NAME);
44+
$strategy->setCurrentLocalVersion('@package_version@');
45+
46+
if ($updater->rollback()) {
47+
$logger->info('Roll back successful!');
48+
} else {
49+
$logger->alert('Roll back failed.');
50+
}
51+
52+
return 0;
53+
}
54+
}

0 commit comments

Comments
 (0)