Skip to content

Commit

Permalink
Pre commit Hook added. (litmuschaos#203)
Browse files Browse the repository at this point in the history
* Added Workflow script.

Signed-off-by: Aryan <[email protected]>

* Added pre commit script.

Signed-off-by: Aryan <[email protected]>

* Modified build with pre-commit hook.

Signed-off-by: Aryan <[email protected]>

* Removed check.

Signed-off-by: Aryan Bhokare <[email protected]>

* Added pre-commit prerequisite.

Signed-off-by: Aryan Bhokare <[email protected]>

---------

Signed-off-by: Aryan <[email protected]>
Signed-off-by: Aryan Bhokare <[email protected]>
  • Loading branch information
aryan-bhokare authored Feb 28, 2024
1 parent 9fe2a37 commit 95fad15
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 1 deletion.
31 changes: 31 additions & 0 deletions .github-workflow-script
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/usr/bin/env python3

"""Extract steps containing special env variable COMMIT_HOOKS from Github workflow"""
import yaml
import argparse

# Parse command-line arguments
parser = argparse.ArgumentParser()
parser.add_argument("workflow_file",
help="Path to the GitHub Actions workflow file")

args = parser.parse_args()

# Load the GitHub Actions workflow file as YAML
with open(args.workflow_file, "r") as file:
data = yaml.safe_load(file)

print("#!/bin/bash")
# Loop over all jobs
for job_name, job in data["jobs"].items():
# Loop over all steps in the job
for step in job["steps"]:
# Check if the step has a KCIDB_HOOKS environment variable
if "env" in step and step["env"].get("COMMIT_HOOKS") == "pre-commit":
# Print the name of the step
print(f"\n# {step['name']}")
# Extract the command(s) from the step
command = step.get("run", [])
# Print the command(s)
for line in command if isinstance(command, list) else [command]:
print(line)
2 changes: 2 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ jobs:
uses: actions/checkout@v2

- name: gofmt check
env:
COMMIT_HOOKS: pre-commit
run: |
if [ "$(gofmt -s -l . | wc -l)" -ne 0 ]
then
Expand Down
7 changes: 7 additions & 0 deletions .pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash

# If there are whitespace errors, print the offending file names and fail.
# git diff-index --check --cached $against --

# Execute steps extracted from GitHub Actions
. <(./.github-workflow-script .github/workflows/build.yml)
10 changes: 10 additions & 0 deletions DEVELOPMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,16 @@ To run tests, use the following command:
go test ./...
```

## **Contributing Prerequisites**

Setting up pre-commit:

Execute the following command to create a symbolic link named `pre-commit` in the `.git/hooks` directory that points to the `.pre-commit`.

```bash
ln -s ../../.pre-commit .git/hooks/pre-commit
```

## **Contributing Guidelines**

If you wish to contribute to **`litmusctl`**, please follow our [contributing guidelines](https://github.com/litmuschaos/litmus/blob/master/CONTRIBUTING.md). Your contributions are valuable, and adhering to these guidelines ensures a smooth and collaborative development process.
Expand Down
1 change: 0 additions & 1 deletion pkg/cmd/get/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ var ChaosEnvironmentCmd = &cobra.Command{

environmentID, err := cmd.Flags().GetString("environment-id")
utils.PrintError(err)

if environmentID == "" {
utils.White_B.Print("\nEnter the Environment ID: ")
fmt.Scanln(&environmentID)
Expand Down

0 comments on commit 95fad15

Please sign in to comment.