Skip to content

Commit

Permalink
Enable Scrutinizer analysis on new projects. Requires SCRUTINIZER_TOK…
Browse files Browse the repository at this point in the history
…EN environment variable be set.
  • Loading branch information
greg-1-anderson committed Apr 5, 2018
1 parent 68214d3 commit dc3bc32
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 19 deletions.
11 changes: 11 additions & 0 deletions .scrutinizer.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
checks:
php: true
filter:
excluded_paths:
- customize/*
- tests/*
tools:
php_sim: true
php_pdepend: true
php_analyzer: true
php_cs_fixer: false
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Starter

A starter PHP project with many services and features pre-configured. Simply clone and then customize to suit.
A starter PHP project with many services and features pre-configured. Simply use `composer create-project`, and a new GitHub repository will be created and configured to be tested on Travis CI.

## Usage

Expand Down Expand Up @@ -39,8 +39,8 @@ The following things are provided:
- Testing
- **Travis:** Automatically enables testing for the new project in Travis.
- [phpunit.xml.dist](/phpunit.xml.dist): Test configuration with code coverage (html coverage report configuration is present, but commented out).
- [Example.php](/src/Example.php): A simple class that multiplies.
- [ExampleTest.php](/tests/ExampleTest.php): A simple data-driven test that pulls fixture data from a data provider.
- [Example.php](/src/Example.php): A simple class that multiplies. Replace with your own code.
- [ExampleTest.php](/tests/ExampleTest.php): A simple data-driven test that pulls fixture data from a data provider. Replace with your own tests.
- **Coveralls:** Project must be manually configured on [coveralls.io](https://coveralls.io). PHPUnit and Travis are already configured to export coverage data to Coveralls automatically.
- **Appveyor:** An appveyor configuration file is provided, but project must be manually enabled on [appveyor](https://www.appveyor.com/) if Windows testing is desired.
- **Scrutinizer:** Project must be manually enabled on [scrutinizer-ci.com](https://scrutinizer-ci.com).
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"@cs"
],
"scenario": "scenarios/install",
"xxx-post-install-cmd": [
"post-create-project-cmd": [
"@customize"
],
"post-update-cmd": [
Expand Down
60 changes: 54 additions & 6 deletions customize/Customizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,15 @@ public function authenticatedUsername()
public function run()
{
$this->github_token = getenv('GITHUB_TOKEN');

// Providing TRAVIS_TOKEN is not required; GITHUB_TOKEN will
// be used if a Travis-specific token is not available.
$this->travis_token = getenv('TRAVIS_TOKEN');

// create an access token for Scrutinizer at:
// https://scrutinizer-ci.com/profile/applications
$this->scrutinizer_token = getenv('SCRUTINIZER_TOKEN');

// TODO: Notify and quit if github_token is not provided, or fails to authenticate.
$this->createGitHubClient($this->github_token);

Expand Down Expand Up @@ -157,9 +164,9 @@ public function run()

// Testing:
// 1. Enable testing on Travis via `travis enable`
// 2. Enable testing on AppVeyor (tbd)
// 3. Enable coveralls (tbd)
// 4. Enable scrutinizer (tbd)
// 2. Enable Scrutinizer via web API
// 3. Enable testing on AppVeyor (TODO)
// 4. Enable coveralls (TODO API not available)
$this->enableTesting();

// Make initial commit.
Expand All @@ -171,8 +178,8 @@ public function run()
$this->passthru("git push -u origin master");

// Composer:
// 1. Register with packagist? (tbd cli not provided)
// 2. Register with dependencies.io (tbd)
// 1. Register with packagist? (TODO API not available)
// 2. Register with dependencies.io (TODO API not available)
}

protected function readComposerJson($composer_path)
Expand Down Expand Up @@ -205,7 +212,7 @@ protected function placeTemplates()
protected function cleanupCustomization()
{
$fs = new Filesystem();
// $fs->remove($this->working_dir . '/customize');
$fs->remove($this->working_dir . '/customize');
}

protected function createRepository()
Expand All @@ -215,6 +222,12 @@ protected function createRepository()
}

protected function enableTesting()
{
$this->enableTravis();
$this->enableScrutinizer($this->project_name_and_org);
}

protected function enableTravis()
{
// If there is no travis token, log in with the github token
if (empty($this->travis_token)) {
Expand Down Expand Up @@ -242,6 +255,41 @@ protected function enableTesting()
}
}

protected function enableScrutinizer($project)
{
if (!$this->scrutinizer_token) {
print "No SCRUTINIZER_TOKEN environment variable provided; skipping Scrutinizer setup.\n";
return;
}

$uri = 'repositories/g';
$data = ['name' => $project];
$this->scrutinizerAPI($uri, $this->scrutinizer_token, $data);
}

function scrutinizerAPI($uri, $token, $data = [], $method = 'GET')
{
$url = "https://scrutinizer-ci.com/api/$uri?access_token=$token";
$headers = [
'Content-Type' => 'application/json',
'User-Agent' => 'my-org/my-app',
];
$guzzleParams = [ 'headers' => $headers, ];
if (!empty($data)) {
$method = 'POST';
$guzzleParams['json'] = $data;
}
$client = new \GuzzleHttp\Client();
$res = $client->request($method, $url, $guzzleParams);
$resultData = json_decode($res->getBody(), true);
$httpCode = $res->getStatusCode();
if ($httpCode >= 300) {
throw new \Exception("Scrutinizer API call $uri failed with $httpCode");
}

return $resultData;
}

protected function replaceContentsOfAllTemplateFiles($replacements)
{
$files = Finder::create()
Expand Down
20 changes: 11 additions & 9 deletions customize/templates/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,37 +10,39 @@ Put a one-line description of your project here.

## Getting Started

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system.
Explain how to get a copy of this project up and running on a new user's local machine.

See deployment for notes on how to deploy the project on a live system.

### Prerequisites

What things you need to install the software and how to install them
List the things that are needed to install the software and how to install them. For most PHP projects, it should usually be sufficient to run:

```
Give examples
composer install
```

### Installing

A step by step series of examples that tell you have to get a development env running
Provide a step by step series of examples that show how to install this project.

Say what the step will be
Say what the step will be:

```
Give the example
```

And repeat
And repeat:

```
until finished
```

End with an example of getting some data out of the system or using it for a little demo
End with an example of getting some data out of the system or using it for a little demo.

## Running the tests

The test suite may be run locally by way of some simple composer scripts.
The test suite may be run locally by way of some simple composer scripts:

| Test | Command
| ---------------- | ---
Expand All @@ -53,7 +55,7 @@ The test suite may be run locally by way of some simple composer scripts.

## Deployment

Add additional notes about how to deploy this on a live system
Add additional notes about how to deploy this on a live system.

## Built With

Expand Down

0 comments on commit dc3bc32

Please sign in to comment.