PyPi Release workflow #20
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 PyPi | |
on: | |
push: | |
branches: | |
- v3-competition | |
pull_request: | |
branches: | |
- v3-competition | |
jobs: | |
build-and-test: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v2 | |
- name: Set up Python | |
uses: actions/setup-python@v2 | |
with: | |
python-version: 3.8 | |
- name: Install dependencies | |
run: | | |
python -m pip install --upgrade pip | |
pip install -r requirements.txt | |
deploy-testpypi: | |
needs: build-and-test | |
if: github.event_name == 'pull_request' | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v2 | |
- name: Set up Python | |
uses: actions/setup-python@v2 | |
with: | |
python-version: 3.8 | |
- name: Install dependencies | |
run: | | |
python -m pip install --upgrade pip | |
pip install -r requirements.txt | |
pip install wheel twine bump2version | |
- name: Build | |
run: | | |
cd src | |
python setup.py sdist bdist_wheel | |
- name: Publish to Test PyPi with unique version | |
run: | | |
cd src | |
GIT_HASH=$(echo "${{ github.sha }}" | cut -c1-7) | |
CURRENT_VERSION=$(python -c "exec(open('setup.py').read()); print(version)") | |
NEW_VERSION="${CURRENT_VERSION}dev${GIT_HASH}" | |
sed -i "s/version='${CURRENT_VERSION}'/version='${NEW_VERSION}'/" setup.py | |
python setup.py sdist bdist_wheel | |
twine upload --repository-url https://test.pypi.org/legacy/ dist/* --verbose --skip-existing | |
env: | |
TWINE_USERNAME: ${{ secrets.TEST_PYPI_USERNAME }} | |
TWINE_PASSWORD: ${{ secrets.TEST_PYPI_PASSWORD }} | |
deploy: | |
needs: build-and-test | |
if: github.event_name == 'push' && github.ref == 'refs/heads/v3-competition' | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v2 | |
- name: Set up Python | |
uses: actions/setup-python@v2 | |
with: | |
python-version: 3.8 | |
- name: Install dependencies | |
run: | | |
python -m pip install --upgrade pip | |
pip install -r requirements.txt | |
pip install wheel twine | |
- name: Bump version | |
id: bump_version | |
run: | | |
bump2version patch --config-file .bumpversion.cfg | |
echo "::set-output name=new_version::$(cat .bumpversion.cfg | grep current_version | sed 's/^current_version = //')" | |
- name: Build and publish | |
run: | | |
cd src | |
python setup.py sdist bdist_wheel | |
twine upload dist/* --skip-existing | |
env: | |
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }} | |
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }} |