Skip to content
This repository has been archived by the owner on Feb 19, 2020. It is now read-only.

Commit

Permalink
Add phar support
Browse files Browse the repository at this point in the history
### Added
- support to build phar using `box-project/box2`
- support to provide certificate bundle via temporary file to avoid curl issue when using phar, see (https://bugs.php.net/bug.php?id=69035) for further details
- support to create phar during travis build and attach it to release
  • Loading branch information
MaSpeng committed Mar 22, 2018
1 parent 546ac2e commit 2cb1cd3
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 1 deletion.
13 changes: 13 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,23 @@ before_script:
# In case of timeouts and build failures you may want to prepend 'travis_retry' to the following commands:
- curl -s http://getcomposer.org/installer | php
- php composer.phar install -n
- wget -O box.phar https://github.com/box-project/box2/releases/download/2.7.5/box-2.7.5.phar

# Explicitly use the phpunit from composer, not any system-wide found
script:
- php vendor/bin/phpunit --coverage-clover build/coverage/xml tests

after_success:
- php vendor/bin/codacycoverage clover build/coverage/xml

before_deploy:
- php -d phar.readonly=0 box.phar build && chmod +x build/codacy-coverage.phar

deploy:
provider: releases
skip_cleanup: true
api_key:
secure: <api-key>
file: build/codacy-coverage.phar
on:
tags: true
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@

# Installation

Setup codacy-coverage as phar, you can simply download a pre-compiled and ready-to-use version as a phar to any directory. Simply download the latest `codacy-coverage.phar` file from our [releases page](https://github.com/codacy/php-codacy-coverage/releases):

[Latest release](https://github.com/codacy/php-codacy-coverage/releases/latest)

That's it already.

Setup codacy-coverage with Composer, just add the following to your composer.json:

```js
Expand Down
9 changes: 9 additions & 0 deletions box.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"directories": [
"src",
"vendor"
],
"main": "bin/codacycoverage",
"output": "build/codacy-coverage.phar",
"stub": true
}
21 changes: 20 additions & 1 deletion src/Codacy/Coverage/Util/CodacyApiClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,12 @@ function __construct($baseUrl, $projectToken)
*/
public function sendCoverage($commit, $data)
{
$tempCertFile = $this->dumpCertificateBundle();

$url = $this->baseUrl . "/2.0/coverage/" . $commit . "/php";

$curl = curl_init($url);

curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt(
Expand All @@ -37,12 +40,14 @@ public function sendCoverage($commit, $data)
"project_token: " . $this->projectToken
)
);
curl_setopt($curl, CURLOPT_CAINFO, dirname(__FILE__) . '/cacert.pem');
curl_setopt($curl, CURLOPT_CAINFO, $tempCertFile);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);

$json_response = curl_exec($curl);

unlink($tempCertFile);

$status = curl_getinfo($curl, CURLINFO_HTTP_CODE);

if ($status < 200 || $status > 201) {
Expand All @@ -63,4 +68,18 @@ public function sendCoverage($commit, $data)
return $json['error'];
}
}

/**
* Store certificate bundle to temporary file to be available when used within phar context
*
* @return string Full qualified path to temporary file
*/
protected function dumpCertificateBundle()
{
$tempCertFile = tempnam(sys_get_temp_dir(), 'cacert');

copy(dirname(__FILE__) . '/cacert.pem', $tempCertFile);

return $tempCertFile;
}
}

0 comments on commit 2cb1cd3

Please sign in to comment.