-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Migrate from Bash to Python (#12)
- Loading branch information
Showing
5 changed files
with
57 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
repos: | ||
- repo: https://github.com/psf/black | ||
rev: 24.4.2 | ||
hooks: | ||
- id: black | ||
name: Python black | ||
language_version: python3.12 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
- id: circleci_validate | ||
name: Validate CircleCI config | ||
description: This hook validates CircleCI config | ||
entry: circleci_validate.sh | ||
language: script | ||
entry: circleci-validate | ||
language: python | ||
files: .circleci/.*.yml | ||
pass_filenames: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#!/usr/bin/env python3 | ||
|
||
import os | ||
import subprocess | ||
import sys | ||
import shutil | ||
|
||
|
||
def main(): | ||
# Check if running in CircleCI environment | ||
if os.getenv("CIRCLECI"): | ||
print("Circleci environment detected, skipping validation.") | ||
sys.exit(0) | ||
|
||
# Check if CircleCI CLI is installed | ||
if not shutil.which("circleci"): | ||
print( | ||
"Circleci CLI could not be found. Install the latest CLI version https://circleci.com/docs/2.0/local-cli/#installation" | ||
) | ||
sys.exit(1) | ||
|
||
# Validate CircleCI config | ||
try: | ||
command = ["circleci", "config", "validate"] + sys.argv[1:] | ||
result = subprocess.run(command, capture_output=True, text=True) | ||
result.check_returncode() | ||
print("CircleCI Configuration Passed Validation.") | ||
except subprocess.CalledProcessError as e: | ||
print("CircleCI Configuration Failed Validation.") | ||
print(e.stderr) | ||
sys.exit(1) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
from setuptools import setup, find_packages | ||
|
||
setup( | ||
name="pre_commit_circleci", | ||
version="0.1.0", | ||
packages=find_packages(), | ||
py_modules=["circleci_validate"], | ||
entry_points={ | ||
"console_scripts": [ | ||
"circleci-validate=circleci_validate:main", | ||
], | ||
}, | ||
) |