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

Commit 30cf045

Browse files
authored
Merge pull request #38 from vivamera/add-phar-support
Add support for phar
2 parents 546ac2e + 659933a commit 30cf045

File tree

4 files changed

+47
-1
lines changed

4 files changed

+47
-1
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,14 @@ We have php5-curl dependency, if you have issues related to curl_init() please i
4949
sudo apt-get install php5-curl
5050
```
5151

52+
## Alternative Installation (using phar)
53+
54+
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):
55+
56+
[Latest release](https://github.com/codacy/php-codacy-coverage/releases/latest)
57+
58+
That's it already.
59+
5260
## Updating Codacy
5361

5462
To update Codacy, you will need your project API token. You can find the token in Project -> Settings -> Integrations -> Project API.

box.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"directories": [
3+
"src",
4+
"vendor"
5+
],
6+
"main": "bin/codacycoverage",
7+
"output": "build/codacy-coverage.phar",
8+
"stub": true
9+
}

circle.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,18 @@ dependencies:
66
pre:
77
- curl -s http://getcomposer.org/installer | php
88
- php composer.phar install -n
9+
- go get github.com/aktau/github-release
10+
- wget -O box.phar https://github.com/box-project/box2/releases/download/2.7.5/box-2.7.5.phar
911

1012
test:
1113
post:
1214
- php vendor/bin/phpunit --coverage-clover build/coverage/xml tests
1315
- php bin/codacycoverage clover build/coverage/xml
16+
17+
deployment:
18+
release:
19+
tag: /[0-9]+(\.[0-9]+)*/
20+
commands:
21+
- php -d phar.readonly=0 box.phar build
22+
- git config user.name $CIRCLE_PROJECT_USERNAME
23+
- github-release upload --user $CIRCLE_PROJECT_USERNAME --repo $CIRCLE_PROJECT_REPONAME --tag $CIRCLE_TAG --name codacy-coverage.phar --file build/codacy-coverage.phar

src/Codacy/Coverage/Util/CodacyApiClient.php

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,12 @@ function __construct($baseUrl, $projectToken)
2525
*/
2626
public function sendCoverage($commit, $data)
2727
{
28+
$tempCertFile = $this->dumpCertificateBundle();
29+
2830
$url = $this->baseUrl . "/2.0/coverage/" . $commit . "/php";
2931

3032
$curl = curl_init($url);
33+
3134
curl_setopt($curl, CURLOPT_HEADER, false);
3235
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
3336
curl_setopt(
@@ -37,12 +40,14 @@ public function sendCoverage($commit, $data)
3740
"project_token: " . $this->projectToken
3841
)
3942
);
40-
curl_setopt($curl, CURLOPT_CAINFO, dirname(__FILE__) . '/cacert.pem');
43+
curl_setopt($curl, CURLOPT_CAINFO, $tempCertFile);
4144
curl_setopt($curl, CURLOPT_POST, true);
4245
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
4346

4447
$json_response = curl_exec($curl);
4548

49+
unlink($tempCertFile);
50+
4651
$status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
4752

4853
if ($status < 200 || $status > 201) {
@@ -63,4 +68,18 @@ public function sendCoverage($commit, $data)
6368
return $json['error'];
6469
}
6570
}
71+
72+
/**
73+
* Store certificate bundle to temporary file to be available when used within phar context
74+
*
75+
* @return string Full qualified path to temporary file
76+
*/
77+
protected function dumpCertificateBundle()
78+
{
79+
$tempCertFile = tempnam(sys_get_temp_dir(), 'cacert');
80+
81+
copy(dirname(__FILE__) . '/cacert.pem', $tempCertFile);
82+
83+
return $tempCertFile;
84+
}
6685
}

0 commit comments

Comments
 (0)