PyPI prerelease any module. #65
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
name: PyPI prerelease any module. | |
on: | |
workflow_dispatch: | |
inputs: | |
library: | |
required: true | |
type: choice | |
description: "Choose the library to deploy (note: it points to develop branch only)" | |
options: | |
- ./libs/llmstudio | |
- ./libs/core | |
- ./libs/proxy | |
- ./libs/tracker | |
target_version: | |
description: "Target version (e.g., 1.1.0)" | |
required: true | |
default: "1.1.0" | |
jobs: | |
deploy: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
with: | |
ref: develop | |
token: ${{ secrets.GH_TOKEN }} | |
- name: Set up Python | |
uses: actions/setup-python@v4 | |
with: | |
python-version: "3.x" | |
- name: Install Poetry | |
run: curl -sSL https://install.python-poetry.org | python3 - | |
- name: Configure Poetry | |
run: poetry config pypi-token.pypi ${{ secrets.PYPI_API_TOKEN }} | |
- name: Check PyPI for Target Version | |
working-directory: ${{ inputs.library }} | |
id: check-version | |
run: | | |
TARGET_VERSION="${{ github.event.inputs.target_version }}" | |
PACKAGE_NAME=$(poetry version | awk '{print $1}') | |
RESPONSE=$(curl -s "https://pypi.org/pypi/$PACKAGE_NAME/json" || echo "{}") | |
echo "$RESPONSE" | jq -r '.releases | keys[]' > all_versions.txt | |
if grep -qx "$TARGET_VERSION" all_versions.txt; then | |
echo "Error: Version ${{ github.event.inputs.target_version }} already exists on PyPI." | |
exit 1 | |
fi | |
NEXT_ALPHA=$(grep "^${TARGET_VERSION}a[0-9]*$" all_versions.txt | sort -V | tail -n 1 | awk -F'a' '{print $2}') | |
if [[ -z "$NEXT_ALPHA" ]]; then | |
NEW_VERSION="${TARGET_VERSION}a0" | |
else | |
NEW_VERSION="${TARGET_VERSION}a$((NEXT_ALPHA + 1))" | |
fi | |
echo "new_version=$NEW_VERSION" >> $GITHUB_ENV | |
echo "Determined new version: $NEW_VERSION" | |
- name: Build and publish to PyPI as development release | |
working-directory: ${{ inputs.library }} | |
run: | | |
poetry version ${{ env.new_version }} | |
poetry build | |
poetry publish | |
- name: Commit and push updated pyproject.toml | |
working-directory: ${{ inputs.library }} | |
run: | | |
git config user.name "GitHub Actions" | |
git config user.email "[email protected]" | |
git add pyproject.toml | |
git commit -m "[fix] bump prerelease version in pyproject.toml" | |
git push | |
- name: Wait for PyPI to update | |
working-directory: ${{ inputs.library }} | |
run: | | |
VERSION=$(poetry version --short) | |
PACKAGE_NAME=$(poetry version | awk '{print $1}') | |
echo "Checking for $PACKAGE_NAME==$VERSION on PyPI..." | |
for i in {1..10}; do | |
if python -m pip install $PACKAGE_NAME==${VERSION} --dry-run >/dev/null 2>&1; then | |
echo "Package $PACKAGE_NAME==${VERSION} is available on PyPI." | |
break | |
else | |
echo "Package $PACKAGE_NAME==${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 |