diff --git a/.codecov.yml b/.codecov.yml index 645dc264..81eb4aaf 100644 --- a/.codecov.yml +++ b/.codecov.yml @@ -1,2 +1,3 @@ ignore: - - "src/InfluxDB2Generated/**/*" \ No newline at end of file + - "src/InfluxDB2/Model/*" + - "src/InfluxDB2/Model/**/*" \ No newline at end of file diff --git a/.gitignore b/.gitignore index 14a47ced..c5e978fe 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,5 @@ composer.lock build/ .idea/ coverage.xml +/scripts/.m2/ +/generated/ diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 00000000..a332202e --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,5 @@ +## 1.0.0 [unreleased] + +### Features +1. [#4](https://github.com/influxdata/influxdb-client-php/issues/4): Use Makefile Targets Instead of scripts dir +1. [#7](https://github.com/influxdata/influxdb-client-php/issues/7): Set User-Agent to influxdb-client-php/VERSION for all requests diff --git a/Makefile b/Makefile index 1555833c..b30bb100 100644 --- a/Makefile +++ b/Makefile @@ -1,29 +1,52 @@ -### -# Docker Targets -## -TARGET=v2.0.0-alpha.4 +.DEFAULT_GOAL := help + +help: + @echo "Please use \`make ' where is one of" + @echo " start-server to start the InfluxDB server" + @echo " stop-server to stop the InfluxDB server" + @echo " test to perform unit tests" + @echo " coverage to perform unit tests with code coverage" + @echo " coverage-show to show the code coverage report" + @echo " generate-sources to generate API sources from swagger.yml" + @echo " generate-sources to generate API sources from swagger.yml" + @echo " deps to installs the project dependencies" + @echo " dshell to start Docker Shell for Local Development" + @echo " release to release client with version specified by VERSION property . make release VERSION=1.5.0" # Docker Shell for Local Development dshell: - @docker-compose run --entrypoint=ash --rm php - -# This needs hard-coded to a version when the beta drops -generate-api-client: - @rm -rf src/InfluxDB2Generated - @docker container run --rm -it -v ${PWD}:/code -w /code openapitools/openapi-generator-cli:latest \ - generate \ - -i https://raw.githubusercontent.com/influxdata/influxdb/$(TARGET)/http/swagger.yml \ - -g php \ - -o /code/src/InfluxDB2Generated \ - --api-package ApiClient \ - --invoker-package InfluxDB2Generated - -### -# Normal Targets -### + @docker-compose run --entrypoint=bash --rm php + deps: @composer install -test: - @./bin/phpspec run - @./bin/phpunit +generate-sources: + @scripts/generate-sources.sh + +test: start-server + @docker-compose run php composer run test + +coverage: start-server + @docker-compose run php composer run test-coverage + +coverage-show: + open build/coverage-report/index.html + +start-server: + @docker-compose up -d influxdb_v2 + @scripts/influxdb-onboarding.sh ||: + +stop-server: + @docker-compose stop influxdb_v2 + +release: + $(if $(VERSION),,$(error VERSION is not defined. Pass via "make release VERSION=1.5.0")) + @echo Tagging $(VERSION) + git checkout master + git pull + sed -i '' -e "s/VERSION = '.*'/VERSION = '$(VERSION)'/" src/InfluxDB2/Client.php + git commit -am "release influxdb-client-php-$(VERSION)" + git tag v$(VERSION) + sed -i '' -e "s/VERSION = '.*'/VERSION = 'dev'/" src/InfluxDB2/Client.php + git commit -am "prepare for next development iteration" + git push origin --tags diff --git a/README.md b/README.md index 65b357ee..9105b271 100644 --- a/README.md +++ b/README.md @@ -191,11 +191,8 @@ $writeApi->write('h2o,location=west value=33i 15'); ## Local tests ```shell script -# start/restart InfluxDB2 on local machine using docker -./scripts/influxdb-restart.sh - # run unit & integration tests -composer test +make test ``` ## Contributing diff --git a/composer.json b/composer.json index 473e8d6d..ef0e97ed 100644 --- a/composer.json +++ b/composer.json @@ -4,7 +4,6 @@ "keywords": [ "InfluxDB" ], - "version": "0.0.1-alpha", "homepage": "https://www.github.com/influxdata/influxdb-client-php", "license": "MIT", "require": { @@ -32,7 +31,7 @@ }, "scripts": { "test": "vendor/bin/phpunit tests", - "test-ci": "vendor/bin/phpunit tests --log-junit build/junit.xml -v --coverage-html=build/coverage-report" + "test-coverage": "vendor/bin/phpunit tests --log-junit build/junit.xml -v --coverage-html=build/coverage-report" } } diff --git a/docker-compose.yml b/docker-compose.yml index 8a080347..eb8912b9 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -4,7 +4,14 @@ services: php: build: context: . - target: dev + dockerfile: Dockerfile volumes: - .:/code working_dir: /code + network_mode: host + + influxdb_v2: + image: quay.io/influxdb/influxdb:2.0.0-beta + ports: + - "9999:9999" + command: influxd --reporting-disabled diff --git a/scripts/generate-sources.sh b/scripts/generate-sources.sh index e67e3695..7d5e9e78 100755 --- a/scripts/generate-sources.sh +++ b/scripts/generate-sources.sh @@ -6,13 +6,18 @@ rm -rf "${SCRIPT_PATH}"/../generated # Generate client cd "${SCRIPT_PATH}"/ || exit -mvn org.openapitools:openapi-generator-maven-plugin:generate +docker run --rm -it \ + -v "${PWD}":/code \ + -v "${PWD}/../generated":/generated \ + -v "${PWD}/.m2":/root/.m2 \ + -w /code \ + maven:3.6-slim mvn org.openapitools:openapi-generator-maven-plugin:generate #### sync generated php files to src # delete old sources -rm "${SCRIPT_PATH}"/../src/InfluxDB2/API/* -rm "${SCRIPT_PATH}"/../src/InfluxDB2/Model/* +rm -f "${SCRIPT_PATH}"/../src/InfluxDB2/API/* +rm -f "${SCRIPT_PATH}"/../src/InfluxDB2/Model/* #cp -r "${SCRIPT_PATH}"/../generated/lib/ApiException.php "${SCRIPT_PATH}"/../src/InfluxDB2 cp -r "${SCRIPT_PATH}"/../generated/lib/ObjectSerializer.php "${SCRIPT_PATH}"/../src/InfluxDB2 diff --git a/scripts/influxdb-restart.sh b/scripts/influxdb-restart.sh deleted file mode 100755 index 591d06de..00000000 --- a/scripts/influxdb-restart.sh +++ /dev/null @@ -1,60 +0,0 @@ -#!/usr/bin/env bash -# -# The MIT License -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in -# all copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -# THE SOFTWARE. -# - -set -e - -DEFAULT_DOCKER_REGISTRY="quay.io/influxdb/" -DOCKER_REGISTRY="${DOCKER_REGISTRY:-$DEFAULT_DOCKER_REGISTRY}" - -DEFAULT_INFLUXDB_V2_REPOSITORY="influxdb" -DEFAULT_INFLUXDB_V2_VERSION="2.0.0-beta" -INFLUXDB_V2_REPOSITORY="${INFLUXDB_V2_REPOSITORY:-$DEFAULT_INFLUXDB_V2_REPOSITORY}" -INFLUXDB_V2_VERSION="${INFLUXDB_V2_VERSION:-$DEFAULT_INFLUXDB_V2_VERSION}" -INFLUXDB_V2_IMAGE=${DOCKER_REGISTRY}${INFLUXDB_V2_REPOSITORY}:${INFLUXDB_V2_VERSION} - -SCRIPT_PATH="$( cd "$(dirname "$0")" ; pwd -P )" - -docker kill influxdb_v2 || true -docker rm influxdb_v2 || true -docker network rm influx_network || true -docker network create -d bridge influx_network --subnet 192.168.0.0/24 --gateway 192.168.0.1 - -# -# InfluxDB 2.0 -# -echo -echo "Restarting InfluxDB 2.0 [${INFLUXDB_V2_IMAGE}] ... " -echo - -docker pull "${INFLUXDB_V2_IMAGE}" || true -docker run \ - --detach \ - --name influxdb_v2 \ - --network influx_network \ - --publish 9999:9999 \ - "${INFLUXDB_V2_IMAGE}" - -# -# Post onBoarding request to InfluxDB 2 -# -"${SCRIPT_PATH}"/influxdb-onboarding.sh \ No newline at end of file diff --git a/scripts/pom.xml b/scripts/pom.xml index 97775ff8..ae5964a5 100644 --- a/scripts/pom.xml +++ b/scripts/pom.xml @@ -28,7 +28,7 @@ false false - ${project.basedir}/../generated + /generated false diff --git a/src/InfluxDB2/Client.php b/src/InfluxDB2/Client.php index 71b47c1b..b932c027 100644 --- a/src/InfluxDB2/Client.php +++ b/src/InfluxDB2/Client.php @@ -4,6 +4,11 @@ class Client { + /** + * Client version updated by: 'make release VERSION=1.5.0' + */ + const VERSION = 'dev'; + public $options; public $closed = false; private $autoCloseable = array(); diff --git a/src/InfluxDB2/DefaultApi.php b/src/InfluxDB2/DefaultApi.php index 0c600f20..73f8c26a 100644 --- a/src/InfluxDB2/DefaultApi.php +++ b/src/InfluxDB2/DefaultApi.php @@ -40,6 +40,7 @@ public function post($payload, $uriPath, $queryParams, $limit = self::DEFAULT_TI $options = [ 'headers' => [ 'Authorization' => "Token {$this->options['token']}", + 'User-Agent' => 'influxdb-client-php/' . \InfluxDB2\Client::VERSION ], 'query' => $queryParams, 'body' => $payload, diff --git a/tests/DefaultApiTest.php b/tests/DefaultApiTest.php new file mode 100644 index 00000000..0e326b35 --- /dev/null +++ b/tests/DefaultApiTest.php @@ -0,0 +1,21 @@ +mockHandler->append(new Response(204)); + $this->writeApi->write('h2o,location=west value=33i 15'); + + $request = $this->mockHandler->getLastRequest(); + + $this->assertStringStartsWith('influxdb-client-php/', + strval($request->getHeader("User-Agent")[0])); + } +} diff --git a/tests/WriteApiTest.php b/tests/WriteApiTest.php index dc0e19a9..3115d867 100644 --- a/tests/WriteApiTest.php +++ b/tests/WriteApiTest.php @@ -2,8 +2,6 @@ namespace InfluxDB2Test; -use GuzzleHttp\Exception\RequestException; -use GuzzleHttp\Psr7\Request; use GuzzleHttp\Psr7\Response; use InfluxDB2\ApiException; use InfluxDB2\Point;