commit 16a9260572f3d11e7ecf6dd1028ae742d70c72de Author: D Ther Date: Wed Oct 14 16:17:09 2020 +0630 first commit diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..9d5ef6a --- /dev/null +++ b/Dockerfile @@ -0,0 +1,28 @@ +FROM golang:1.13 AS builder + +RUN apt-get update && apt-get -y install upx + +ENV GO111MODULE=on CGO_ENABLED=0 + +COPY . . + +RUN go build \ + -a \ + -trimpath \ + -ldflags "-s -w -extldflags '-static'" \ + -installsuffix cgo \ + -tags netgo \ + -o /bin/google-chat-action \ + . + +RUN strip /bin/google-chat-action + +RUN upx -q -9 /bin/google-chat-action + +FROM scratch + +COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ + +COPY --from=builder /bin/google-chat-action /bin/google-chat-action + +ENTRYPOINT ["/bin/google-chat-action"] diff --git a/README.md b/README.md new file mode 100644 index 0000000..0cb8de0 --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +# google-chat-action diff --git a/action.yml b/action.yml new file mode 100644 index 0000000..52de445 --- /dev/null +++ b/action.yml @@ -0,0 +1,14 @@ +name: 'Google Chat Action' +author: 'D Ther Htun' +description: 'Github actions for google chat Room Bot' +inputs: + msg: + description: 'Github Event Number' + required: true + webhook: + description: 'Google Chat Webhook URL' + required: true + +runs: + using: 'docker' + image: 'Dockerfile' diff --git a/main.go b/main.go new file mode 100644 index 0000000..eb7fc25 --- /dev/null +++ b/main.go @@ -0,0 +1,36 @@ +package main + +import ( + "bytes" + "fmt" + "net/http" + + "github.com/sethvargo/go-githubactions" +) + +func main() { + msg := githubactions.GetInput("msg") + if msg == "" { + githubactions.Fatalf("Missing input 'msg'") + } + webhook := githubactions.GetInput("webhook") + if webhook == "" { + githubactions.Fatalf("Missing input 'webshook'") + } + + fmt.Println("URL:> ", webhook) + + var jsonStr = []byte(fmt.Sprintf("{'text' : '%s'}", msg)) + req, err := http.NewRequest("POST", webhook, bytes.NewBuffer(jsonStr)) + if err != nil { + panic(err) + } + req.Header.Set("Content-Type", "application/json; charset=UTF-8") + client := &http.Client{} + resp, err := client.Do(req) + if err != nil { + panic(err) + } + defer resp.Body.Close() + fmt.Println("response Status:", resp.Status) +}