diff --git a/php/.gitignore b/php/.gitignore new file mode 100644 index 00000000..2ab84e67 --- /dev/null +++ b/php/.gitignore @@ -0,0 +1 @@ +wechaty-php-grpc.*/ diff --git a/php/Makefile b/php/Makefile new file mode 100644 index 00000000..78f31cd6 --- /dev/null +++ b/php/Makefile @@ -0,0 +1,26 @@ +# Makefile for PHP Wechaty +# +# GitHb: https://github.com/wechaty/php-wechaty +# Author: Chunsheng Zhang https://git.io/JJmKd +# + +.PHONY: all +all : clean lint + +.PHONY: clean +clean: + rm -fr generated/* + +.PHONY: test +test: + bash -x ./generate.sh + php grpc_test.php + +.PHONY: generate +generate: + bash -x ./generate.sh + +.PHONY: publish +publish: clean generate + ./publish.sh + diff --git a/php/generate.sh b/php/generate.sh new file mode 100755 index 00000000..891b341d --- /dev/null +++ b/php/generate.sh @@ -0,0 +1,31 @@ +#!/usr/bin/env bash + +set -eo pipefail + +PROTO_BASE_DIR=../proto +PROTO_PUPPET_DIR=$PROTO_BASE_DIR/wechaty/puppet +PROTO_WECHATY_DIR=$PROTO_BASE_DIR/wechaty + +OUT_WECHATY_DIR=./generated/wechaty +OUT_PUPPET_DIR=$OUT_WECHATY_DIR + +if [ ! -d "$PUPPET_GEN_DIR" ]; then + mkdir -p $OUT_PUPPET_DIR +fi + +protoc --version + +protoc \ + -I $PROTO_PUPPET_DIR \ + --php_out=$OUT_PUPPET_DIR \ + --grpc_out=$OUT_PUPPET_DIR \ + --plugin=protoc-gen-grpc=../../grpc-demo/grpc/bins/opt/grpc_php_plugin \ + $PROTO_PUPPET_DIR/*.proto + +protoc \ + -I $PROTO_WECHATY_DIR \ + -I $PROTO_PUPPET_DIR \ + --php_out=$OUT_WECHATY_DIR \ + --grpc_out=$OUT_WECHATY_DIR \ + --plugin=protoc-gen-grpc=../../grpc-demo/grpc/bins/opt/grpc_php_plugin \ + $PROTO_WECHATY_DIR/*.proto diff --git a/php/grpc_test.php b/php/grpc_test.php new file mode 100644 index 00000000..8717d397 --- /dev/null +++ b/php/grpc_test.php @@ -0,0 +1,30 @@ + Grpc\ChannelCredentials::createInsecure() +]); +$request = new \Wechaty\Puppet\DingRequest(); +list($response, $status) = $client->Ding($request)->wait(); +echo sprintf("code: %s, msg: %s \n", $status->code, $status->details); diff --git a/php/publish.sh b/php/publish.sh new file mode 100755 index 00000000..07569314 --- /dev/null +++ b/php/publish.sh @@ -0,0 +1,45 @@ +#!/usr/bin/env bash + +set -eo pipefail + +GENERATED_DIR="$(pwd)/generated" + +VERSION=$(jq -r .version ../package.json) +DEPLOY_DIR="wechaty-php-grpc.$$" + +mkdir "$DEPLOY_DIR" +pushd "$DEPLOY_DIR" +# trap "rm -rfv $(pwd)/$DEPLOY_DIR" EXIT + +git clone git@github.com:wechaty/php-grpc.git +cd php-grpc +cp -Rav "$GENERATED_DIR"/wechaty . +echo "$VERSION" > VERSION + +if [ -z "$(git status --porcelain)" ]; then + echo + echo "[Publish] There's no new generated code found" + echo + exit 0 +fi + +git \ + -c "user.name=zhangchunsheng" \ + -c "user.email=zhangchunsheng423@gmail.com" \ + \ + commit \ + -am "Deploy PHP Grpc Module v${VERSION}" + +git push +echo +echo '[Publish] New code has been generated and pushed' +echo + +git tag v"$VERSION" +git push origin v"$VERSION" +echo +echo "[Publish] New version ${VERSION} has been tagged" +echo + +git status +popd