Skip to content

Commit

Permalink
document code
Browse files Browse the repository at this point in the history
  • Loading branch information
umputun committed Dec 31, 2023
1 parent bbed976 commit 6ab1291
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 8 deletions.
19 changes: 16 additions & 3 deletions publisher/app/cmd/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cmd
import (
"fmt"
"net/http"
"strings"

log "github.com/go-pkgz/lgr"
"github.com/pkg/errors"
Expand All @@ -20,8 +21,15 @@ type Deploy struct {
Dry bool
}

// Do run deploy sequence for the given episodeNum
// may panic on executor error
var supers = []string{"umputun", "bobuk", "ksenks", "grayodesa"}

// Do performs a series of actions to deploy a new episode.
// It takes an episode number as input and returns an error if any of the actions fail.
// It performs the following actions:
// 1. Commit the new episode to git.
// 2. Update the remote hugo site via ssh.
// 3. Create the chat log.
// 4. Archive the news.
func (d *Deploy) Do(episodeNum int) error {
log.Printf("[INFO] commit new episode to git")
d.Run(fmt.Sprintf(`git pull && git commit -am "episode %d" && git push`, episodeNum))
Expand All @@ -30,7 +38,12 @@ func (d *Deploy) Do(episodeNum int) error {
d.Run("ssh [email protected]", `cd /srv/site.hugo && git pull && docker-compose run --rm hugo`)

log.Printf("[INFO] create chat log")
d.Run("ssh [email protected]", fmt.Sprintf(`docker exec -i super-bot /srv/telegram-rt-bot --super=umputun --super=bobuk --super=ksenks --super=grayodesa --dbg --export-num=%d --export-path=/srv/html`, episodeNum))
slParams := []string{}
for _, s := range supers {
slParams = append(slParams, fmt.Sprintf("--super=%s", s))
}
d.Run("ssh [email protected]", fmt.Sprintf(`docker exec -i super-bot /srv/telegram-rt-bot %s --dbg --export-num=%d --export-path=/srv/html`,
strings.Join(slParams, " "), episodeNum))

log.Printf("[INFO] archive news")
err := d.archiveNews()
Expand Down
17 changes: 12 additions & 5 deletions publisher/app/cmd/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,21 @@ import (
//go:embed artifacts/*
var artifactsFS embed.FS

// Upload handles podcast upload to all destinations. It uses spot to deploy and set mp3 tags before deploy
// Upload handles podcast upload to all destinations. It sets mp3 tags first and then deploys to master and nodes via spot tool.
type Upload struct {
Executor
LocationMp3 string
LocationPosts string
Dry bool
}

// Do runs uploads for given episode
// Do uploads an episode to all destinations. It takes an episode number as input and returns an error if any of the actions fail.
// It performs the following actions:
// 1. Set mp3 tags.
// 2. Deploy to master.
// 3. Deploy to nodes.
//
// deploy performed by spot tool, see spot.yml
func (u *Upload) Do(episodeNum int) error {
log.Printf("[INFO] upload episode %d, mp3 location:%q, posts location:%q", episodeNum, u.LocationMp3, u.LocationPosts)
mp3file := fmt.Sprintf("%s/rt_podcast%d/rt_podcast%d.mp3", u.LocationMp3, episodeNum, episodeNum)
Expand Down Expand Up @@ -58,7 +64,8 @@ type chapter struct {
Begin time.Duration
}

// setMp3Tags sets mp3 tags for given episode. It uses artifactsFS to read cover.jpg
// setMp3Tags sets mp3 tags for a given episode. It uses artifactsFS to read cover.jpg
// and uses the chapter information to set the chapter tags.
func (u *Upload) setMp3Tags(episodeNum int, chapters []chapter) error {
mp3file := fmt.Sprintf("%s/rt_podcast%d/rt_podcast%d.mp3", u.LocationMp3, episodeNum, episodeNum)
log.Printf("[INFO] set mp3 tags for %s", mp3file)
Expand Down Expand Up @@ -121,7 +128,7 @@ func (u *Upload) setMp3Tags(episodeNum int, chapters []chapter) error {
return tag.Save()
}

// parseChapters parses the input content and returns a slice of chapters
// parseChapters parses md post content and returns a list of chapters
func (u *Upload) parseChapters(content string) ([]chapter, error) {
parseDuration := func(timestamp string) (time.Duration, error) {
parts := strings.Split(timestamp, ":")
Expand All @@ -146,8 +153,8 @@ func (u *Upload) parseChapters(content string) ([]chapter, error) {
}

chapters := []chapter{}
// - [Chapter One](http://example.com/one) - *00:01:00*.
chapterRegex := regexp.MustCompile(`-\s+\[(.*?)\]\((.*?)\)\s+-\s+\*(.*?)\*\.`)

matches := chapterRegex.FindAllStringSubmatch(content, -1)
for _, match := range matches {
if len(match) == 4 {
Expand Down

0 comments on commit 6ab1291

Please sign in to comment.