Skip to content

llmstudio-core to PyPI and build/push Docker images. #2

llmstudio-core to PyPI and build/push Docker images.

llmstudio-core to PyPI and build/push Docker images. #2

name: llmstudio-core to PyPI and build/push Docker images.
on:
push:
branches:
- main
paths:
- "libs/core/**"
workflow_dispatch:
inputs:
security-token:
description: 'Security token to trigger this workflow'
required: true
type: string
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Check security token
run: |
if [[ "${{ github.event.inputs.security-token }}" != "${{ secrets.SECURITY_TOKEN }}" ]]; then
echo "Unauthorized access attempt detected."
exit 1
fi
# Checkout the code
- name: Checkout code
uses: actions/checkout@v3
with:
ref: main
token: ${{ secrets.GH_TOKEN }}
# Set up Python environment
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: "3.x"
# Install Poetry
- name: Install Poetry
run: |
curl -sSL https://install.python-poetry.org | python3 -
# Configure Poetry with PyPI token
- name: Configure Poetry
run: |
poetry config pypi-token.pypi ${{ secrets.PYPI_API_TOKEN }}
# Build and publish package to PyPI
- name: Build and publish to PyPI
working-directory: ./libs/core
run: |
CURRENT_VERSION=$(poetry version --short)
FINAL_VERSION=$(echo "$CURRENT_VERSION" | sed -E 's/[a-zA-Z]+[0-9]*//')
echo "Checking for llmstudio-core==$FINAL_VERSION on PyPI..."
if python -m pip install llmstudio-core==$FINAL_VERSION --dry-run >/dev/null 2>&1; then
echo "Package llmstudio-core==$FINAL_VERSION is already available on PyPI. Please bump version."
exit 1
fi
poetry version "$FINAL_VERSION"
echo "Updated version: $(poetry version --short)"
poetry build
poetry publish
- name: Commit and push updated pyproject.toml
working-directory: ./libs/core
run: |
git config user.name "GitHub Actions"
git config user.email "[email protected]"
git add pyproject.toml
git commit -m "[fix] bump release version in pyproject.toml"
git push
# Extract the new version number from pyproject.toml
- name: Extract version.
working-directory: ./libs/core
run: |
echo "VERSION=$(poetry version --short)" >> $GITHUB_ENV
# Wait for the package to become available on PyPI
- name: Wait for PyPI to update
run: |
echo "Checking for llmstudio-core==${{ env.VERSION }} on PyPI..."
for i in {1..10}; do
if python -m pip install llmstudio-core==${{ env.VERSION }} --dry-run >/dev/null 2>&1; then
echo "Package llmstudio-core==${{ env.VERSION }} is available on PyPI."
break
else
echo "Package llmstudio-core==${{ env.VERSION }} not available yet. Waiting 15 seconds..."
sleep 15
fi
if [ $i -eq 10 ]; then
echo "Package did not become available in time."
exit 1
fi
done