|
| 1 | +name: Publish Validator PyPi |
| 2 | +description: Re-Usable action to publish a Validator to Guardrails PyPi |
| 3 | +inputs: |
| 4 | + github_token: |
| 5 | + description: 'GitHub Token' |
| 6 | + required: true |
| 7 | + guardrails_token: |
| 8 | + description: 'Guardrails Token' |
| 9 | + required: true |
| 10 | + pypi_repository_url: |
| 11 | + description: 'PyPi Repository URL' |
| 12 | + required: false |
| 13 | + default: 'https://pypi.guardrailsai.com' |
| 14 | + |
| 15 | +runs: |
| 16 | + using: "composite" |
| 17 | + steps: |
| 18 | + - name: Checkout "Validator" Repository |
| 19 | + uses: actions/checkout@v3 |
| 20 | + with: |
| 21 | + path: 'validator' |
| 22 | + |
| 23 | + - name: Checkout "Action" repository |
| 24 | + uses: actions/checkout@v3 |
| 25 | + with: |
| 26 | + token: ${{ inputs.github_token }} |
| 27 | + repository: guardrails-ai/shared-ci |
| 28 | + ref: main |
| 29 | + path: shared-ci-scripts |
| 30 | + sparse-checkout: | |
| 31 | + .github |
| 32 | +
|
| 33 | + - name: Set up Python |
| 34 | + uses: actions/setup-python@v4 |
| 35 | + with: |
| 36 | + python-version: '3.10' |
| 37 | + |
| 38 | + - name: Install Twine & Build |
| 39 | + shell: bash |
| 40 | + run: | |
| 41 | + python -m pip install --upgrade pip |
| 42 | + pip install twine build toml |
| 43 | +
|
| 44 | + - name: Create .pypirc |
| 45 | + shell: bash |
| 46 | + run: | |
| 47 | + touch ~/.pypirc |
| 48 | + echo "[distutils]" >> ~/.pypirc |
| 49 | + echo "index-servers =" >> ~/.pypirc |
| 50 | + echo " private-repository" >> ~/.pypirc |
| 51 | + echo "" >> ~/.pypirc |
| 52 | + echo "[private-repository]" >> ~/.pypirc |
| 53 | + echo "repository = ${{ inputs.pypi_repository_url }}" >> ~/.pypirc |
| 54 | + echo "username = __token__" >> ~/.pypirc |
| 55 | + echo "password = ${{ inputs.guardrails_token }}" >> ~/.pypirc |
| 56 | +
|
| 57 | + - name: Move CI Scripts to Validator |
| 58 | + shell: bash |
| 59 | + run: | |
| 60 | + mv shared-ci-scripts/.github/actions/validator_pypi_publish/add_build_prefix.py ./validator/__shared_ci_script__.py |
| 61 | +
|
| 62 | + - name: Add Package Prefix |
| 63 | + shell: bash |
| 64 | + run: | |
| 65 | + cd validator |
| 66 | + python __shared_ci_script__.py ./pyproject.toml |
| 67 | + echo "===== pyproject.toml file after edits ====" |
| 68 | + cat ./pyproject.toml |
| 69 | + echo "==========================================" |
| 70 | +
|
| 71 | + - name: Build & Upload |
| 72 | + shell: bash |
| 73 | + run: | |
| 74 | + cd validator |
| 75 | + python -m build |
| 76 | + twine upload dist/* -u __token__ -p ${{ inputs.guardrails_token }} -r private-repository |
| 77 | + |
0 commit comments