Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update GitHub actions #215

Merged
merged 2 commits into from
May 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
on:
push:
branches: [main]
pull_request:
branches: [main]

jobs:
build:
name: Check Build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '>=1.19.0'

- name: Verify dependencies
run: go mod verify

- name: Build
run: go build -v ./...
39 changes: 0 additions & 39 deletions .github/workflows/golangci-lint.yml

This file was deleted.

20 changes: 20 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
on:
push:
branches: [main]
pull_request:
branches: [main]

jobs:
lint:
name: Lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '>=1.19.0'

- name: Run golangci-lint
uses: golangci/golangci-lint-action@v3
23 changes: 23 additions & 0 deletions .github/workflows/staticcheck.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
on:
push:
branches: [main]
pull_request:
branches: [main]

jobs:
staticcheck:
name: Staticcheck
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '>=1.19.0'

- name: Install staticcheck
run: go install honnef.co/go/tools/cmd/staticcheck@latest

- name: Run staticcheck
run: staticcheck ./...
23 changes: 23 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
on:
push:
branches: [main]
pull_request:
branches: [main]

jobs:
test:
name: Test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '>=1.19.0'

- name: Verify dependencies
run: go mod verify

- name: Run tests
run: go test -race -vet=off ./...
20 changes: 20 additions & 0 deletions .github/workflows/vet.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
on:
push:
branches: [main]
pull_request:
branches: [main]

jobs:
vet:
name: Go Vet
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '>=1.19.0'

- name: Run go vet
run: go vet ./...
1 change: 0 additions & 1 deletion cmd/db_connect/db_connect.go

This file was deleted.

2 changes: 1 addition & 1 deletion cmd/test_logger/test_logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ func main() {
logger.Warning("warning")
logger.Error("error")
//logger.Panic("panic")
logger.Fatal("fatal")
//logger.Fatal("fatal")
}
1 change: 0 additions & 1 deletion container/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
logger "github.com/br0-space/bot-logger"
"github.com/br0-space/bot/interfaces"
"github.com/br0-space/bot/pkg/config"
_ "github.com/br0-space/bot/pkg/config"
"github.com/br0-space/bot/pkg/db"
"github.com/br0-space/bot/pkg/fortune"
"github.com/br0-space/bot/pkg/matcher"
Expand Down
12 changes: 6 additions & 6 deletions pkg/webhook/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func (h *Handler) InitMatchers() {
func (h *Handler) ServeHTTP(res http.ResponseWriter, req *http.Request) {
h.log.Debugf("%s %s %s from %s", req.Method, req.URL, req.Proto, req.RemoteAddr)

messageIn, err, status := h.parseRequest(req)
messageIn, status, err := h.parseRequest(req)
if err != nil {
h.log.Error(err)
http.Error(res, err.Error(), status)
Expand All @@ -45,21 +45,21 @@ func (h *Handler) ServeHTTP(res http.ResponseWriter, req *http.Request) {
h.processRequest(*messageIn)
}

func (h *Handler) parseRequest(req *http.Request) (*interfaces.TelegramWebhookMessageStruct, error, int) {
func (h *Handler) parseRequest(req *http.Request) (*interfaces.TelegramWebhookMessageStruct, int, error) {
if req.Method != http.MethodPost {
return nil, fmt.Errorf("method not allowed: %s (actual) != POST (expected)", req.Method), http.StatusMethodNotAllowed
return nil, http.StatusMethodNotAllowed, fmt.Errorf("method not allowed: %s (actual) != POST (expected)", req.Method)
}

body := &interfaces.TelegramWebhookBodyStruct{}
if err := json.NewDecoder(req.Body).Decode(body); err != nil {
return nil, fmt.Errorf("unable to decode request body: %s", err.Error()), http.StatusBadRequest
return nil, http.StatusBadRequest, fmt.Errorf("unable to decode request body: %s", err.Error())
}

if body.Message.Chat.ID != h.cfg.Telegram.ChatID {
return nil, fmt.Errorf("chat id mismatch: %d (actual) != %d (expected)", body.Message.Chat.ID, h.cfg.Telegram.ChatID), http.StatusOK
return nil, http.StatusOK, fmt.Errorf("chat id mismatch: %d (actual) != %d (expected)", body.Message.Chat.ID, h.cfg.Telegram.ChatID)
}

return &body.Message, nil, 0
return &body.Message, 0, nil
}

func (h *Handler) processRequest(messageIn interfaces.TelegramWebhookMessageStruct) {
Expand Down