From 2cb1cd39f6e6483991b4f2cd1091d5afd22ed079 Mon Sep 17 00:00:00 2001 From: Unknown Date: Thu, 22 Mar 2018 10:13:22 +0100 Subject: [PATCH 1/4] Add phar support ### 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 --- .travis.yml | 13 ++++++++++++ README.md | 6 ++++++ box.json | 9 +++++++++ src/Codacy/Coverage/Util/CodacyApiClient.php | 21 +++++++++++++++++++- 4 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 box.json diff --git a/.travis.yml b/.travis.yml index 81ccf07..63b2221 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,6 +10,7 @@ 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: @@ -17,3 +18,15 @@ script: 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: + file: build/codacy-coverage.phar + on: + tags: true diff --git a/README.md b/README.md index 7ea1eff..0bb6592 100644 --- a/README.md +++ b/README.md @@ -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 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/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; + } } From c951719d9a7992351273436605db2c984520ef70 Mon Sep 17 00:00:00 2001 From: Unknown Date: Thu, 22 Mar 2018 15:35:26 +0100 Subject: [PATCH 2/4] Updated readme Moved description for alternative installation method at the end of the installation description. --- README.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 0bb6592..78f499e 100644 --- a/README.md +++ b/README.md @@ -15,12 +15,6 @@ # 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 @@ -55,6 +49,12 @@ We have php5-curl dependency, if you have issues related to curl_init() please i sudo apt-get install php5-curl ``` +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. From e4a7c3b0c3468b52e51eea7566826d988001e5e0 Mon Sep 17 00:00:00 2001 From: Unknown Date: Thu, 22 Mar 2018 16:39:56 +0100 Subject: [PATCH 3/4] Update CI configuration Revertet changes to travis ci configuration and added required deployment changes to CircleCi configuration. --- .travis.yml | 13 ------------- circle.yml | 10 ++++++++++ 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/.travis.yml b/.travis.yml index 63b2221..81ccf07 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,7 +10,6 @@ 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: @@ -18,15 +17,3 @@ script: 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: - file: build/codacy-coverage.phar - on: - tags: 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 From 659933ad851fc86f12b96bc4a295a782005b5ee9 Mon Sep 17 00:00:00 2001 From: Unknown Date: Thu, 22 Mar 2018 16:52:54 +0100 Subject: [PATCH 4/4] Updated readme Added separate title for alternative installation using phar. --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 78f499e..6dd23ad 100644 --- a/README.md +++ b/README.md @@ -49,6 +49,8 @@ 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)