@@ -3,48 +3,58 @@ name: Sync Precommit Config
33on :
44 push :
55 branches :
6- - main
7- paths :
8- - " .pre-commit-config.yaml"
9- - " global/pre-commit.sh"
6+ - feat/precommit-config
107 workflow_dispatch :
118
129permissions :
1310 contents : write
11+ pull-requests : write
12+
13+ concurrency :
14+ group : ${{ github.workflow }}-${{ github.ref }}
15+ cancel-in-progress : true
1416
1517jobs :
1618 sync :
1719 runs-on : ubuntu-latest
1820
1921 steps :
2022 - name : Checkout repository
21- uses : actions/checkout@v4
23+ uses : actions/checkout@v4
2224 with :
2325 fetch-depth : 0
2426 persist-credentials : true
2527
26- - name : Ensure target folder exists inside global/
27- run : mkdir -p global/precommitFile
28+ - name : Extract config from script
29+ run : bash global/extract_config.sh
2830
29- - name : Copy updated pre-commit config to global/precommitFile
31+ - name : Validate YAML syntax
3032 run : |
31- cp .pre-commit-config.yaml global/precommitFile/.pre-commit-config.yaml
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
3242
3343 - name : Check if changes exist
3444 id : changes
3545 run : |
36- if git diff --quiet global/precommitFile/ .pre-commit-config.yaml; then
46+ if git diff --quiet .pre-commit-config.yaml; then
3747 echo "changed=false" >> $GITHUB_OUTPUT
3848 else
3949 echo "changed=true" >> $GITHUB_OUTPUT
4050 fi
4151
4252 - name : Commit & push updates
43- if : steps.changes.outputs.changed == 'true'
53+ if : steps.changes.outputs.changed == 'true' && github.event_name == 'push'
4454 run : |
4555 git config user.name "GitHub Actions"
4656 git config user.email "actions@github.com"
47-
48- git add global/precommitFile/ .pre-commit-config.yaml
49- git commit -m "Sync pre-commit YAML config → global/precommitFile"
57+
58+ git add .pre-commit-config.yaml
59+ git commit -m "Sync pre-commit YAML config from global/precommitFile"
5060 git push
0 commit comments