Skip to content

Commit 95fad15

Browse files
Pre commit Hook added. (#203)
* 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]>
1 parent 9fe2a37 commit 95fad15

File tree

5 files changed

+50
-1
lines changed

5 files changed

+50
-1
lines changed

.github-workflow-script

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/usr/bin/env python3
2+
3+
"""Extract steps containing special env variable COMMIT_HOOKS from Github workflow"""
4+
import yaml
5+
import argparse
6+
7+
# Parse command-line arguments
8+
parser = argparse.ArgumentParser()
9+
parser.add_argument("workflow_file",
10+
help="Path to the GitHub Actions workflow file")
11+
12+
args = parser.parse_args()
13+
14+
# Load the GitHub Actions workflow file as YAML
15+
with open(args.workflow_file, "r") as file:
16+
data = yaml.safe_load(file)
17+
18+
print("#!/bin/bash")
19+
# Loop over all jobs
20+
for job_name, job in data["jobs"].items():
21+
# Loop over all steps in the job
22+
for step in job["steps"]:
23+
# Check if the step has a KCIDB_HOOKS environment variable
24+
if "env" in step and step["env"].get("COMMIT_HOOKS") == "pre-commit":
25+
# Print the name of the step
26+
print(f"\n# {step['name']}")
27+
# Extract the command(s) from the step
28+
command = step.get("run", [])
29+
# Print the command(s)
30+
for line in command if isinstance(command, list) else [command]:
31+
print(line)

.github/workflows/build.yml

+2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ jobs:
1919
uses: actions/checkout@v2
2020

2121
- name: gofmt check
22+
env:
23+
COMMIT_HOOKS: pre-commit
2224
run: |
2325
if [ "$(gofmt -s -l . | wc -l)" -ne 0 ]
2426
then

.pre-commit

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/bin/bash
2+
3+
# If there are whitespace errors, print the offending file names and fail.
4+
# git diff-index --check --cached $against --
5+
6+
# Execute steps extracted from GitHub Actions
7+
. <(./.github-workflow-script .github/workflows/build.yml)

DEVELOPMENT.md

+10
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,16 @@ To run tests, use the following command:
7070
go test ./...
7171
```
7272

73+
## **Contributing Prerequisites**
74+
75+
Setting up pre-commit:
76+
77+
Execute the following command to create a symbolic link named `pre-commit` in the `.git/hooks` directory that points to the `.pre-commit`.
78+
79+
```bash
80+
ln -s ../../.pre-commit .git/hooks/pre-commit
81+
```
82+
7383
## **Contributing Guidelines**
7484

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

pkg/cmd/get/environment.go

-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ var ChaosEnvironmentCmd = &cobra.Command{
5252

5353
environmentID, err := cmd.Flags().GetString("environment-id")
5454
utils.PrintError(err)
55-
5655
if environmentID == "" {
5756
utils.White_B.Print("\nEnter the Environment ID: ")
5857
fmt.Scanln(&environmentID)

0 commit comments

Comments
 (0)