Add GitHub Action for integration of event reporter (#96)

diff --git a/.github/scripts/entrypoint.sh b/.github/scripts/entrypoint.sh
new file mode 100755
index 0000000..1bf3a37
--- /dev/null
+++ b/.github/scripts/entrypoint.sh
@@ -0,0 +1,19 @@
+#!/usr/bin/env sh
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+echo ::save-state name=START_TIME::$(date +%s)000
diff --git a/.github/scripts/post-entrypoint.sh b/.github/scripts/post-entrypoint.sh
new file mode 100755
index 0000000..3802e4d
--- /dev/null
+++ b/.github/scripts/post-entrypoint.sh
@@ -0,0 +1,34 @@
+#!/usr/bin/env sh
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+set -ex
+
+echo "Reporting event..."
+
+/swctl \
+    --grpcAddr="$OAP_URL" \
+    event report \
+    --uuid="$(cat /proc/sys/kernel/random/uuid)" \
+    --name="$NAME" \
+    --service="$SERVICE" \
+    --instance="$INSTANCE" \
+    --endpoint="$ENDPOINT" \
+    --message="$MESSAGE" \
+    --startTime="$STATE_START_TIME" \
+    --endTime=$(date +%s)000 \
+    $PARAMETERS
diff --git a/Dockerfile b/Dockerfile
new file mode 100644
index 0000000..264a581
--- /dev/null
+++ b/Dockerfile
@@ -0,0 +1,37 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+FROM golang:1.14 AS builder
+
+ENV CGO_ENABLED=0
+ENV GO111MODULE=on
+
+WORKDIR /cli
+
+COPY go.* ./
+
+RUN go mod download
+
+COPY . .
+
+RUN make linux && mv bin/swctl-*-linux-amd64 /swctl
+
+FROM alpine
+
+COPY --from=builder /swctl /swctl
+
+COPY .github/scripts/* /
+
+ENTRYPOINT [ "/swctl" ]
diff --git a/Makefile b/Makefile
index 448f123..cc61d7e 100644
--- a/Makefile
+++ b/Makefile
@@ -15,10 +15,13 @@
 # limitations under the License.
 #
 
-VERSION ?= latest
+VERSION ?= dev-$(shell git rev-parse --short HEAD)
+APP_NAME = skywalking-cli
 OUT_DIR = bin
 BINARY = swctl
 
+HUB ?= docker.io/apache
+
 RELEASE_BIN = skywalking-cli-$(VERSION)-bin
 RELEASE_SRC = skywalking-cli-$(VERSION)-src
 
@@ -144,6 +147,10 @@
 		exit 1; \
 	fi
 
+.PHONY: docker
+docker:
+	docker build . -t $(HUB)/$(APP_NAME):$(VERSION)
+
 .PHONY: test-commands
 test-commands:
 	@if ! docker run --name oap -p 12800:12800 -p 11800:11800 -d -e SW_HEALTH_CHECKER=default -e SW_TELEMETRY=prometheus apache/skywalking-oap-server:8.4.0-es7 > /dev/null 2>&1;then \
@@ -151,6 +158,6 @@
 		docker container prune -f; \
 		docker run --name oap -p 12800:12800 -p 11800:11800 -d -e SW_HEALTH_CHECKER=default -e SW_TELEMETRY=prometheus apache/skywalking-oap-server:8.4.0-es7; \
 	fi
-	./scripts/test_commands.sh
+	VERSION=$(VERSION) ./scripts/test_commands.sh
 	@docker container stop oap
 	@docker container prune -f
diff --git a/README.md b/README.md
index fbf8746..168b230 100644
--- a/README.md
+++ b/README.md
@@ -748,6 +748,45 @@
 
 </details>
 
+<details>
+<summary>Report events in CD workflows - GitHub Actions</summary>
+
+Integrate skywalking-cli into your CD workflows to report events, this is an implementation of GitHub Actions, but we
+welcome you to contribute plugins of other CD platforms, like Jenkins, GitLab, etc.
+
+The usage of integration for GitHub Actions is as follows.
+
+```yaml
+# ...
+
+jobs:
+  deploy:
+    strategy:
+      matrix:
+        instance:
+          - asia-southeast
+          - asia-northeast
+    name: Deploy Product Service
+    runs-on: ubuntu-latest
+    steps:
+      # other steps such as checkout ...
+
+      - name: Wrap the deployment steps with skywalking-cli
+        uses: apache/skywalking-cli@main # we always suggest using a revision instead of `main`
+        with:
+          oap-url: ${{ secrets.OAP_URL }}                       # Required. Set the OAP backend URL, such as example.com:11800
+          auth-token: ${{ secrets.OAP_AUTH_TOKEN }}             # Optional. OAP auth token if you enable authentication in OAP
+          service: product                                      # Required. Name of the service to be deployed
+          instance: ${{ matrix.instance }}                      # Required. Name of the instance to be deployed
+          endpoint: ""                                          # Optional. Endpoint of the service, if any
+          message: "Upgrade from {fromVersion} to {toVersion}"  # Optional. The message of the event
+          parameters: ""                                        # Optional. The parameters in the message, if any
+
+      # your package / deployment steps... 
+```
+
+</details>
+
 # Contributing
 For developers who want to contribute to this project, see [Contribution Guide](CONTRIBUTING.md)
 
diff --git a/action.yaml b/action.yaml
new file mode 100644
index 0000000..b511b17
--- /dev/null
+++ b/action.yaml
@@ -0,0 +1,62 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+name: SkyWalking Event Reporter
+description: Report GitHub workflow events to Apache SkyWalking
+author: Apache SkyWalking
+inputs:
+  oap-url:
+    description: URL of SkyWalking OAP
+    required: true
+  auth-token:
+    description: Authorization token of SkyWalking OAP
+    required: false
+  name:
+    description: The name of the event, for example, "Upgrade"
+    required: false
+    default: Upgrade
+  service:
+    description: The service name of the event
+    required: true
+  instance:
+    description: The service instance of the event
+    required: true
+  endpoint:
+    description: The service endpoint of the event, if any
+    required: false
+  message:
+    description: The message of the event
+    required: false
+    default: Upgrade from {fromVersion} to {toVersion}
+  parameters:
+    description: The parameters in the message
+    required: false
+    default: ""
+
+runs:
+  using: docker
+  image: Dockerfile
+  env:
+    OAP_URL: ${{ inputs.oap-url }}
+    AUTH_TOKEN: ${{ inputs.auth-token }}
+    NAME: ${{ inputs.name }}
+    SERVICE: ${{ inputs.service }}
+    INSTANCE: ${{ inputs.instance }}
+    ENDPOINT: ${{ inputs.endpoint }}
+    MESSAGE: ${{ inputs.message }}
+    PARAMETERS: ${{ inputs.parameters }}
+  entrypoint: /entrypoint.sh
+  post-entrypoint: /post-entrypoint.sh
diff --git a/scripts/test_commands.sh b/scripts/test_commands.sh
index 35b305b..3fe3fee 100755
--- a/scripts/test_commands.sh
+++ b/scripts/test_commands.sh
@@ -21,7 +21,7 @@
   os="linux"
 fi
 
-swctl="bin/swctl-latest-${os}-amd64 --base-url=http://localhost:12800/graphql"
+swctl="bin/swctl-${VERSION}-${os}-amd64 --base-url=http://localhost:12800/graphql"
 
 retries=1
 max_retries=10