Skip to content

Commit

Permalink
chore: fix CI actions (#70)
Browse files Browse the repository at this point in the history
  • Loading branch information
freak12techno committed Mar 28, 2024
1 parent 0fe086a commit 82420ae
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 30 deletions.
17 changes: 10 additions & 7 deletions .github/workflows/actions.yaml
Original file line number Diff line number Diff line change
@@ -1,23 +1,26 @@
name: test
on: [push]
permissions:
contents: read
checks: write
jobs:
go-build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- uses: actions/setup-go@v2
- uses: actions/setup-go@v5
with:
go-version: '1.18.2'
go-version: '1.21.3'
- run: go version
- run: go mod download
- run: go build cmd/cosmos-proposals-checker.go
go-vet:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- uses: actions/setup-go@v2
- uses: actions/setup-go@v5
with:
go-version: '1.18.2'
go-version: '1.21.3'
- run: go version
- run: go mod download
- run: go vet ./...
Expand All @@ -27,16 +30,16 @@ jobs:
steps:
- uses: actions/checkout@v2
- name: golangci-lint
uses: golangci/golangci-lint-action@v2
uses: golangci/golangci-lint-action@v4
with:
args: --timeout 300s
test:
name: test
runs-on: ubuntu-latest
steps:
- uses: actions/setup-go@v2
- uses: actions/setup-go@v5
with:
go-version: '1.18.2'
go-version: '1.21.3'
- name: Check out code into the Go module directory
uses: actions/checkout@v2
- name: Run tests
Expand Down
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,4 @@ linters:
- ifshort
- ireturn
- godox
- perfsprint
28 changes: 20 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

![Latest release](https://img.shields.io/github/v/release/QuokkaStake/cosmos-proposals-checker)
[![Actions Status](https://github.com/QuokkaStake/cosmos-proposals-checker/workflows/test/badge.svg)](https://github.com/QuokkaStake/cosmos-proposals-checker/actions)
[![codecov](https://codecov.io/gh/QuokkaStake/cosmos-proposals-checker/graph/badge.svg?token=3C1TDJAHZ0)](https://codecov.io/gh/QuokkaStake/cosmos-proposals-checker)

cosmos-proposals-checker is a tool that checks all configured chains for new proposals in voting period,
then notifies you if one or more of the configured wallets haven't voted on it. Like that:
Expand Down Expand Up @@ -39,7 +40,8 @@ Then we need to create a systemd service for our app:
sudo nano /etc/systemd/system/cosmos-proposals-checker.service
```

You can use this template (change the user to whatever user you want this to be executed from. It's advised to create a separate user for that instead of running it from root):
You can use this template (change the user to whatever user you want this to be executed from.
It's advised to create a separate user for that instead of running it from root):

```
[Unit]
Expand Down Expand Up @@ -78,22 +80,29 @@ sudo journalctl -u cosmos-proposals-checker -f --output cat

## How does it work?

It queries LCD nodes for the proposals list in voting period, then for each wallet it queries its vote. If you haven't voted, it spawns an alert and sends it to configured notifiers.
It queries LCD nodes for the proposals list in voting period, then for each wallet it queries its vote.
If you haven't voted, it spawns an alert and sends it to configured notifiers.

## How can I configure it?

All configuration is done via `.toml` config file, which is mandatory. Run the app with `--config <path/to/config.toml>` to specify config. Check out `config.example.toml` to see the params that can be set.
All configuration is done via `.toml` config file, which is mandatory.
Run the app with `--config <path/to/config.toml>` to specify config.
Check out `config.example.toml` to see the params that can be set.

## Notifiers

Currently, this program supports the following notifications channels:
1) Telegram

Go to @BotFather in Telegram and create a bot. After that, there are two options:
- you want to send messages to a user. This user should write a message to @getmyid_bot, then copy the `Your user ID` number. Also keep in mind that the bot won't be able to send messages unless you contact it first, so write a message to a bot before proceeding.
- you want to send messages to a channel. Write something to a channel, then forward it to @getmyid_bot and copy the `Forwarded from chat` number. Then add the bot as an admin.

To have fancy commands auto-suggestion, go to @BotFather again, select your bot -> Edit bot -> Edit description and paste the following:
- you want to send messages to a user. This user should write a message to @getmyid_bot, then copy
the `Your user ID` number. Also keep in mind that the bot won't be able to send messages unless you contact it first,
so write a message to a bot before proceeding.
- you want to send messages to a channel. Write something to a channel, then forward it to @getmyid_bot and copy
the `Forwarded from chat` number. Then add the bot as an admin.

To have fancy commands auto-suggestion, go to @BotFather again, select your bot -> Edit bot -> Edit description
and paste the following:
```
proposals - List proposals and wallets' votes on them
proposals_mute - Mutes a proposal
Expand All @@ -107,7 +116,10 @@ Then add a Telegram config to your config file (see `config.example.toml` for re

2) PagerDuty

Go to your PagerDuty page, then go to Services. Create a service if you haven't created one already. Select this service, then go to "Integrations" tab, add an integration there. Copy the integration key and add it to the `pagerduty` part in config (see `config.example.toml` for reference). Additionally, override PagerDuty URL in config if you are using EU version.
Go to your PagerDuty page, then go to Services. Create a service if you haven't created one already.
Select this service, then go to "Integrations" tab, add an integration there. Copy the integration key
and add it to the `pagerduty` part in config (see `config.example.toml` for reference).
Additionally, override PagerDuty URL in config if you are using EU version.


## Which networks this is guaranteed to work?
Expand Down
3 changes: 1 addition & 2 deletions pkg/fetchers/cosmos/params.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
package cosmos

import (
"fmt"
"main/pkg/fetchers/cosmos/responses"
"main/pkg/types"
"sync"
)

func (rpc *RPC) GetGovParams(paramsType string) (*responses.ParamsResponse, *types.QueryError) {
url := fmt.Sprintf("/cosmos/gov/v1beta1/params/%s", paramsType)
url := "/cosmos/gov/v1beta1/params/" + paramsType

var params responses.ParamsResponse
if errs := rpc.Client.Get(url, &params); len(errs) > 0 {
Expand Down
19 changes: 10 additions & 9 deletions pkg/fetchers/cosmos/tally.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cosmos

import (
"errors"
"fmt"
"main/pkg/fetchers/cosmos/responses"
"main/pkg/types"
Expand Down Expand Up @@ -30,7 +31,7 @@ func (rpc *RPC) GetTallies() (types.ChainTallyInfos, error) {
var wg sync.WaitGroup
var mutex sync.Mutex

errors := make([]error, 0)
errorsList := make([]error, 0)

var pool math.LegacyDec
var proposals []types.Proposal
Expand All @@ -46,10 +47,10 @@ func (rpc *RPC) GetTallies() (types.ChainTallyInfos, error) {

if err != nil {
rpc.Logger.Error().Err(err).Msg("Error fetching staking pool")
errors = append(errors, err)
errorsList = append(errorsList, err)
} else if poolResponse.Pool == nil {
rpc.Logger.Error().Err(err).Msg("Staking pool is empty!")
errors = append(errors, fmt.Errorf("staking pool is empty"))
errorsList = append(errorsList, errors.New("staking pool is empty"))
} else {
pool = poolResponse.Pool.BondedTokens
}
Expand All @@ -66,7 +67,7 @@ func (rpc *RPC) GetTallies() (types.ChainTallyInfos, error) {

if err != nil {
rpc.Logger.Error().Err(err).Msg("Error fetching chain proposals")
errors = append(errors, err)
errorsList = append(errorsList, err)

mutex.Unlock()
return
Expand Down Expand Up @@ -94,13 +95,13 @@ func (rpc *RPC) GetTallies() (types.ChainTallyInfos, error) {
Err(err).
Str("proposal_id", p.ID).
Msg("Error fetching tally for proposal")
errors = append(errors, err)
errorsList = append(errorsList, err)
} else if tally == nil {
rpc.Logger.Error().
Err(err).
Str("proposal_id", p.ID).
Msg("Tally is empty")
errors = append(errors, fmt.Errorf("tally is empty"))
errorsList = append(errorsList, errors.New("tally is empty"))
} else {
tallies[p.ID] = *tally
}
Expand All @@ -112,9 +113,9 @@ func (rpc *RPC) GetTallies() (types.ChainTallyInfos, error) {

wg.Wait()

if len(errors) > 0 {
if len(errorsList) > 0 {
rpc.Logger.Error().Msg("Errors getting tallies info, not processing")
return types.ChainTallyInfos{}, fmt.Errorf("could not get tallies info: got %d errors", len(errors))
return types.ChainTallyInfos{}, fmt.Errorf("could not get tallies info: got %d errors", len(errorsList))
}

tallyInfos := types.ChainTallyInfos{
Expand All @@ -125,7 +126,7 @@ func (rpc *RPC) GetTallies() (types.ChainTallyInfos, error) {
for index, proposal := range proposals {
tally, ok := tallies[proposal.ID]
if !ok {
return types.ChainTallyInfos{}, fmt.Errorf("could not get tallies info")
return types.ChainTallyInfos{}, errors.New("could not get tallies info")
}

tallyInfos.TallyInfos[index] = types.TallyInfo{
Expand Down
2 changes: 1 addition & 1 deletion pkg/reporters/pagerduty/pagerduty.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ func (r Reporter) SendAlert(alert Alert) error {
}

if response.Status != "success" {
return fmt.Errorf("expected 'success' status, got '" + response.Status + "'. Error: " + response.Message)
return errors.New("expected 'success' status, got '" + response.Status + "'. Error: " + response.Message)
}

return nil
Expand Down
3 changes: 1 addition & 2 deletions pkg/reporters/telegram/add_mute.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package telegram

import (
"bytes"
"fmt"

tele "gopkg.in/telebot.v3"
)
Expand All @@ -15,7 +14,7 @@ func (reporter *Reporter) HandleAddMute(c tele.Context) error {

mute, err := ParseMuteOptions(c.Text(), c)
if err != "" {
return c.Reply(fmt.Sprintf("Error muting notification: %s", err))
return c.Reply("Error muting notification: " + err)
}

reporter.MutesManager.AddMute(mute)
Expand Down
2 changes: 1 addition & 1 deletion pkg/reporters/telegram/telegram.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func (reporter *Reporter) GetTemplate(tmlpType string) (*template.Template, erro

reporter.Logger.Trace().Str("type", tmlpType).Msg("Loading template")

filename := fmt.Sprintf("%s.html", tmlpType)
filename := tmlpType + ".html"

t, err := template.New(filename).Funcs(template.FuncMap{
"SerializeLink": reporter.SerializeLink,
Expand Down

0 comments on commit 82420ae

Please sign in to comment.