Skip to content

Workflow file for this run

name: Publish Python distributions to PyPI
on:
release:
types: [published]
env:
PACKAGE_NAME: exchange_calendars_extensions_api
MODULE_NAME: exchange_calendars_extensions.api
jobs:
build-and-publish:
name: Build and publish Python distributions to TestPyPI and PyPI.
runs-on: ubuntu-latest
permissions:
id-token: write
steps:
- uses: actions/checkout@v3
- name: Install poetry.
run: pipx install poetry
- name: Set up Python.
uses: actions/setup-python@v4
with:
python-version: "3.11"
cache: 'poetry'
- name: Determine version number.
run: |
export VERSION=${{ github.ref_name }}
echo "Version is $VERSION."
echo "VERSION=$VERSION" >> $GITHUB_ENV
- name: Set poetry package version.
run: poetry version ${{ env.VERSION }}
- name: Determine path to version.py from module name.
run: |
export VERSION_PATH=$(echo ${{ env.MODULE_NAME }} | sed 's/\./\//g')/version.py
echo "VERSION_PATH is $VERSION_PATH."
echo "VERSION_PATH=$VERSION_PATH" >> $GITHUB_ENV
- name: Generate version.py
run: |
echo "version = '${{ env.VERSION }}'" > ${{ env.VERSION_PATH }}
- name: Generate requirements.txt.
run: poetry export -f requirements.txt --without-hashes > requirements.txt
- name: Build package with poetry.
run: poetry build
- name: Publish package to Test PyPI.
uses: pypa/gh-action-pypi-publish@release/v1
with:
repository-url: https://test.pypi.org/legacy/
skip-existing: true
- name: Install from testpypi and import.
run: |
i=0
n=60
exists=0
while [ $i -lt $n ] && [ $exists -eq 0 ]; do
if curl -s https://test.pypi.org/pypi/${{ env.PACKAGE_NAME }}/json | jq -e '.releases | has("${{ env.VERSION }}")' &> /dev/null; then
exists=1
else
((i++))
echo "$i/$n Waiting for package to appear in test index, sleeping 5s."
sleep 5s
fi
done
pip install --no-cache-dir --index-url https://test.pypi.org/simple ${{ env.PACKAGE_NAME }}==${{ env.VERSION }} --no-deps
pip install -r requirements.txt
python -c 'import ${{ env.MODULE_NAME }};print(${{ env.MODULE_NAME }}.__version__)'
- name: Clean pip
run: |
pip uninstall -y ${{ env.PACKAGE_NAME }}
pip cache purge
- name: Publish package to PyPI.
uses: pypa/gh-action-pypi-publish@release/v1
- name: Install and import.
run: |
i=0
n=60
exists=0
while [ $i -lt $n ] && [ $exists -eq 0 ]; do
if curl -s https://pypi.org/pypi/${{ env.PACKAGE_NAME }}/json | jq -e '.releases | has("${{ env.VERSION }}")' &> /dev/null; then
exists=1
else
((i++))
echo "$i/$n Waiting for package to appear in test index, sleeping 5s."
sleep 5s
fi
done
pip install --no-cache-dir --index-url https://pypi.org/simple ${{ env.PACKAGE_NAME }}==${{ env.VERSION }}
python -c 'import ${{ env.MODULE_NAME }};print(${{ env.MODULE_NAME }}.__version__)'