Skip to content
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

Conversation

gusandrioli
Copy link
Contributor

@gusandrioli gusandrioli commented Oct 10, 2022

This PR resolves #370

Changes

  • Moved cheatsheet generate script to pkg/cheatsheet/generate.go.
  • Added pkg/cheatsheet/check.go to validate if cheatsheets are up to date.
  • Added GHA step to validate if cheatsheets are up to date on ci.yaml.

Comment on lines 414 to 441

// GetLazydockerRootDirectory finds lazydocker root directory.
//
// It's used for our cheatsheet script and integration tests. Not to be confused with finding the
// root directory of _any_ random repo.
func GetLazydockerRootDirectory() string {
path, err := os.Getwd()
if err != nil {
panic(err)
}

for {
_, err := os.Stat(filepath.Join(path, ".git"))
if err == nil {
return path
}

if !os.IsNotExist(err) {
panic(err)
}

path = filepath.Dir(path)

if path == "/" {
log.Fatal("must run in lazydocker folder or child folder")
}
}
}
Copy link
Contributor Author

@gusandrioli gusandrioli Oct 10, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I copied over from lazygit, but I was wondering if a shared package would fit this case (Maybe lazyutils?). There seems to be quite a bit of overlap between lazygit and lazydocker. Even these scripts for cheatsheets could be used in both projects. Let me know your thoughts 😄.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gusandrioli I actually made a repo for this exact purpose over the weekend: https://github.com/jesseduffield/lazycore. If you would like to raise a PR on that repo for shared cheatsheet functionality, I'll happily review :) Also happy to give pointers

Copy link
Contributor Author

@gusandrioli gusandrioli Oct 10, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah neat! I'll open a PR there then 😄.

pkg/cheatsheet/validate.go Show resolved Hide resolved
pkg/cheatsheet/generate.go Outdated Show resolved Hide resolved
.github/workflows/ci.yml Outdated Show resolved Hide resolved
@gusandrioli gusandrioli marked this pull request as ready for review October 10, 2022 20:29
@gusandrioli
Copy link
Contributor Author

@jesseduffield This one is ready for review as well!

@gusandrioli gusandrioli force-pushed the check-cheatsheet-is-up-to-date branch from af4add5 to c562563 Compare October 10, 2022 20:43
@gusandrioli
Copy link
Contributor Author

@jesseduffield Added a PR on lazycore: jesseduffield/lazycore#3. Also, investigating why the failure on windows-latest ci. I saw lazygit doesn't have this problem, so let me know if this is a known issue.

@jesseduffield
Copy link
Owner

@gusandrioli nice, I've merged that PR. There's a scripts/bump_lazycore.sh script you can run to bump it for you in this repo.

I'm not sure why windows-latest ci would be failing. I am aware of it being slow but not failing

@jesseduffield
Copy link
Owner

@gusandrioli actually I bet it's because windows uses different line ending characters than unix. I'm not sure how that's possible when the script is only using newlines though

@gusandrioli
Copy link
Contributor Author

@jesseduffield No luck yet here. Seems like on lazygit it only runs check-codebase on ubuntu machines (and Check Cheatsheet within there). We'd probably have the same issue there. I'll probably separate the jobs here to match that.

Copy link
Contributor Author

@gusandrioli gusandrioli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jesseduffield CI passing now :)

Comment on lines +90 to +96
- name: Check Cheatsheet
run: |
go run scripts/cheatsheet/main.go check
- name: Check Vendor Directory
# ensure our vendor directory matches up with our go modules
run: |
go mod vendor && git diff --exit-code || (echo "Unexpected change to vendor directory. Run 'go mod vendor' locally and commit the changes" && exit 1)
Copy link
Contributor Author

@gusandrioli gusandrioli Oct 10, 2022

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).

Comment on lines -103 to -105
# github.com/golang-collections/collections v0.0.0-20130729185459-604e922904d3
## explicit
github.com/golang-collections/collections/stack
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ran go mod vendor as now there's validation on CI.

@jesseduffield
Copy link
Owner

Amazing work @gusandrioli ! Merging :)

@jesseduffield jesseduffield merged commit 38959a0 into jesseduffield:master Oct 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Check cheatsheet is up to date in CI
2 participants