Skip to content

Build and Upload Python Package #37

Build and Upload Python Package

Build and Upload Python Package #37

# This workflow will upload a Python Package using Twine when a release is created
name: Build and Upload Python Package
on:
workflow_dispatch:
inputs:
version:
description: 'Version number'
required: true
description:
description: 'Description'
required: false
permissions:
contents: write
jobs:
deploy:
runs-on: ubuntu-latest
environment: build_and_publish
steps:
- uses: actions/checkout@v3
- name: Print version number
run: echo ${{ github.event.inputs.version }}
- name: set up Python
uses: actions/setup-python@v3
with:
python-version: '3.x'
- name: update version number
run: |
python ./.github/update_version.py setup.py ${{ github.event.inputs.version }}
python ./.github/update_version.py conda-recipe/meta.yaml ${{ github.event.inputs.version }}
python ./.github/update_version.py docs/source/conf.py ${{ github.event.inputs.version }}
- name: install yapf
run: |
python -m pip install --upgrade pip
pip install yapf
- name: format repository with yapf in google-python format
run: yapf -i -r --style ./.github/style.yapf .
- name: retrieve name and E-Mail configuration
run: |
git config --global user.name ${{ secrets.NAME_GITHUB }}
git config --global user.email ${{ secrets.MAIL_GITHUB }}
- name: check for changes
run: git status
- name: stage changed files
run: git add .
- name: commit changed files
run: git commit -m "updated version number" --allow-empty
- name: fetch
run: git fetch
- name: push code to main
run: git push
- name: Create Release
uses: actions/create-release@v1
id: create_release
with:
draft: false
prerelease: false
release_name: v${{ github.event.inputs.version }}
tag_name: v${{ github.event.inputs.version }}
body: ${{ github.event.inputs.description }}
env:
GITHUB_TOKEN: ${{ github.token }}
- name: Install setuptools, wheel and twine
run: |
pip install build setuptools wheel twine
- name: Clean PyPi build directories
run: rm -rf dist
- name: Build for PyPi
# env:
# TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
# TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
run: |
python setup.py sdist bdist_wheel
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.PYPI_API_TOKEN }}
# twine upload dist/*
- name: Install conda dependencies
run: conda install anaconda-client conda-build
- name: Clean Anaconda build directories
run: rm -rf conda-bld
- name: Build and publish on Anaconda
env:
ANCONDA_USERNAME: ${{ secrets.ANACONDA_USERNAME }}
ANACONDA_PASSWORD: ${{ secrets.ANACONDA_PASSWORD }}
run: |
conda build conda-recipe/. -c conda-forge --croot conda-bld
/usr/share/miniconda/bin/anaconda login --username $ANCONDA_USERNAME --password $ANACONDA_PASSWORD
/usr/share/miniconda/bin/anaconda upload -u cnapy conda-bld/noarch/straindesign*
- name: Final clean up
run: |
rm -rf dist
rm -rf conda-bld