Skip to content

Commit

Permalink
feat: add User-Agent request header, use Makefile Targets as a base f…
Browse files Browse the repository at this point in the history
…or commands (#9)

* feat: remove hardcoded version from composer.json - https://getcomposer.org/doc/02-libraries.md#library-versioning
* feat: move scripts into Makefile (#4)
* feat: add User-Agent request header, add release command to Makefile
* docs: added CHANGELOG.md
  • Loading branch information
bednar authored Mar 3, 2020
1 parent bf9592b commit bca2f1e
Show file tree
Hide file tree
Showing 14 changed files with 101 additions and 97 deletions.
3 changes: 2 additions & 1 deletion .codecov.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
ignore:
- "src/InfluxDB2Generated/**/*"
- "src/InfluxDB2/Model/*"
- "src/InfluxDB2/Model/**/*"
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ composer.lock
build/
.idea/
coverage.xml
/scripts/.m2/
/generated/
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
69 changes: 46 additions & 23 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,29 +1,52 @@
###
# Docker Targets
##
TARGET=v2.0.0-alpha.4
.DEFAULT_GOAL := help

help:
@echo "Please use \`make <target>' where <target> 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
5 changes: 1 addition & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
"keywords": [
"InfluxDB"
],
"version": "0.0.1-alpha",
"homepage": "https://www.github.com/influxdata/influxdb-client-php",
"license": "MIT",
"require": {
Expand Down Expand Up @@ -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"
}

}
9 changes: 8 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
11 changes: 8 additions & 3 deletions scripts/generate-sources.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
60 changes: 0 additions & 60 deletions scripts/influxdb-restart.sh

This file was deleted.

2 changes: 1 addition & 1 deletion scripts/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<generateModelTests>false</generateModelTests>

<verbose>false</verbose>
<output>${project.basedir}/../generated</output>
<output>/generated</output>
<addCompileSourceRoot>false</addCompileSourceRoot>
</configuration>
</plugin>
Expand Down
5 changes: 5 additions & 0 deletions src/InfluxDB2/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
1 change: 1 addition & 0 deletions src/InfluxDB2/DefaultApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
21 changes: 21 additions & 0 deletions tests/DefaultApiTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace InfluxDB2Test;

use GuzzleHttp\Psr7\Response;

require_once('BasicTest.php');

class DefaultApiTest extends BasicTest
{
public function testUserAgent()
{
$this->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]));
}
}
2 changes: 0 additions & 2 deletions tests/WriteApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

namespace InfluxDB2Test;

use GuzzleHttp\Exception\RequestException;
use GuzzleHttp\Psr7\Request;
use GuzzleHttp\Psr7\Response;
use InfluxDB2\ApiException;
use InfluxDB2\Point;
Expand Down

0 comments on commit bca2f1e

Please sign in to comment.