Skip to content

Commit 1a11aa2

Browse files
Added validator name input to publish npm action
1 parent e87116b commit 1a11aa2

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

.github/actions/validator_pypi_publish/action.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
name: Publish Validator PyPi
22
description: Re-Usable action to publish a Validator to Guardrails PyPi
33
inputs:
4+
validator:
5+
description: 'Validator Name ex. guardrails/detect_pii'
6+
required: true
47
guardrails_token:
58
description: 'Guardrails Token'
69
required: true
@@ -59,10 +62,7 @@ runs:
5962
shell: bash
6063
run: |
6164
cd validator
62-
python __shared_ci_script__.py ./pyproject.toml
63-
echo "===== pyproject.toml file after edits ===="
64-
cat ./pyproject.toml
65-
echo "=========================================="
65+
python __shared_ci_script__.py ./pyproject.toml ${{ inputs.validator }}
6666
6767
- name: Build & Upload
6868
shell: bash

.github/actions/validator_pypi_publish/add_build_prefix.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import sys
44

55

6-
def add_package_name_prefix(pyproject_path):
6+
def add_package_name_prefix(pyproject_path, validator_name):
77
with open(pyproject_path, "r") as f:
88
content = f.read()
99

@@ -15,10 +15,11 @@ def add_package_name_prefix(pyproject_path):
1515

1616
existing_name = toml_data.get("project", {}).get("name")
1717
if not existing_name:
18-
print("Could not find the 'project.name' in pyproject.toml.")
18+
print(f"Could not find the 'project.name' in {pyproject_path}.")
1919
sys.exit(1)
2020

21-
new_name = f"guardrails-ai-validator-{existing_name}"
21+
validator_name = validator_name.split("/")
22+
new_name = f"{validator_name[0]}-grhub-{validator_name[1]}"
2223

2324
updated_content = re.sub(
2425
rf'(^name\s*=\s*")({re.escape(existing_name)})(")',
@@ -34,4 +35,11 @@ def add_package_name_prefix(pyproject_path):
3435

3536

3637
if __name__ == "__main__":
37-
add_package_name_prefix("pyproject.toml")
38+
if len(sys.argv) < 3:
39+
print("Usage: python script.py <pyproject_path> <validator-name>")
40+
sys.exit(1)
41+
42+
pyproject_path = sys.argv[1]
43+
validator_name = sys.argv[2]
44+
45+
add_package_name_prefix(pyproject_path, validator_name)

0 commit comments

Comments
 (0)