Skip to content

Commit

Permalink
Record tapes using VHS - initial version
Browse files Browse the repository at this point in the history
  • Loading branch information
NiclasvanEyk committed Jun 11, 2023
1 parent 95e8bf2 commit 36359ac
Show file tree
Hide file tree
Showing 14 changed files with 231 additions and 36 deletions.
43 changes: 43 additions & 0 deletions .github/workflows/record_and_publish_demos.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Record Demo Workflows And Publish Them To GitHub Pages

on:
push:
branches: [$default-branch]

# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
permissions:
contents: read
pages: write
id-token: write

# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
concurrency:
group: "pages"
cancel-in-progress: false

jobs:
deploy:
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup Pages
uses: actions/configure-pages@v3
- uses: actions/setup-go@v4
- name: Install VHS
run: go version && go install github.com/charmbracelet/vhs@latest
- name: Build keepac
run: go build -o changelog
- name: Record tapes
run: ./scripts/record-tapes
- name: Upload artifact
uses: actions/upload-pages-artifact@v1
with:
path: "tapes/recordings"
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v2
9 changes: 7 additions & 2 deletions CHANGELOG.md
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# Changelog

## [Unreleased]

### Added

- Something even more useful

- The initial version
- Something Why does this not get inserted at the end?
- Something This is unexpected
- Something really good
- foo bar foo
32 changes: 20 additions & 12 deletions cmd/insert.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package cmd
import (
// "fmt"

"fmt"
"os"
"strings"

clog "github.com/niclasvaneyk/keepac/internal/changelog"
"github.com/niclasvaneyk/keepac/internal/editor"
Expand Down Expand Up @@ -54,19 +54,19 @@ var insertCmd = &cobra.Command{
}
}

response, err := editor.Prompt("- ", "<!-- Add your changes above. Don't worry, this line will be excluded from the final output. -->")
if err != nil {
return err
var response string
if len(args) > 0 {
response = strings.Join(args, " ")
} else {
response, err = editor.Prompt("- ", "<!-- Add your changes above. Don't worry, this line will be excluded from the final output. -->")
if err != nil {
return err
}
}

// TODO: Support adding a section via a flag (--added, --changed, deleted)
// TODO: Prompt for the section if none was specified
// TODO: Create the section, if it was not present previously
//
// TODO: Add the response to the specified section
response = normalized(response)

newSource := changelog.AddItem(changeType, response)

return os.WriteFile(filename, []byte(newSource), 0774)
},
}
Expand All @@ -93,7 +93,15 @@ func chooseChangeType() clog.ChangeType {
"Security",
})

fmt.Printf("choice was: %s\n", choice)

return clog.ParseChangeType(choice)
}

func normalized(response string) string {
normalized := strings.TrimSpace(response)

if strings.HasPrefix(normalized, "- ") {
return normalized
}

return "- " + normalized
}
7 changes: 0 additions & 7 deletions internal/changelog/finder.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,6 @@ import (
"path/filepath"
)

func handleErr(err error) {
if err != nil {
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
os.Exit(1)
}
}

func FindChangelogIn(directory string) (string, bool) {
changelogPath := filepath.Join(directory, "CHANGELOG.md")
_, err := os.Stat(changelogPath)
Expand Down
7 changes: 0 additions & 7 deletions internal/changelog/inserter.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package changelog

import (
"fmt"
"strings"
)

Expand Down Expand Up @@ -98,7 +97,6 @@ func (changelog *Changelog) AddItem(changeType ChangeType, contents string) stri
newContent := strings.Join(parts, "\n\n")

insertionPoint, padding := determineInsertionPoint(changeType, changelog)
fmt.Printf("Inserting new section at %v\n", insertionPoint)

return changelog.source[:insertionPoint] + padding.ApplyTo(newContent) + changelog.source[insertionPoint:]
}
Expand All @@ -116,7 +114,6 @@ func (p *Padding) ApplyTo(subject string) string {
func determineInsertionPoint(changeType ChangeType, changelog *Changelog) (int, Padding) {
nextRelease := changelog.Releases.Next
if nextRelease == nil {
fmt.Println("nextRelease is nil")
if len(changelog.Releases.Past) == 0 {
// We have an empty changelog with just the title:
// # Changelog <-- Add here
Expand Down Expand Up @@ -146,11 +143,7 @@ func determineInsertionPoint(changeType ChangeType, changelog *Changelog) (int,
// ## [1.1.0] - 2020-01-01
existingSection := nextRelease.FindSection(changeType)
if existingSection != nil {
fmt.Println("Found an existing section")
fmt.Printf("%v\n", existingSection.Bounds)
return existingSection.Bounds.Stop, Padding{Before: 1, After: 0}
} else {
fmt.Println("existing section is nil")
}

// Now we know, that the section does not exist yet.
Expand Down
48 changes: 48 additions & 0 deletions internal/changelog/inserter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,54 @@ func TestAddToExistingSectionInNextRelease(t *testing.T) {
scenario(t, source, changeType, addition, expected)
}

func TestAppendToExistingSectionInNextReleaseWithoutPastReleases(t *testing.T) {
source := `# Changelog
## [Unreleased]
### Added
- First
- Second
- Third`
changeType := Added
addition := "- Fourth"
expected := `# Changelog
## [Unreleased]
### Added
- First
- Second
- Third
- Fourth`

scenario(t, source, changeType, addition, expected)
}

func TestAddToNewSectionInNextReleaseWithoutPastReleases(t *testing.T) {
source := `# Changelog
## [Unreleased]
### Added
- Something`
changeType := Changed
addition := "- Another New Thing"
expected := `# Changelog
## [Unreleased]
### Added
- Something
- Another New Thing`

scenario(t, source, changeType, addition, expected)
}

func TestAddNewAddedSectionAboveRemovedOne(t *testing.T) {
source := `# Changelog
Expand Down
3 changes: 0 additions & 3 deletions internal/changelog/parser.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package changelog

import (
"fmt"
"math"

"github.com/yuin/goldmark"
Expand Down Expand Up @@ -175,8 +174,6 @@ func Parse(source []byte) Changelog {

if node.Kind() == ast.KindHeading {
heading := node.(*ast.Heading)
text := heading.Text(source)
fmt.Printf("%s", text)

if title == "" && heading.Level == 1 {
title = string(heading.Text(source))
Expand Down
5 changes: 1 addition & 4 deletions internal/tui/choice.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,14 @@ func (d itemDelegate) Render(w io.Writer, m list.Model, index int, listItem list
return
}

str := fmt.Sprintf("%s", i)

fn := itemStyle.Render
if index == m.Index() {
fn = func(s ...string) string {
return selectedItemStyle.Render("> " + strings.Join(s, " "))
}
}

fmt.Fprint(w, fn(str))
fmt.Fprint(w, fn(string(i)))
}

type model struct {
Expand All @@ -67,7 +65,6 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
case "enter":
i, ok := m.list.SelectedItem().(item)
if ok {
fmt.Printf("You chose %s!\n", i)
m.onSelect(i)
}
return m, tea.Quit
Expand Down
66 changes: 66 additions & 0 deletions scripts/record-tapes
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#!/usr/bin/env python3

from os import path
import os
import pathlib
import sys
import subprocess

project_root_folder = pathlib.Path(path.dirname(__file__), '..').resolve()
tapes_folder = project_root_folder / 'tapes'
dark_tapes_folder = tapes_folder / 'dark'
light_tapes_folder = tapes_folder / 'light'
gifs_folder = tapes_folder / 'recordings'


def main() -> int:
create_light_tapes()
record_tapes()

return 0


def create_light_tapes() -> None:
for dark_tape in dark_tapes_folder.glob('*.tape'):
with open(light_tapes_folder.joinpath(dark_tape.name), 'w') as light_tape:
print(f"Creating light version of {light_tape.name}...")
light_tape.write("# This file is auto-generated and will be overridden!\n\n")
light_tape.write("Set Theme Github\n")
light_tape.write(dark_tape.read_text())


def record_tapes() -> None:
recorded_tapes = 0



for tapes in [light_tapes_folder, dark_tapes_folder]:
colorscheme = tapes.name

local_env = os.environ
# Uses locally built version of keepac
local_env["PATH"] = str(project_root_folder) + ":" + local_env["PATH"]
# Auto-colorscheme detection does not work within vhs, so we manually
# set the style here
local_env["GLAMOUR_STYLE"] = colorscheme

print(f"Recording {colorscheme} tapes...\n")
for tape in tapes.glob('*.tape'):
subprocess.run(['vhs', tape], env=local_env, cwd=tapes)

recording = tapes / 'out.gif'
tape_name = path.splitext(tape.name)[0]
destination = gifs_folder / f'{tape_name}.{colorscheme}.gif'

print(f"Moving {recording} to {destination}...")
recording.rename(destination)
recorded_tapes += 1

print("")

print("Done!")
print(f"Recorded {recorded_tapes} tapes.")


if __name__ == '__main__':
sys.exit(main())
2 changes: 2 additions & 0 deletions tapes/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*.gif
*.md
5 changes: 4 additions & 1 deletion vhs/demo.tape → tapes/dark/demo.tape
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Output demo.gif
Require changelog

Type "changelog find"
Enter
Expand All @@ -11,3 +11,6 @@ Enter
Sleep 1500ms

Type "changelog add"

Enter
Sleep 1500ms
36 changes: 36 additions & 0 deletions tapes/dark/insert.tape
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
Require changelog

Hide
# Create new file
Type "changelog init"
Sleep 500ms
Enter
Sleep 1500ms
Show

# Trigger section selection
Type "changelog insert"
Sleep 500ms
Enter
Sleep 1500ms

# Select "Fixed"
Down
Sleep 500ms
Down
Sleep 500ms
Down
Sleep 500ms
Down
Sleep 1500ms
Enter

Type "That one annoying bug"
Enter

Sleep 1500ms

# Cleanup
Hide
Type rm CHANGELOG.md
Enter
2 changes: 2 additions & 0 deletions tapes/light/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*
!.gitignore
2 changes: 2 additions & 0 deletions tapes/recordings/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*
!.gitignore

0 comments on commit 36359ac

Please sign in to comment.