Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions .github/scripts/extract_config.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# #!/bin/bash

# # Extract the YAML config from setup_pre_commit_config function in global/pre-commit.sh
# # and save it to global/precommitFile/.pre-commit-config.yaml

# mkdir -p global/precommitFile

# sed -n '/cat > "\$file" <<'\''EOF'\''/,/EOF/p' global/pre-commit.sh | sed '1d;$d' > global/precommitFile/.pre-commit-config.yaml

# echo "Config extracted to global/precommitFile/.pre-commit-config.yaml"

#!/bin/bash

# List of directories in root that may contain pre-commit.sh
LANG_DIRS=("global" "golang" "python" "terraform" "typescript")

echo "🔍 Searching for pre-commit.sh in project folders..."

for dir in "${LANG_DIRS[@]}"; do
script_path="$dir/pre-commit.sh"

if [[ -f "$script_path" ]]; then
echo "➡️ Found: $script_path"

# Create destination folder
dest_dir="$dir/precommitFile"
mkdir -p "$dest_dir"

# Output file
dest_file="$dest_dir/.pre-commit-config.yaml"

# Extract YAML using sed
sed -n "/cat > \"\\\$file\" <<'EOF'/,/EOF/p" "$script_path" \
| sed '1d;$d' > "$dest_file"

echo " ✓ Extracted config → $dest_file"
else
echo "⚠️ No pre-commit.sh found in $dir — skipping."
fi
done

echo "✅ Extraction complete!"
16 changes: 3 additions & 13 deletions .github/workflows/sync-precommit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,9 @@ jobs:
persist-credentials: true

- name: Extract config from script
run: bash global/extract_config.sh

# - name: Validate YAML syntax
# run: |
# if command -v yamllint >/dev/null 2>&1; then
# yamllint global/precommitFile/.pre-commit-config.yaml
# else
# python3 -c "import yaml; yaml.safe_load(open('global/precommitFile/.pre-commit-config.yaml'))"
# fi

# - name: Copy updated pre-commit config to root
# run: |
# cp global/precommitFile/.pre-commit-config.yaml .pre-commit-config.yaml
run: |
chmod +x .github/scripts/extract_config.sh
.github/scripts/extract_config.sh

- name: Check if changes exist
id: changes
Expand Down
12 changes: 6 additions & 6 deletions global/extract_config.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#!/bin/bash
# #!/bin/bash

# Extract the YAML config from setup_pre_commit_config function in global/pre-commit.sh
# and save it to global/precommitFile/.pre-commit-config.yaml
# # Extract the YAML config from setup_pre_commit_config function in global/pre-commit.sh
# # and save it to global/precommitFile/.pre-commit-config.yaml

mkdir -p global/precommitFile
# mkdir -p global/precommitFile

sed -n '/cat > "\$file" <<'\''EOF'\''/,/EOF/p' global/pre-commit.sh | sed '1d;$d' > global/precommitFile/.pre-commit-config.yaml
# sed -n '/cat > "\$file" <<'\''EOF'\''/,/EOF/p' global/pre-commit.sh | sed '1d;$d' > global/precommitFile/.pre-commit-config.yaml

echo "Config extracted to global/precommitFile/.pre-commit-config.yaml"
# echo "Config extracted to global/precommitFile/.pre-commit-config.yaml"
4 changes: 2 additions & 2 deletions global/pre-commit.sh
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ setup_pre_commit_config() {
if [[ ! -f "$file" ]]; then
cat > "$file" <<'EOF'
repos:
# ✅ Precommit hooks
############ ✅ Precommit hooks #############
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
Expand All @@ -81,7 +81,7 @@ repos:
- id: destroyed-symlinks
- id: pretty-format-json

# ✅ golang fmt and go tidey
########## ✅ golang fmt and go tidey #########
- repo: https://github.com/TekWizely/pre-commit-golang
rev: v1.0.0-rc.1
hooks:
Expand Down
4 changes: 2 additions & 2 deletions global/precommitFile/.pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
repos:
# ✅ Precommit hooks
############ ✅ Precommit hooks #############
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
Expand All @@ -12,7 +12,7 @@ repos:
- id: destroyed-symlinks
- id: pretty-format-json

# ✅ golang fmt and go tidey
########## ✅ golang fmt and go tidey #########
- repo: https://github.com/TekWizely/pre-commit-golang
rev: v1.0.0-rc.1
hooks:
Expand Down
1 change: 1 addition & 0 deletions golang/pre-commit.sh
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ setup_pre_commit_config() {

cat > "$file" <<'EOF'
repos:
############ ✅ Precommit hooks #############
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
Expand Down
35 changes: 35 additions & 0 deletions golang/precommitFile/.pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
repos:
############ ✅ Precommit hooks #############
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: check-yaml
args: ["--allow-multiple-documents"]
- id: end-of-file-fixer
- id: trailing-whitespace
- id: check-added-large-files
- id: check-vcs-permalinks
- id: check-symlinks
- id: destroyed-symlinks

- repo: https://github.com/TekWizely/pre-commit-golang
rev: v1.0.0-rc.1
hooks:
- id: go-fmt
args: [-w]
- id: go-mod-tidy # Ensure go.mod & go.sum are tidy


- repo: https://github.com/codespell-project/codespell
rev: v2.2.5
hooks:
- id: codespell
files: ^.*\.(py|c|h|md|rst|yml|go|sh|sql|tf|yaml)$
exclude: ^.*(_test\.go|\.min\.js|\.map)$
args: ["--ignore-words-list", "hist,nd"]

- repo: https://github.com/zricethezav/gitleaks
rev: v8.18.0
hooks:
- id: gitleaks
args: ["detect", "--verbose"]
2 changes: 1 addition & 1 deletion python/pre-commit.sh
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ setup_pre_commit_config() {

cat > "$config" <<'EOF'
repos:
# ✅ Generic pre-commit hygiene
############ ✅ Precommit hooks #############
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v6.0.0
hooks:
Expand Down
Empty file.
1 change: 1 addition & 0 deletions terraform/pre-commit.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ setup_pre_commit_config() {
if [ ! -f "$pre_commit_config" ]; then
cat > "$pre_commit_config" <<EOF
repos:
############ ✅ Terraform Docs #############
- repo: https://github.com/terraform-docs/terraform-docs
rev: "v0.16.0"
hooks:
Expand Down
Empty file.
1 change: 1 addition & 0 deletions typescript/pre-commit.sh
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ setup_pre_commit_config() {
if [[ ! -f "$file" ]]; then
cat > "$file" <<'EOF'
repos:
############ ✅ Precommit hooks #############
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
Expand Down
35 changes: 35 additions & 0 deletions typescript/precommitFile/.pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
repos:
############ ✅ Precommit hooks #############
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: check-yaml
- id: end-of-file-fixer
- id: trailing-whitespace
- id: check-added-large-files

# - repo: https://github.com/pre-commit/mirrors-prettier
# rev: v3.1.0
# hooks:
# - id: prettier
# files: \.(js|jsx|ts|tsx|css|html|json)$
# types: [file]
# exclude: "node_modules/"
# args: ['--config', '.prettierrc']

- repo: https://github.com/thibaudcolas/pre-commit-stylelint
rev: v15.10.3
hooks:
- id: stylelint
files: \.(css|scss)$
exclude: "node_modules/"
additional_dependencies:
- stylelint
- stylelint-config-standard
args: ['--config', '.stylelintrc.json', '--fix']

- repo: https://github.com/gitleaks/gitleaks
rev: v8.21.0
hooks:
- id: gitleaks
args: ["detect", "--verbose"]