Merge pull request #1969 from github/redsun82/pre-commit
Add pre-commit configuration
This commit is contained in:
commit
dad0ebd6ca
2 changed files with 29 additions and 5 deletions
20
.pre-commit-config.yaml
Normal file
20
.pre-commit-config.yaml
Normal file
|
|
@ -0,0 +1,20 @@
|
||||||
|
repos:
|
||||||
|
- repo: local
|
||||||
|
hooks:
|
||||||
|
- id: compile-ts
|
||||||
|
name: Compile typescript
|
||||||
|
files: \.[tj]s$
|
||||||
|
language: system
|
||||||
|
entry: npm run build
|
||||||
|
pass_filenames: false
|
||||||
|
- id: lint-ts
|
||||||
|
name: Lint typescript code
|
||||||
|
files: \.ts$
|
||||||
|
language: system
|
||||||
|
entry: npm run lint -- --fix
|
||||||
|
- id: pr-checks-sync
|
||||||
|
name: Synchronize PR check workflows
|
||||||
|
files: ^.github/workflows/__.*\.yml$|^pr-checks
|
||||||
|
language: system
|
||||||
|
entry: python3 pr-checks/sync.py
|
||||||
|
pass_filenames: false
|
||||||
14
pr-checks/sync.py
Normal file → Executable file
14
pr-checks/sync.py
Normal file → Executable file
|
|
@ -1,6 +1,8 @@
|
||||||
|
#!/usr/bin/env python
|
||||||
|
|
||||||
import ruamel.yaml
|
import ruamel.yaml
|
||||||
from ruamel.yaml.scalarstring import FoldedScalarString
|
from ruamel.yaml.scalarstring import FoldedScalarString
|
||||||
import os
|
import pathlib
|
||||||
import textwrap
|
import textwrap
|
||||||
|
|
||||||
# The default set of CodeQL Bundle versions to use for the PR checks.
|
# The default set of CodeQL Bundle versions to use for the PR checks.
|
||||||
|
|
@ -47,9 +49,11 @@ def writeHeader(checkStream):
|
||||||
yaml = ruamel.yaml.YAML()
|
yaml = ruamel.yaml.YAML()
|
||||||
yaml.Representer = NonAliasingRTRepresenter
|
yaml.Representer = NonAliasingRTRepresenter
|
||||||
|
|
||||||
|
this_dir = pathlib.Path(__file__).resolve().parent
|
||||||
|
|
||||||
allJobs = {}
|
allJobs = {}
|
||||||
for file in os.listdir('checks'):
|
for file in (this_dir / 'checks').glob('*.yml'):
|
||||||
with open(f"checks/{file}", 'r') as checkStream:
|
with open(file, 'r') as checkStream:
|
||||||
checkSpecification = yaml.load(checkStream)
|
checkSpecification = yaml.load(checkStream)
|
||||||
|
|
||||||
matrix = []
|
matrix = []
|
||||||
|
|
@ -126,9 +130,9 @@ for file in os.listdir('checks'):
|
||||||
checkJob['env'] = checkJob.get('env', {})
|
checkJob['env'] = checkJob.get('env', {})
|
||||||
if 'CODEQL_ACTION_TEST_MODE' not in checkJob['env']:
|
if 'CODEQL_ACTION_TEST_MODE' not in checkJob['env']:
|
||||||
checkJob['env']['CODEQL_ACTION_TEST_MODE'] = True
|
checkJob['env']['CODEQL_ACTION_TEST_MODE'] = True
|
||||||
checkName = file[:len(file) - 4]
|
checkName = file.stem
|
||||||
|
|
||||||
with open(f"../.github/workflows/__{checkName}.yml", 'w') as output_stream:
|
with open(this_dir.parent / ".github" / "workflows" / f"__{checkName}.yml", 'w') as output_stream:
|
||||||
writeHeader(output_stream)
|
writeHeader(output_stream)
|
||||||
yaml.dump({
|
yaml.dump({
|
||||||
'name': f"PR Check - {checkSpecification['name']}",
|
'name': f"PR Check - {checkSpecification['name']}",
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue