Skip to content

Commit

Permalink
feat: Migrate from Bash to Python (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
zahorniak committed May 30, 2024
1 parent 849d723 commit f105fdd
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 21 deletions.
7 changes: 7 additions & 0 deletions .pre-commit-config.yaml
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
4 changes: 2 additions & 2 deletions .pre-commit-hooks.yaml
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
35 changes: 35 additions & 0 deletions circleci_validate.py
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()
19 changes: 0 additions & 19 deletions circleci_validate.sh

This file was deleted.

13 changes: 13 additions & 0 deletions setup.py
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",
],
},
)

0 comments on commit f105fdd

Please sign in to comment.