diff --git a/.github/workflows/record_and_publish_demos.yml b/.github/workflows/record_and_publish_demos.yml new file mode 100644 index 0000000..f15c317 --- /dev/null +++ b/.github/workflows/record_and_publish_demos.yml @@ -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 diff --git a/CHANGELOG.md b/CHANGELOG.md old mode 100644 new mode 100755 index 04eb8f9..b956c39 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/cmd/insert.go b/cmd/insert.go index 0f8c361..e781a3c 100644 --- a/cmd/insert.go +++ b/cmd/insert.go @@ -3,8 +3,8 @@ package cmd import ( // "fmt" - "fmt" "os" + "strings" clog "github.com/niclasvaneyk/keepac/internal/changelog" "github.com/niclasvaneyk/keepac/internal/editor" @@ -54,19 +54,19 @@ var insertCmd = &cobra.Command{ } } - response, err := editor.Prompt("- ", "") - if err != nil { - return err + var response string + if len(args) > 0 { + response = strings.Join(args, " ") + } else { + response, err = editor.Prompt("- ", "") + 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) }, } @@ -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 +} diff --git a/internal/changelog/finder.go b/internal/changelog/finder.go index 9336ba5..1220114 100644 --- a/internal/changelog/finder.go +++ b/internal/changelog/finder.go @@ -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) diff --git a/internal/changelog/inserter.go b/internal/changelog/inserter.go index 640af7e..97a2906 100644 --- a/internal/changelog/inserter.go +++ b/internal/changelog/inserter.go @@ -1,7 +1,6 @@ package changelog import ( - "fmt" "strings" ) @@ -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:] } @@ -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 @@ -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. diff --git a/internal/changelog/inserter_test.go b/internal/changelog/inserter_test.go index 7335ec7..17d7893 100644 --- a/internal/changelog/inserter_test.go +++ b/internal/changelog/inserter_test.go @@ -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 diff --git a/internal/changelog/parser.go b/internal/changelog/parser.go index c6107c4..3e402b1 100644 --- a/internal/changelog/parser.go +++ b/internal/changelog/parser.go @@ -1,7 +1,6 @@ package changelog import ( - "fmt" "math" "github.com/yuin/goldmark" @@ -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)) diff --git a/internal/tui/choice.go b/internal/tui/choice.go index cd3f764..d0c9ad4 100644 --- a/internal/tui/choice.go +++ b/internal/tui/choice.go @@ -32,8 +32,6 @@ 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 { @@ -41,7 +39,7 @@ func (d itemDelegate) Render(w io.Writer, m list.Model, index int, listItem list } } - fmt.Fprint(w, fn(str)) + fmt.Fprint(w, fn(string(i))) } type model struct { @@ -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 diff --git a/scripts/record-tapes b/scripts/record-tapes new file mode 100755 index 0000000..08df219 --- /dev/null +++ b/scripts/record-tapes @@ -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()) diff --git a/tapes/.gitignore b/tapes/.gitignore new file mode 100644 index 0000000..7c06303 --- /dev/null +++ b/tapes/.gitignore @@ -0,0 +1,2 @@ +*.gif +*.md diff --git a/vhs/demo.tape b/tapes/dark/demo.tape similarity index 73% rename from vhs/demo.tape rename to tapes/dark/demo.tape index 2e23f70..b5bbcdd 100644 --- a/vhs/demo.tape +++ b/tapes/dark/demo.tape @@ -1,4 +1,4 @@ -Output demo.gif +Require changelog Type "changelog find" Enter @@ -11,3 +11,6 @@ Enter Sleep 1500ms Type "changelog add" + +Enter +Sleep 1500ms diff --git a/tapes/dark/insert.tape b/tapes/dark/insert.tape new file mode 100644 index 0000000..df16fe1 --- /dev/null +++ b/tapes/dark/insert.tape @@ -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 diff --git a/tapes/light/.gitignore b/tapes/light/.gitignore new file mode 100644 index 0000000..d6b7ef3 --- /dev/null +++ b/tapes/light/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore diff --git a/tapes/recordings/.gitignore b/tapes/recordings/.gitignore new file mode 100644 index 0000000..d6b7ef3 --- /dev/null +++ b/tapes/recordings/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore