diff --git a/README.md b/README.md index 7ea1eff..6dd23ad 100644 --- a/README.md +++ b/README.md @@ -49,6 +49,14 @@ We have php5-curl dependency, if you have issues related to curl_init() please i sudo apt-get install php5-curl ``` +## Alternative Installation (using phar) + +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. + ## Updating Codacy To update Codacy, you will need your project API token. You can find the token in Project -> Settings -> Integrations -> Project API. diff --git a/box.json b/box.json new file mode 100644 index 0000000..c3c06a6 --- /dev/null +++ b/box.json @@ -0,0 +1,9 @@ +{ + "directories": [ + "src", + "vendor" + ], + "main": "bin/codacycoverage", + "output": "build/codacy-coverage.phar", + "stub": true +} diff --git a/circle.yml b/circle.yml index ba90e04..e0919d6 100644 --- a/circle.yml +++ b/circle.yml @@ -6,8 +6,18 @@ dependencies: pre: - curl -s http://getcomposer.org/installer | php - php composer.phar install -n + - go get github.com/aktau/github-release + - wget -O box.phar https://github.com/box-project/box2/releases/download/2.7.5/box-2.7.5.phar test: post: - php vendor/bin/phpunit --coverage-clover build/coverage/xml tests - php bin/codacycoverage clover build/coverage/xml + +deployment: + release: + tag: /[0-9]+(\.[0-9]+)*/ + commands: + - php -d phar.readonly=0 box.phar build + - git config user.name $CIRCLE_PROJECT_USERNAME + - github-release upload --user $CIRCLE_PROJECT_USERNAME --repo $CIRCLE_PROJECT_REPONAME --tag $CIRCLE_TAG --name codacy-coverage.phar --file build/codacy-coverage.phar \ No newline at end of file diff --git a/src/Codacy/Coverage/Util/CodacyApiClient.php b/src/Codacy/Coverage/Util/CodacyApiClient.php index 0f1fc27..8462dd2 100644 --- a/src/Codacy/Coverage/Util/CodacyApiClient.php +++ b/src/Codacy/Coverage/Util/CodacyApiClient.php @@ -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( @@ -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) { @@ -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; + } }