Skip to content

Commit 544738a

Browse files
authored
Add GitHub Action for integration of event reporter (#96)
1 parent 9f26787 commit 544738a

File tree

7 files changed

+201
-3
lines changed

7 files changed

+201
-3
lines changed

.github/scripts/entrypoint.sh

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/usr/bin/env sh
2+
#
3+
# Licensed to the Apache Software Foundation (ASF) under one or more
4+
# contributor license agreements. See the NOTICE file distributed with
5+
# this work for additional information regarding copyright ownership.
6+
# The ASF licenses this file to You under the Apache License, Version 2.0
7+
# (the "License"); you may not use this file except in compliance with
8+
# the License. You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS,
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
# See the License for the specific language governing permissions and
16+
# limitations under the License.
17+
#
18+
19+
echo ::save-state name=START_TIME::$(date +%s)000

.github/scripts/post-entrypoint.sh

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#!/usr/bin/env sh
2+
#
3+
# Licensed to the Apache Software Foundation (ASF) under one or more
4+
# contributor license agreements. See the NOTICE file distributed with
5+
# this work for additional information regarding copyright ownership.
6+
# The ASF licenses this file to You under the Apache License, Version 2.0
7+
# (the "License"); you may not use this file except in compliance with
8+
# the License. You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS,
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
# See the License for the specific language governing permissions and
16+
# limitations under the License.
17+
#
18+
19+
set -ex
20+
21+
echo "Reporting event..."
22+
23+
/swctl \
24+
--grpcAddr="$OAP_URL" \
25+
event report \
26+
--uuid="$(cat /proc/sys/kernel/random/uuid)" \
27+
--name="$NAME" \
28+
--service="$SERVICE" \
29+
--instance="$INSTANCE" \
30+
--endpoint="$ENDPOINT" \
31+
--message="$MESSAGE" \
32+
--startTime="$STATE_START_TIME" \
33+
--endTime=$(date +%s)000 \
34+
$PARAMETERS

Dockerfile

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one or more
2+
# contributor license agreements. See the NOTICE file distributed with
3+
# this work for additional information regarding copyright ownership.
4+
# The ASF licenses this file to You under the Apache License, Version 2.0
5+
# (the "License"); you may not use this file except in compliance with
6+
# the License. You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
FROM golang:1.14 AS builder
17+
18+
ENV CGO_ENABLED=0
19+
ENV GO111MODULE=on
20+
21+
WORKDIR /cli
22+
23+
COPY go.* ./
24+
25+
RUN go mod download
26+
27+
COPY . .
28+
29+
RUN make linux && mv bin/swctl-*-linux-amd64 /swctl
30+
31+
FROM alpine
32+
33+
COPY --from=builder /swctl /swctl
34+
35+
COPY .github/scripts/* /
36+
37+
ENTRYPOINT [ "/swctl" ]

Makefile

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,13 @@
1515
# limitations under the License.
1616
#
1717

18-
VERSION ?= latest
18+
VERSION ?= dev-$(shell git rev-parse --short HEAD)
19+
APP_NAME = skywalking-cli
1920
OUT_DIR = bin
2021
BINARY = swctl
2122

23+
HUB ?= docker.io/apache
24+
2225
RELEASE_BIN = skywalking-cli-$(VERSION)-bin
2326
RELEASE_SRC = skywalking-cli-$(VERSION)-src
2427

@@ -144,13 +147,17 @@ check-codegen:
144147
exit 1; \
145148
fi
146149

150+
.PHONY: docker
151+
docker:
152+
docker build . -t $(HUB)/$(APP_NAME):$(VERSION)
153+
147154
.PHONY: test-commands
148155
test-commands:
149156
@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 \
150157
docker container stop oap; \
151158
docker container prune -f; \
152159
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; \
153160
fi
154-
./scripts/test_commands.sh
161+
VERSION=$(VERSION) ./scripts/test_commands.sh
155162
@docker container stop oap
156163
@docker container prune -f

README.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -748,6 +748,45 @@ spec:
748748
749749
</details>
750750
751+
<details>
752+
<summary>Report events in CD workflows - GitHub Actions</summary>
753+
754+
Integrate skywalking-cli into your CD workflows to report events, this is an implementation of GitHub Actions, but we
755+
welcome you to contribute plugins of other CD platforms, like Jenkins, GitLab, etc.
756+
757+
The usage of integration for GitHub Actions is as follows.
758+
759+
```yaml
760+
# ...
761+
762+
jobs:
763+
deploy:
764+
strategy:
765+
matrix:
766+
instance:
767+
- asia-southeast
768+
- asia-northeast
769+
name: Deploy Product Service
770+
runs-on: ubuntu-latest
771+
steps:
772+
# other steps such as checkout ...
773+
774+
- name: Wrap the deployment steps with skywalking-cli
775+
uses: apache/skywalking-cli@main # we always suggest using a revision instead of `main`
776+
with:
777+
oap-url: ${{ secrets.OAP_URL }} # Required. Set the OAP backend URL, such as example.com:11800
778+
auth-token: ${{ secrets.OAP_AUTH_TOKEN }} # Optional. OAP auth token if you enable authentication in OAP
779+
service: product # Required. Name of the service to be deployed
780+
instance: ${{ matrix.instance }} # Required. Name of the instance to be deployed
781+
endpoint: "" # Optional. Endpoint of the service, if any
782+
message: "Upgrade from {fromVersion} to {toVersion}" # Optional. The message of the event
783+
parameters: "" # Optional. The parameters in the message, if any
784+
785+
# your package / deployment steps...
786+
```
787+
788+
</details>
789+
751790
# Contributing
752791
For developers who want to contribute to this project, see [Contribution Guide](CONTRIBUTING.md)
753792

action.yaml

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
#
2+
# Licensed to the Apache Software Foundation (ASF) under one or more
3+
# contributor license agreements. See the NOTICE file distributed with
4+
# this work for additional information regarding copyright ownership.
5+
# The ASF licenses this file to You under the Apache License, Version 2.0
6+
# (the "License"); you may not use this file except in compliance with
7+
# the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
name: SkyWalking Event Reporter
18+
description: Report GitHub workflow events to Apache SkyWalking
19+
author: Apache SkyWalking
20+
inputs:
21+
oap-url:
22+
description: URL of SkyWalking OAP
23+
required: true
24+
auth-token:
25+
description: Authorization token of SkyWalking OAP
26+
required: false
27+
name:
28+
description: The name of the event, for example, "Upgrade"
29+
required: false
30+
default: Upgrade
31+
service:
32+
description: The service name of the event
33+
required: true
34+
instance:
35+
description: The service instance of the event
36+
required: true
37+
endpoint:
38+
description: The service endpoint of the event, if any
39+
required: false
40+
message:
41+
description: The message of the event
42+
required: false
43+
default: Upgrade from {fromVersion} to {toVersion}
44+
parameters:
45+
description: The parameters in the message
46+
required: false
47+
default: ""
48+
49+
runs:
50+
using: docker
51+
image: Dockerfile
52+
env:
53+
OAP_URL: ${{ inputs.oap-url }}
54+
AUTH_TOKEN: ${{ inputs.auth-token }}
55+
NAME: ${{ inputs.name }}
56+
SERVICE: ${{ inputs.service }}
57+
INSTANCE: ${{ inputs.instance }}
58+
ENDPOINT: ${{ inputs.endpoint }}
59+
MESSAGE: ${{ inputs.message }}
60+
PARAMETERS: ${{ inputs.parameters }}
61+
entrypoint: /entrypoint.sh
62+
post-entrypoint: /post-entrypoint.sh

scripts/test_commands.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ else
2121
os="linux"
2222
fi
2323

24-
swctl="bin/swctl-latest-${os}-amd64 --base-url=http://localhost:12800/graphql"
24+
swctl="bin/swctl-${VERSION}-${os}-amd64 --base-url=http://localhost:12800/graphql"
2525

2626
retries=1
2727
max_retries=10

0 commit comments

Comments
 (0)