Add Python code doc site, programmatically grab package name #23
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: CI Pipeline | |
on: | |
push: | |
branches: | |
- main | |
tags: | |
- '*' | |
pull_request: | |
jobs: | |
test: | |
name: Run Tests | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
python-version: ["3.9", "3.10", "3.11", "3.12"] | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Set up Python | |
uses: actions/setup-python@v5 | |
with: | |
python-version: ${{ matrix.python-version }} | |
- name: Install Poetry | |
run: pip install poetry | |
- name: Install dependencies | |
run: poetry install --with dev | |
- name: Run Tests | |
run: poetry run pytest | |
publish-to-testpypi: | |
name: Publish to Test PyPI | |
if: github.ref == 'refs/heads/main' | |
needs: test | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Set up Python | |
uses: actions/setup-python@v5 | |
with: | |
python-version: "3.11" | |
- name: Install Poetry | |
run: pip install poetry | |
- name: Configure Test PyPI | |
run: poetry config repositories.testpypi https://test.pypi.org/legacy/ | |
- name: Set Test PyPI Token | |
run: poetry config pypi-token.testpypi ${{ secrets.TEST_PYPI_API_TOKEN }} | |
- name: Get current version | |
id: get-version | |
run: | | |
poetry build | |
VERSION=$(poetry version -s) | |
echo "VERSION=${VERSION}" >> $GITHUB_ENV | |
- name: Check version on Test PyPI | |
id: version-check | |
run: | | |
PACKAGE_NAME=$(poetry version | awk '{print $1}') | |
RESPONSE=$(curl -s https://test.pypi.org/pypi/${PACKAGE_NAME}/json || echo "error") | |
if [ "$RESPONSE" != "error" ] && echo "$RESPONSE" | jq -r '.releases | keys' | grep -q "\"${VERSION}\""; then | |
echo "Version ${VERSION} already exists on Test PyPI." | |
echo "skip=true" >> $GITHUB_ENV | |
else | |
echo "Version ${VERSION} does not exist on Test PyPI. Proceeding with publish." | |
echo "skip=false" >> $GITHUB_ENV | |
fi | |
- name: Publish to Test PyPI | |
if: env.skip != 'true' | |
run: | | |
poetry install | |
poetry build | |
poetry publish --repository testpypi | |
publish-to-pypi: | |
name: Publish to PyPI | |
if: startsWith(github.ref, 'refs/tags/') | |
needs: test | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Set up Python | |
uses: actions/setup-python@v5 | |
with: | |
python-version: "3.11" | |
- name: Install Poetry | |
run: pip install poetry | |
- name: Configure PyPI | |
run: poetry config repositories.pypi https://upload.pypi.org/legacy/ | |
- name: Set PyPI Token | |
run: poetry config pypi-token.pypi ${{ secrets.PYPI_API_TOKEN }} | |
- name: Get current version | |
id: get-version | |
run: | | |
VERSION=$(poetry version -s) | |
echo "VERSION=${VERSION}" >> $GITHUB_ENV | |
- name: Check version on PyPI | |
id: version-check | |
run: | | |
PACKAGE_NAME=$(poetry version | awk '{print $1}') | |
RESPONSE=$(curl -s https://pypi.org/pypi/${PACKAGE_NAME}/json || echo "error") | |
if [ "$RESPONSE" != "error" ] && echo "$RESPONSE" | jq -r '.releases | keys' | grep -q "\"${VERSION}\""; then | |
echo "Version ${VERSION} already exists on PyPI." | |
echo "skip=true" >> $GITHUB_ENV | |
else | |
echo "Version ${VERSION} does not exist on PyPI. Proceeding with publish." | |
echo "skip=false" >> $GITHUB_ENV | |
fi | |
- name: Publish to PyPI | |
if: env.skip != 'true' | |
run: | | |
poetry install | |
poetry build | |
poetry publish --repository pypi |