Fixing up GH package build #6
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: Generate and publish Python client package for COCT SR API | |
on: | |
push: | |
branches: | |
- main | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v2 | |
- name: Install dependencies | |
run: | | |
sudo apt-get update | |
sudo apt-get install -y python3 python3-pip | |
pip3 install twine | |
- name: Generate Python client package | |
run: | | |
docker run --rm -v "${PWD}:/local" \ | |
openapitools/openapi-generator-clisha256:a1460b4c11dc8c883cd34b2dbfe19d08954aea2f533cf238ff24a1fd71462aa4 \ | |
generate \ | |
-i /local/city-sr-api.json \ | |
-g python \ | |
-o /local/dist/python \ | |
--additional-properties=packageName="coct_sr_api_client" \ | |
--additional-properties=packageVersion=0.2.0 | |
- name: Check if package version exists on PyPI | |
env: | |
TWINE_USERNAME: __token__ | |
TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }} | |
run: | | |
package_version=$(python3 setup.py --version) | |
curl -sSL https://pypi.org/pypi/my_package_name/json | grep -q "\"$package_version\"" && exit 1 || exit 0 | |
continue-on-error: true | |
id: check_package_version | |
- name: Publish to PyPI | |
env: | |
TWINE_USERNAME: __token__ | |
TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }} | |
run: | | |
if [ ${{ steps.check_package_version.outcome }} == "success" ]; then | |
sudo chown -R $USER:$USER dist/python | |
cd dist/python | |
python3 setup.py sdist bdist_wheel | |
twine upload dist/* | |
else | |
echo "Package version already exists on PyPI, skipping upload" | |
fi |