Skip to content

Commit 7f7aa09

Browse files
committed
Add pre-commit configuration
[pre-commit](https://pre-commit.com/) is a framework for easy set-up of pre-commit hooks. This adds configuration for it to run: * ts compilation * ts linting * pr-checks synchronization The latter required the `sync.py` to be callable from the project root. `pre-commit` can be enabled with ``` python3 -m pip install pre-commit pre-commit install ```
1 parent edb8265 commit 7f7aa09

File tree

2 files changed

+29
-5
lines changed

2 files changed

+29
-5
lines changed

.pre-commit-config.yaml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
repos:
2+
- repo: local
3+
hooks:
4+
- id: compile-ts
5+
name: Compile typescript
6+
files: \.[tj]s$
7+
language: system
8+
entry: npm run build
9+
pass_filenames: false
10+
- id: lint-ts
11+
name: Lint typescript code
12+
files: \.ts$
13+
language: system
14+
entry: npm run lint -- --fix
15+
- id: pr-checks-sync
16+
name: Synchronize PR check workflows
17+
files: ^.github/workflows/__.*\.yml$|^pr-checks
18+
language: system
19+
entry: python3 pr-checks/sync.py
20+
pass_filenames: false

pr-checks/sync.py

100644100755
Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
#!/usr/bin/env python
2+
13
import ruamel.yaml
24
from ruamel.yaml.scalarstring import FoldedScalarString
3-
import os
5+
import pathlib
46
import textwrap
57

68
# The default set of CodeQL Bundle versions to use for the PR checks.
@@ -47,9 +49,11 @@ def writeHeader(checkStream):
4749
yaml = ruamel.yaml.YAML()
4850
yaml.Representer = NonAliasingRTRepresenter
4951

52+
this_dir = pathlib.Path(__file__).resolve().parent
53+
5054
allJobs = {}
51-
for file in os.listdir('checks'):
52-
with open(f"checks/{file}", 'r') as checkStream:
55+
for file in (this_dir / 'checks').glob('*.yml'):
56+
with open(file, 'r') as checkStream:
5357
checkSpecification = yaml.load(checkStream)
5458

5559
matrix = []
@@ -126,9 +130,9 @@ def writeHeader(checkStream):
126130
checkJob['env'] = checkJob.get('env', {})
127131
if 'CODEQL_ACTION_TEST_MODE' not in checkJob['env']:
128132
checkJob['env']['CODEQL_ACTION_TEST_MODE'] = True
129-
checkName = file[:len(file) - 4]
133+
checkName = file.stem
130134

131-
with open(f"../.github/workflows/__{checkName}.yml", 'w') as output_stream:
135+
with open(this_dir.parent / ".github" / "workflows" / f"__{checkName}.yml", 'w') as output_stream:
132136
writeHeader(output_stream)
133137
yaml.dump({
134138
'name': f"PR Check - {checkSpecification['name']}",

0 commit comments

Comments
 (0)