Skip to content
This repository was archived by the owner on Jul 16, 2025. It is now read-only.
This repository was archived by the owner on Jul 16, 2025. It is now read-only.

Setup Pre-Commit and Pre-Push Hooks for Automated Tasks #41

@codersquirrelbln

Description

@codersquirrelbln

Description:
Implement pre-commit and pre-push hooks to automate running Tailwind CSS compilation, build scripts, RuboCop for linting, and tests to ensure code quality before committing or pushing changes to GitHub.

Motivation:
By implementing these hooks, we can ensure that essential tasks are automated and executed before code is committed or pushed, maintaining code quality and preventing broken builds.

Tasks:

  • Install Husky for managing Git hooks.

  • Create a pre-commit hook to run the following tasks:

    • Compile Tailwind CSS:
      npx tailwindcss -i ./app/assets/stylesheets/application.tailwind.css -o ./app/assets/builds/application.css

    • Run the build script:
      node build.ci.js

    • Run RuboCop for linting:
      bundle exec rubocop

    • Run tests:
      bundle exec rspec

  • Create a pre-push hook to run the same tasks as the pre-commit hook.

  • Update package.json to include Husky configuration.

  • Ensure hooks check for uncommitted changes and prompt the user to commit them before proceeding.

Example package.json Scripts:

{
  "scripts": {
    "precommit": "npx tailwindcss -i ./app/assets/stylesheets/application.tailwind.css -o ./app/assets/builds/application.css && node build.ci.js && bundle exec rubocop && bundle exec rspec",
    "prepare": "husky install"
  }
}
  • Commands to Add Hooks:
npx husky add .husky/pre-commit "npm run precommit"
npx husky add .husky/pre-push "npm run precommit"

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions