Skip to content

Commit 28d6dff

Browse files
committed
ci: add pre-push package validation
add a pre-push hook to build and validate the standalone executable - run the packaging script before each push - verify the packaged executable with the version command - support windows and unix executable paths - document pre-commit setup in CONTRIBUTING.md
1 parent d1a53a7 commit 28d6dff

3 files changed

Lines changed: 36 additions & 0 deletions

File tree

‎.pre-commit-config.yaml‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,12 @@ repos:
44
hooks:
55
- id: trailing-whitespace
66
- id: end-of-file-fixer
7+
8+
- repo: local
9+
hooks:
10+
- id: build-and-test-package
11+
name: Build and test package
12+
entry: python scripts/pre_push_hook.py
13+
language: system
14+
pass_filenames: false
15+
stages: [pre-push]

‎CONTRIBUTING.md‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@ Install the required tools listed in the [README](README.md#requirements), then
88

99
```shell
1010
python java_inventory.py setup
11+
````
12+
13+
Install `pre-commit` for the development hooks:
14+
15+
```shell
16+
pip install pre-commit
17+
pre-commit install
1118
```
1219

1320
Use the CLI directly while developing:

‎scripts/pre_push_hook.py‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/usr/bin/env python3
2+
3+
"""Build the standalone executable and verify its version command."""
4+
5+
# pylint: disable=missing-function-docstring
6+
7+
import os
8+
import subprocess
9+
import sys
10+
11+
12+
def main():
13+
subprocess.run([sys.executable, "package.py"], check=True)
14+
15+
executable = "dist/java-inventory.exe" if os.name == "nt" else "dist/java-inventory"
16+
subprocess.run([executable, "version"], check=True)
17+
18+
19+
if __name__ == "__main__":
20+
main()

0 commit comments

Comments
 (0)