Skip to content

Commit 186116d

Browse files
authored
Merge pull request #28 from BerryBytes/feat/sync-precommit
Feat/sync precommit
2 parents ebfdf7c + b5dfd24 commit 186116d

13 files changed

Lines changed: 129 additions & 24 deletions

File tree

.github/scripts/extract_config.sh

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# #!/bin/bash
2+
3+
# # Extract the YAML config from setup_pre_commit_config function in global/pre-commit.sh
4+
# # and save it to global/precommitFile/.pre-commit-config.yaml
5+
6+
# mkdir -p global/precommitFile
7+
8+
# sed -n '/cat > "\$file" <<'\''EOF'\''/,/EOF/p' global/pre-commit.sh | sed '1d;$d' > global/precommitFile/.pre-commit-config.yaml
9+
10+
# echo "Config extracted to global/precommitFile/.pre-commit-config.yaml"
11+
12+
#!/bin/bash
13+
14+
# List of directories in root that may contain pre-commit.sh
15+
LANG_DIRS=("global" "golang" "python" "terraform" "typescript")
16+
17+
echo "🔍 Searching for pre-commit.sh in project folders..."
18+
19+
for dir in "${LANG_DIRS[@]}"; do
20+
script_path="$dir/pre-commit.sh"
21+
22+
if [[ -f "$script_path" ]]; then
23+
echo "➡️ Found: $script_path"
24+
25+
# Create destination folder
26+
dest_dir="$dir/precommitFile"
27+
mkdir -p "$dest_dir"
28+
29+
# Output file
30+
dest_file="$dest_dir/.pre-commit-config.yaml"
31+
32+
# Extract YAML using sed
33+
sed -n "/cat > \"\\\$file\" <<'EOF'/,/EOF/p" "$script_path" \
34+
| sed '1d;$d' > "$dest_file"
35+
36+
echo " ✓ Extracted config → $dest_file"
37+
else
38+
echo "⚠️ No pre-commit.sh found in $dir — skipping."
39+
fi
40+
done
41+
42+
echo "✅ Extraction complete!"

.github/workflows/sync-precommit-config.yaml

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,9 @@ jobs:
2626
persist-credentials: true
2727

2828
- name: Extract config from script
29-
run: bash global/extract_config.sh
30-
31-
# - name: Validate YAML syntax
32-
# run: |
33-
# if command -v yamllint >/dev/null 2>&1; then
34-
# yamllint global/precommitFile/.pre-commit-config.yaml
35-
# else
36-
# python3 -c "import yaml; yaml.safe_load(open('global/precommitFile/.pre-commit-config.yaml'))"
37-
# fi
38-
39-
# - name: Copy updated pre-commit config to root
40-
# run: |
41-
# cp global/precommitFile/.pre-commit-config.yaml .pre-commit-config.yaml
29+
run: |
30+
chmod +x .github/scripts/extract_config.sh
31+
.github/scripts/extract_config.sh
4232
4333
- name: Check if changes exist
4434
id: changes

global/extract_config.sh

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
#!/bin/bash
1+
# #!/bin/bash
22

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

6-
mkdir -p global/precommitFile
6+
# mkdir -p global/precommitFile
77

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

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

global/pre-commit.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ setup_pre_commit_config() {
6868
if [[ ! -f "$file" ]]; then
6969
cat > "$file" <<'EOF'
7070
repos:
71-
# ✅ Precommit hooks
71+
############ ✅ Precommit hooks #############
7272
- repo: https://github.com/pre-commit/pre-commit-hooks
7373
rev: v4.4.0
7474
hooks:
@@ -81,7 +81,7 @@ repos:
8181
- id: destroyed-symlinks
8282
- id: pretty-format-json
8383
84-
# ✅ golang fmt and go tidey
84+
########## ✅ golang fmt and go tidey #########
8585
- repo: https://github.com/TekWizely/pre-commit-golang
8686
rev: v1.0.0-rc.1
8787
hooks:

global/precommitFile/.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
repos:
2-
# ✅ Precommit hooks
2+
############ ✅ Precommit hooks #############
33
- repo: https://github.com/pre-commit/pre-commit-hooks
44
rev: v4.4.0
55
hooks:
@@ -12,7 +12,7 @@ repos:
1212
- id: destroyed-symlinks
1313
- id: pretty-format-json
1414

15-
# ✅ golang fmt and go tidey
15+
########## ✅ golang fmt and go tidey #########
1616
- repo: https://github.com/TekWizely/pre-commit-golang
1717
rev: v1.0.0-rc.1
1818
hooks:

golang/pre-commit.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ setup_pre_commit_config() {
6464

6565
cat > "$file" <<'EOF'
6666
repos:
67+
############ ✅ Precommit hooks #############
6768
- repo: https://github.com/pre-commit/pre-commit-hooks
6869
rev: v4.4.0
6970
hooks:
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
repos:
2+
############ ✅ Precommit hooks #############
3+
- repo: https://github.com/pre-commit/pre-commit-hooks
4+
rev: v4.4.0
5+
hooks:
6+
- id: check-yaml
7+
args: ["--allow-multiple-documents"]
8+
- id: end-of-file-fixer
9+
- id: trailing-whitespace
10+
- id: check-added-large-files
11+
- id: check-vcs-permalinks
12+
- id: check-symlinks
13+
- id: destroyed-symlinks
14+
15+
- repo: https://github.com/TekWizely/pre-commit-golang
16+
rev: v1.0.0-rc.1
17+
hooks:
18+
- id: go-fmt
19+
args: [-w]
20+
- id: go-mod-tidy # Ensure go.mod & go.sum are tidy
21+
22+
23+
- repo: https://github.com/codespell-project/codespell
24+
rev: v2.2.5
25+
hooks:
26+
- id: codespell
27+
files: ^.*\.(py|c|h|md|rst|yml|go|sh|sql|tf|yaml)$
28+
exclude: ^.*(_test\.go|\.min\.js|\.map)$
29+
args: ["--ignore-words-list", "hist,nd"]
30+
31+
- repo: https://github.com/zricethezav/gitleaks
32+
rev: v8.18.0
33+
hooks:
34+
- id: gitleaks
35+
args: ["detect", "--verbose"]

python/pre-commit.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ setup_pre_commit_config() {
6060

6161
cat > "$config" <<'EOF'
6262
repos:
63-
# ✅ Generic pre-commit hygiene
63+
############ ✅ Precommit hooks #############
6464
- repo: https://github.com/pre-commit/pre-commit-hooks
6565
rev: v6.0.0
6666
hooks:

python/precommitFile/.pre-commit-config.yaml

Whitespace-only changes.

terraform/pre-commit.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ setup_pre_commit_config() {
4444
if [ ! -f "$pre_commit_config" ]; then
4545
cat > "$pre_commit_config" <<EOF
4646
repos:
47+
############ ✅ Terraform Docs #############
4748
- repo: https://github.com/terraform-docs/terraform-docs
4849
rev: "v0.16.0"
4950
hooks:

0 commit comments

Comments
 (0)