Automate pypi deployment #8
Workflow file for this run
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: Publish Python 🐍 distributions 📦 to PyPI | ||
on: | ||
push: | ||
tags: | ||
- "*" | ||
jobs: | ||
extract-tag: | ||
runs-on: ubuntu-latest | ||
outputs: | ||
version: ${{ steps.extract_tag.outputs.tag }} | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- id: extract_tag | ||
name: Extract tag name | ||
run: echo "::set-output name=tag::$(echo $GITHUB_REF | cut -d / -f 3)" | ||
build-and-publish-test-pypi: | ||
needs: extract-tag | ||
runs-on: ubuntu-latest | ||
environment: | ||
name: pypi | ||
permissions: | ||
id-token: write # IMPORTANT: mandatory for trusted publishing | ||
steps: | ||
- uses: actions/checkout@master | ||
- name: Set up Python 3.9 | ||
uses: actions/setup-python@v3 | ||
with: | ||
python-version: "3.9" | ||
- name: Install dependencies | ||
run: python3 -m pip install setuptools wheel twine | ||
- name: Update version in setup.py | ||
run: sed -i "s/{{VERSION_PLACEHOLDER}}/${{ needs.extract-tag.outputs.version }}/g" | ||
setup.py | ||
- name: Update version in pyproject.toml | ||
run: sed -i "s/{{VERSION_PLACEHOLDER}}/${{ needs.extract-tag.outputs.version }}/g" | ||
pyproject.toml | ||
- name: Update package name in setup.py | ||
run: sed -i "s/{{PACKAGE_NAME_PLACEHOLDER}}/dspy-ai-test/g" | ||
setup.py | ||
- name: Update package name in pyproject.toml | ||
run: sed -i "s/{{PACKAGE_NAME_PLACEHOLDER}}/dspy-ai-test/g" | ||
pyproject.toml | ||
- name: Print setup.py content | ||
run: cat setup.py | ||
- name: Build a binary wheel | ||
run: python3 setup.py sdist bdist_wheel | ||
- name: Publish distribution 📦 to PyPI | ||
uses: pypa/gh-action-pypi-publish@release/v1 # This requires a trusted publisher to be setup in pypi/testpypi | ||
with: | ||
repository-url: https://test.pypi.org/legacy/ | ||
test-intro-script: | ||
needs: [extract-tag, build-and-publish-test-pypi] | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Set up Python 3.9 | ||
uses: actions/setup-python@v3 | ||
with: | ||
python-version: "3.9" | ||
- name: Install package from TestPyPI | ||
run: | | ||
for i in {1..5}; do | ||
if python3 -m pip install --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple dspy-ai-test==${{ needs.extract-tag.outputs.version }}; then | ||
break | ||
else | ||
echo "Attempt $i failed. Waiting before retrying..." | ||
sleep 10 | ||
fi | ||
done | ||
- name: Install other dependencies | ||
run: | | ||
python3 -m pip install openai~=0.28.1 | ||
python3 -m pip install Jinja2 | ||
- name: Set up cache directory | ||
run: | | ||
mkdir -p cache | ||
echo "DSP_NOTEBOOK_CACHEDIR=$(pwd)/cache" >> $GITHUB_ENV | ||
- name: Run Python script | ||
run: | | ||
python3 tests/intro.py | ||
build-and-publish-pypi: | ||
needs: [extract-tag, build-and-publish-test-pypi, test-intro-script] | ||
runs-on: ubuntu-latest | ||
environment: | ||
name: pypi | ||
permissions: | ||
id-token: write # IMPORTANT: mandatory for trusted publishing | ||
steps: | ||
- uses: actions/checkout@master | ||
- name: Set up Python 3.9 | ||
uses: actions/setup-python@v3 | ||
with: | ||
python-version: "3.9" | ||
- name: Install dependencies | ||
run: python3 -m pip install setuptools wheel twine | ||
- name: Update version in setup.py | ||
run: sed -i "s/{{VERSION_PLACEHOLDER}}/${{ needs.extract-tag.outputs.version }}/g" | ||
setup.py | ||
- name: Update version in pyproject.toml | ||
run: sed -i "s/{{VERSION_PLACEHOLDER}}/${{ needs.extract-tag.outputs.version }}/g" | ||
pyproject.toml | ||
- name: Update package name in setup.py | ||
run: sed -i "s/{{PACKAGE_NAME_PLACEHOLDER}}/dspy-ai-hmoazam/g" #TODO: Change to actual | ||
setup.py | ||
- name: Update package name in pyproject.toml | ||
run: sed -i "s/{{PACKAGE_NAME_PLACEHOLDER}}/dspy-ai-hmoazam/g" #TODO: Change to actual | ||
pyproject.toml | ||
- name: Build a binary wheel | ||
run: python3 setup.py sdist bdist_wheel | ||
- name: Publish distribution 📦 to PyPI | ||
uses: pypa/gh-action-pypi-publish@release/v1 # This requires a trusted publisher to be setup in pypi/testpypi | ||
# create-release-github: # TODO | ||
# needs: needs: [build-and-publish-test-pypi, test-intro-notebook, build-and-publish-pypi] | ||
# Make sure to include release notes |