-
-
Notifications
You must be signed in to change notification settings - Fork 76
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
Added Pre-Commit hook support #541
Closed
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,23 @@ | ||||||
- id: selene | ||||||
name: selene (cargo) | ||||||
description: An opinionated Lua code linter | ||||||
entry: selene | ||||||
language: rust | ||||||
types: | ||||||
- lua | ||||||
|
||||||
- id: selene-system | ||||||
name: selene (system) | ||||||
description: An opinionated Lua code linter | ||||||
entry: selene | ||||||
language: system | ||||||
types: | ||||||
- lua | ||||||
|
||||||
- id: selene-docker | ||||||
name: selene (docker) | ||||||
description: An opinionated Lua code linter | ||||||
entry: selene | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
This should fix the Docker run. |
||||||
language: docker | ||||||
types: | ||||||
- lua |
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,25 @@ | ||
# Git Hook Support | ||
|
||
Selene has [githooks](https://git-scm.com/docs/githooks) support thanks to | ||
[pre-commit](https://pre-commit.com) which means you will need to add a | ||
configuration file - `.pre-commit-config.yaml` to your repository. Thereafter | ||
you'll need to install the hooks and `selene` will be run against all recently | ||
changed files before you commit the changes. | ||
|
||
This section of the document details the ways you could setup `pre-commit` for | ||
linting your Lua code before each commits. | ||
|
||
In the `.pre-commit-config.yaml` file add the following configurations and then | ||
run `pre-commit install --install-hooks` to setup the pre-commit hooks. | ||
|
||
```yaml | ||
repos: | ||
- repo: https://github.com/Kampfkarren/selene | ||
rev: '' # Add the latest version of Selene here | ||
hooks: | ||
- selene # this will use Cargo to compile the binary before usage | ||
- selene-system # this will use the installed binary on the system | ||
- selene-docker # this will build a Docker image before usage | ||
``` | ||
|
||
To ensure `pre-commit` is the latest tagged version of `selene`, run the `pre-commit autoupdate` command. |
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.
Trying to run this hook via
pre-commit try-repo https://github.com/Jarmos-san/selene selene
fails withI suspect Cargo expects something different?
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.
Hey thanks for reporting the issue! I did some research and stumbled across rust-lang/cargo#7599 which is why Cargo fails to correctly identify which
Cargo.toml
to use based on the correct workspace!I think it might be possible to circumvent this issue by specifying the exact path to the correct workspace using theSpecifyingargs
option of the.pre-commit-hooks.yaml
file (see related docs)--path selene
with theargs
key does not work as I expect it to. I'm kinda out of ideas now since I'm not very familiar withcargo
atm.Besides, I also noticed the other Docker based hook is breaking too! See the error logs I stumbled across:
Is it because perhaps theI tried building the Image based on therust:1.64-alpine3.14
Image does not exists?Dockerfile
and the build breaks so I'm sure its because therust:1.64-alpine3.14
wasn't found.It might be a better idea to open another PR with a fix for the Docker build no?
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.
I agree, the Docker build should be fixed in a separate PR.
Regarding the Cargo error, I'm also not familiar with Cargo. Maybe @Kampfkarren has an idea? pre-commit's installation procedure is documented here.
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.
Would you like to take the initiative to fix the
Dockerfile
since you already had the idea work on this PR earlier?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.
I would, if I'd be familiar with containers...
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.
Oh haha...cheers then! Don't worry I'll send another with a fix next weekend then. By then I hope Kamp will help us out figure out how to fix the
cargo
error.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.
It looks like we can make it use
rust-alpine
, right? I always want latest Rust anyway.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.
Yes, it works with
rust:alpine
; checked it recently.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.
Oh great glad
rust:alpine
works, so @f1rstlady do you want to try sharing a PR with a fixedDockerfile
? I can mark this PR a draft till you have shared a mergeable PR. What do you say?Or if you want I can look into the current
Dockerfile
and see if I can fix the broken build.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.
Here it is: #549
I haven't tested the corresponding pre-commit hook yet since I used podman instead of docker to build the repaired image.