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

pre-push git hooks errors + should be limited to formatting only #1038

Closed
rrybarczyk opened this issue Jul 5, 2024 · 4 comments · Fixed by #1039
Closed

pre-push git hooks errors + should be limited to formatting only #1038

rrybarczyk opened this issue Jul 5, 2024 · 4 comments · Fixed by #1039
Assignees
Labels
ci/cd CI/CD
Milestone

Comments

@rrybarczyk
Copy link
Collaborator

Background

act is a tool that works with Docker to run GitHub Actions workflows locally, designed to be run before pushing changes. The .githooks/pre-push uses act to run some GitHub workflows with % ./.githooks/pre-push origin https://github.com/stratum-mining/stratum.git.

The currently defined workflows in this pre-push script are:

  • message_generator_check (this is not an existing workflow, probably trying to reference message-generator-test)
  • sv2_header_check
  • fmt
  • clippy-check
  • ci

During the 2024.07.02 dev meet, the team decided that the pre-push should only containing more commonly needed workflows, like for formatting. Additionally, because of long run times when using act, the usage of act should be replaced with calling the bash scripts in the scripts/ directory in the repo root. This will keep the pre-push runtime shorter, and then any more specific workflows needed can be run manually by executing the bash scripts in the scripts/ directory on the dev branch.

Problem

  • The pre-push script should only contain workflows that are more commonly run, like for linting.
  • The non-existent message_generator_check is causing the pre-push to fail.
  • The run-times associated with act are long.

Solution

In .githooks/pre-push, replace the use of act with calls to the following bash scripts in the scripts/ directory on the dev branch:

  • clippy-on-all-workspaces.sh: Runs cargo clippy, cargo test, and cargo +nightly fmt.
  • sv2-header-check.sh: Ensures that the sv2.h file generated by build_header.sh is in sync with the commited protocols/v2/sv2-ffi/sv2.h.
@rrybarczyk rrybarczyk added the ci/cd CI/CD label Jul 5, 2024
@rrybarczyk rrybarczyk self-assigned this Jul 5, 2024
@rrybarczyk
Copy link
Collaborator Author

rrybarczyk commented Jul 5, 2024

Here are the run times for the scripts:

  • clippy-on-all-workspaces.sh containing cargo clippy, cargo test, and cargo +nightly fmt:./scripts/clippy-on-all-workspaces.sh 58.09s user 1.76s system 145% cpu 41.107 total
  • clippy-on-all-workspaces.sh containing cargo clippy and cargo +nightly fmt (cargo test removed): ./scripts/clippy-on-all-workspaces.sh 2.90s user 0.52s system 74% cpu 4.582 total
  • ./scripts/sv2-header-check.sh 0.92s user 0.24s system 88% cpu 1.307 total

Total run time of the ./.githooks/pre-push:

  • With cargo test in clippy-on-all-workspaces.sh: ./.githooks/pre-push 58.62s user 1.97s system 144% cpu 42.058 total
  • Without cargo test in clippy-on-all-workspaces.sh: ./.githooks/pre-push 3.91s user 0.82s system 89% cpu 5.292 total

@plebhash, do you want to keep the cargo test or remove? I have no preference, just comes down to a 1 minute run time with tests vs a 4 second run time without and what we want the user experience to be.

@rrybarczyk
Copy link
Collaborator Author

rrybarczyk commented Jul 5, 2024

I am experiencing the following issues in running ./scripts/sv2-header-check.sh:

  1. zsh: ./scripts/sv2-header-check.sh: bad interpreter: /usr/bin/sh: no such file or directory
  • This is solved by changing #! /usr/bin/sh at the top of the file to #!/bin/sh. However, will changing this break on other user's systems? The #!/bin/sh is what clippy-on-all-workspaces.sh uses.
  1. Running for the first time yields a success, however running a second time fails because the scripts/sv2.h file generated by this script does not get deleted after the run has completed.

My solution is to add rm -f scripts/sv2.h at the top of the file before running, which deletes the file if it exists.

@rrybarczyk
Copy link
Collaborator Author

@plebhash, thoughts on splitting up the clippy-on-all-workspaces into the following stand alone bash scripts:

  • scripts/clippy: Runs cargo clippy on all workspaces.
  • scripts/test: Runs cargo test on all workspaces.
  • scripts/fmt: Runs cargo nightly fmt on all workspaces.

Or is there a reason why these are all grouped together? If we choose to keep in same file, we should rename to clippy-fmt-and-test.sh or something.

@GitGab19
Copy link
Collaborator

GitGab19 commented Jul 6, 2024

@plebhash, thoughts on splitting up the clippy-on-all-workspaces into the following stand alone bash scripts:

* `scripts/clippy`: Runs `cargo clippy` on all workspaces.

* `scripts/test`: Runs `cargo test` on all workspaces.

* `scripts/fmt`: Runs `cargo nightly fmt` on all workspaces.

Or is there a reason why these are all grouped together? If we choose to keep in same file, we should rename to clippy-fmt-and-test.sh or something.

I think they are grouped just for convenience. I would keep them together, renaming the script in clippy-fmt-and-test.sh as you suggested.

@plebhash plebhash added this to the 1.1.0 milestone Aug 20, 2024
@plebhash plebhash moved this from Todo 📝 to In Progress 🏗️ in SV2 Roadmap 🛣️ Aug 23, 2024
@github-project-automation github-project-automation bot moved this from In Progress 🏗️ to Done ✅ in SV2 Roadmap 🛣️ Aug 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ci/cd CI/CD
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

3 participants