-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Check if cheatsheets are up to date on CI #374
Merged
jesseduffield
merged 6 commits into
jesseduffield:master
from
gusandrioli:check-cheatsheet-is-up-to-date
Oct 11, 2022
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
119835c
Check if cheatsheets are up to date on CI
gusandrioli c562563
Clean up
gusandrioli 337e57a
Bump lazycore
gusandrioli 1cb9506
Update CI jobs: Add check-codebase
gusandrioli dd11b0e
Update CI jobs: Remove Check Cheatsheet from ci job
gusandrioli 574e0b6
Remove GetLazydockerRootDirectory function
gusandrioli File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
package cheatsheet | ||
|
||
import ( | ||
"fmt" | ||
"io/fs" | ||
"log" | ||
"os" | ||
"path/filepath" | ||
"regexp" | ||
|
||
"github.com/jesseduffield/lazycore/pkg/utils" | ||
"github.com/pmezard/go-difflib/difflib" | ||
) | ||
|
||
func Check() { | ||
dir := GetKeybindingsDir() | ||
tmpDir := filepath.Join(os.TempDir(), "lazydocker_cheatsheet") | ||
|
||
err := os.RemoveAll(tmpDir) | ||
if err != nil { | ||
log.Fatalf("Error occurred while checking if cheatsheets are up to date: %v", err) | ||
} | ||
defer os.RemoveAll(tmpDir) | ||
|
||
if err = os.Mkdir(tmpDir, 0o700); err != nil { | ||
log.Fatalf("Error occurred while checking if cheatsheets are up to date: %v", err) | ||
} | ||
|
||
generateAtDir(tmpDir) | ||
|
||
actualContent := obtainContent(dir) | ||
expectedContent := obtainContent(tmpDir) | ||
|
||
if expectedContent == "" { | ||
log.Fatal("empty expected content") | ||
} | ||
|
||
if actualContent != expectedContent { | ||
if err := difflib.WriteUnifiedDiff(os.Stdout, difflib.UnifiedDiff{ | ||
A: difflib.SplitLines(expectedContent), | ||
B: difflib.SplitLines(actualContent), | ||
FromFile: "Expected", | ||
FromDate: "", | ||
ToFile: "Actual", | ||
ToDate: "", | ||
Context: 1, | ||
}); err != nil { | ||
log.Fatalf("Error occurred while checking if cheatsheets are up to date: %v", err) | ||
} | ||
fmt.Printf( | ||
"\nCheatsheets are out of date. Please run `%s` at the project root and commit the changes. "+ | ||
"If you run the script and no keybindings files are updated as a result, try rebasing onto master"+ | ||
"and trying again.\n", | ||
generateCheatsheetCmd, | ||
gusandrioli marked this conversation as resolved.
Show resolved
Hide resolved
|
||
) | ||
os.Exit(1) | ||
} | ||
|
||
fmt.Println("\nCheatsheets are up to date") | ||
} | ||
|
||
func GetKeybindingsDir() string { | ||
return utils.GetLazyRootDirectory() + "/docs/keybindings" | ||
} | ||
|
||
func obtainContent(dir string) string { | ||
re := regexp.MustCompile(`Keybindings_\w+\.md$`) | ||
|
||
content := "" | ||
err := filepath.WalkDir(dir, func(path string, d fs.DirEntry, err error) error { | ||
if re.MatchString(path) { | ||
bytes, err := os.ReadFile(path) | ||
if err != nil { | ||
log.Fatalf("Error occurred while checking if cheatsheets are up to date: %v", err) | ||
} | ||
content += fmt.Sprintf("\n%s\n\n", filepath.Base(path)) | ||
content += string(bytes) | ||
} | ||
|
||
return nil | ||
}) | ||
if err != nil { | ||
log.Fatalf("Error occurred while checking if cheatsheets are up to date: %v", err) | ||
} | ||
|
||
return content | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"os" | ||
|
||
"github.com/jesseduffield/lazydocker/pkg/cheatsheet" | ||
) | ||
|
||
func main() { | ||
if len(os.Args) < 2 { | ||
log.Fatal("Please provide a command: one of 'generate', 'check'") | ||
} | ||
|
||
command := os.Args[1] | ||
|
||
switch command { | ||
case "generate": | ||
cheatsheet.Generate() | ||
fmt.Printf("\nGenerated cheatsheets in %s\n", cheatsheet.GetKeybindingsDir()) | ||
case "check": | ||
cheatsheet.Check() | ||
default: | ||
log.Fatal("\nUnknown command. Expected one of 'generate', 'check'") | ||
} | ||
} |
20 changes: 0 additions & 20 deletions
20
vendor/github.com/golang-collections/collections/LICENSE
This file was deleted.
Oops, something went wrong.
44 changes: 0 additions & 44 deletions
44
vendor/github.com/golang-collections/collections/stack/stack.go
This file was deleted.
Oops, something went wrong.
35 changes: 35 additions & 0 deletions
35
vendor/github.com/jesseduffield/lazycore/pkg/utils/utils.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now we check for cheatsheet diffs here and ensure our vendor dir matches the modules (same job as lazygit).