Skip to content

Commit

Permalink
Ci (#79)
Browse files Browse the repository at this point in the history
CI all the things. Thanks again to packagecloud
  • Loading branch information
svenwiltink authored Jun 29, 2022
1 parent 934e076 commit 4c43ad4
Show file tree
Hide file tree
Showing 18 changed files with 127 additions and 145 deletions.
59 changes: 59 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
---
on: [push, pull_request]
name: Build
jobs:
build:
name: build
strategy:
matrix:
go-version: [1.18.3]
os: [ubuntu-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/setup-go@v3
with:
go-version: ${{ matrix.go-version }}
- uses: actions/checkout@v3
with:
fetch-depth: 0

- run: go test ./...
- run: go build ./cmd/go-musicbot

- name: setup fpm
run: sudo gem install fpm

- name: git status
run: git status

- name: make package
run: ./deb-build.sh

- name: Upload Artifact
uses: actions/upload-artifact@v2
with:
name: package
path: ./out/packages/*
retention-days: 5

- name: Setup package cloud
if: github.event_name == 'release' && github.event.action == 'created'
run: sudo gem install package_cloud
- name: Push to package_cloud
if: github.event_name == 'release' && github.event.action == 'created'
env:
PACKAGECLOUD_TOKEN: ${{ secrets.PACKAGECLOUD_TOKEN }}
run: package_cloud push svenwiltink/go-musicbot/ubuntu/bionic ./out/packages/*
golangci:
name: lint
strategy:
matrix:
go-version: [1.18.x]
runs-on: ubuntu-latest
steps:
- uses: actions/setup-go@v3
with:
go-version: ${{ matrix.go-version }}
- uses: actions/checkout@v3
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
.idea
.vscode
vendor
config.json
whitelist.txt
out
pkg_root
go-musicbot
44 changes: 0 additions & 44 deletions .travis.yml

This file was deleted.

50 changes: 0 additions & 50 deletions Makefile

This file was deleted.

4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[![.deb provided by packagecloud](https://img.shields.io/badge/deb-packagecloud.io-844fec.svg)](https://packagecloud.io/svenwiltink/go-musicbot)[![Build Status](https://travis-ci.org/svenwiltink/go-MusicBot.svg?branch=master)](https://travis-ci.org/svenwiltink/go-MusicBot)
[![.deb provided by packagecloud](https://img.shields.io/badge/deb-packagecloud.io-844fec.svg)](https://packagecloud.io/svenwiltink/go-musicbot)![build status](https://github.com/svenwiltink/go-musicbot/actions/workflows/build.yml/badge.svg)

A simple musicbot to run on IRC or Mattermost. Debian package hosted on [packagecloud](https://packagecloud.io/svenwiltink/go-musicbot)
A simple musicbot to run on IRC, mattermost or slack. Debian package hosted on [packagecloud](https://packagecloud.io/svenwiltink/go-musicbot)
4 changes: 2 additions & 2 deletions deb-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ mkdir -p out/packages
mkdir -p ${PKG_ROOT}/usr/local/bin
mkdir -p ${PKG_ROOT}/usr/local/etc/go-Musicbot

cp out/binaries/MusicBot-linux-amd64 \
cp go-musicbot \
${PKG_ROOT}/usr/local/bin/go-Musicbot

cp dist/config.json.example \
Expand All @@ -32,7 +32,7 @@ fpm \
--license MIT \
-m "Sven Wiltink" \
--url "https://github.com/svenwiltink/go-musicbot" \
--description "A musicbot for rocketchat or irc" \
--description "A musicbot for IRC, mattermost and slack" \
--config-files /usr/local/etc/go-Musicbot \
-p "out/packages/${VERSION}.deb"

2 changes: 1 addition & 1 deletion dist/config.json.example
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"teamname": "svenwiltink",
"channel": "muziek",
"privateAccessToken": "<token>",
"ssl": true
"ssl": true,
"connectionTimeout": 30
},
"youtube": {
Expand Down
12 changes: 6 additions & 6 deletions pkg/bot/bot.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@ import (
var (
errCommandNotFound = errors.New("command not found")
errVariableNotFound = errors.New("command variable not found")

Version = "placeholder string"
GoVersion = "placeholder string"
BuildDate = "placeholder string"
)

type MusicBot struct {
Expand Down Expand Up @@ -147,11 +143,15 @@ func (bot *MusicBot) getCommand(name string) (Command, error) {
}

func (bot *MusicBot) ReplyToMessage(message Message, reply string) {
bot.messageProvider.SendReplyToMessage(message, reply)
if err := bot.messageProvider.SendReplyToMessage(message, reply); err != nil {
log.Printf("Error replying to message: %s", err)
}
}

func (bot *MusicBot) BroadcastMessage(message string) {
bot.messageProvider.BroadcastMessage(message)
if err := bot.messageProvider.BroadcastMessage(message); err != nil {
log.Printf("Error broadcasting message: %s", err)
}
}

func (bot *MusicBot) Stop() {
Expand Down
24 changes: 21 additions & 3 deletions pkg/bot/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ package bot

import (
"fmt"
"github.com/svenwiltink/go-musicbot/pkg/music"
"runtime/debug"
"strconv"
"strings"
"time"

"github.com/svenwiltink/go-musicbot/pkg/music"
)

type Command struct {
Expand Down Expand Up @@ -402,7 +404,7 @@ var volCommand = Command{
}

if volume >= 0 && volume <= 100 {
bot.musicPlayer.SetVolume(volume)
_ = bot.musicPlayer.SetVolume(volume)
} else {
bot.ReplyToMessage(message, fmt.Sprintf("%s is not a valid volume", volumeString))
return
Expand All @@ -421,9 +423,25 @@ var volCommand = Command{
var aboutCommand = Command{
Name: "about",
Function: func(bot *MusicBot, message Message) {
var GoVersion, Version, BuildDate string

info, ok := debug.ReadBuildInfo()
if ok {
GoVersion = info.GoVersion

for _, setting := range info.Settings {
switch setting.Key {
case "vcs.revision":
Version = setting.Value
case "vcs.time":
BuildDate = setting.Value
}
}
}

bot.ReplyToMessage(message, "go-MusicBot by Sven Wiltink: https://github.com/svenwiltink/go-MusicBot")
bot.ReplyToMessage(message, fmt.Sprintf("Version: %s", Version))
bot.ReplyToMessage(message, fmt.Sprintf("Go: %s", GoVersion))
bot.ReplyToMessage(message, fmt.Sprintf("Version: %s", Version))
bot.ReplyToMessage(message, fmt.Sprintf("Build date: %s", BuildDate))
},
}
3 changes: 2 additions & 1 deletion pkg/bot/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ package bot
import (
"encoding/json"
"fmt"
"github.com/pkg/errors"
"os"
"time"

"github.com/pkg/errors"
)

const (
Expand Down
19 changes: 10 additions & 9 deletions pkg/bot/messageprovider/mattermost/mattermost.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ package mattermost

import (
"fmt"
"github.com/gorilla/websocket"
mattermost "github.com/mattermost/mattermost-server/v5/model"
"github.com/svenwiltink/go-musicbot/pkg/bot"
"log"
"strings"
"time"

"github.com/gorilla/websocket"
mattermost "github.com/mattermost/mattermost-server/v5/model"
"github.com/svenwiltink/go-musicbot/pkg/bot"
)

type MessageProvider struct {
Expand Down Expand Up @@ -114,8 +115,8 @@ func (provider *MessageProvider) startReadLoop() {
timeout := provider.Config.Mattermost.ConnectionTimeout

for {
provider.websocketClient.Conn.SetWriteDeadline(time.Now().Add(timeout * time.Second))
provider.websocketClient.Conn.SetReadDeadline(time.Now().Add(timeout * time.Second))
_ = provider.websocketClient.Conn.SetWriteDeadline(time.Now().Add(timeout * time.Second))
_ = provider.websocketClient.Conn.SetReadDeadline(time.Now().Add(timeout * time.Second))

for event := range provider.websocketClient.EventChannel {
if event.Event == mattermost.WEBSOCKET_EVENT_POSTED {
Expand Down Expand Up @@ -193,13 +194,13 @@ func (provider *MessageProvider) pingLoop() {

timeout := provider.Config.Mattermost.ConnectionTimeout
log.Printf("Starting ping loop with timeout of %d seconds", timeout)
provider.websocketClient.Conn.SetWriteDeadline(time.Now().Add(timeout * time.Second))
provider.websocketClient.Conn.SetReadDeadline(time.Now().Add(timeout * time.Second))
_ = provider.websocketClient.Conn.SetWriteDeadline(time.Now().Add(timeout * time.Second))
_ = provider.websocketClient.Conn.SetReadDeadline(time.Now().Add(timeout * time.Second))

// push back the timeout by 30 seconds every time we get a pong
provider.websocketClient.Conn.SetPongHandler(func(appData string) error {
provider.websocketClient.Conn.SetWriteDeadline(time.Now().Add(timeout * time.Second))
provider.websocketClient.Conn.SetReadDeadline(time.Now().Add(timeout * time.Second))
_ = provider.websocketClient.Conn.SetWriteDeadline(time.Now().Add(timeout * time.Second))
_ = provider.websocketClient.Conn.SetReadDeadline(time.Now().Add(timeout * time.Second))
return nil
})

Expand Down
6 changes: 3 additions & 3 deletions pkg/bot/messageprovider/slack/slack.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ package slack

import (
"fmt"
"log"
"os"

"github.com/slack-go/slack"
"github.com/slack-go/slack/slackevents"
"github.com/slack-go/slack/socketmode"
"github.com/svenwiltink/go-musicbot/pkg/bot"
"log"
"os"
)

type MessageProvider struct {
Expand All @@ -24,7 +25,6 @@ func (provider *MessageProvider) Start() error {
provider.rtm = socketmode.New(provider.api)
go func() {
err := provider.rtm.Run()
provider.rtm.Run()
if err != nil {
panic(err)
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/bot/messageprovider/terminal/terminal.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ func (messageProvider *MessageProvider) GetMessageChannel() chan bot.Message {
}

func (messageProvider *MessageProvider) SendReplyToMessage(message bot.Message, reply string) error {
log.Printf(reply)
log.Printf("%s", reply)
return nil
}

func (messageProvider *MessageProvider) BroadcastMessage(message string) error {
log.Printf(message)
log.Printf("%s", message)
return nil
}

Expand Down
3 changes: 2 additions & 1 deletion pkg/music/dataprovider/nts/nts.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package nts

import (
"fmt"

"github.com/svenwiltink/go-musicbot/pkg/music"
)

Expand Down Expand Up @@ -42,7 +43,7 @@ func (DataProvider) Search(name string) ([]music.Song, error) {
fmt.Println("trying to search NTS ", name)
songs := make([]music.Song, 0, len(streams))

for stream, _ := range streams {
for stream := range streams {
songs = append(songs, music.Song{
Name: stream,
Artist: "nts",
Expand Down
Loading

0 comments on commit 4c43ad4

Please sign in to comment.