Created
August 14, 2021 09:58
-
-
Save moritzkoerber/630554b36d3670c54fe98f8bc7262bee to your computer and use it in GitHub Desktop.
Manual PyPi Release GitHub Actions Workflow
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: Manual PyPi Release | |
on: | |
workflow_dispatch: | |
inputs: | |
package_repository: | |
description: '"testpypi" or "pypi"' | |
required: true | |
tag: | |
required: true | |
env: | |
PYTHON_VERSION: '3.8.2' | |
jobs: | |
testing: | |
name: Test installed package | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout source | |
uses: actions/checkout@v2 | |
with: | |
fetch-depth: 0 | |
- name: Setup Python | |
uses: actions/setup-python@v2 | |
with: | |
python-version: ${{ env.PYTHON_VERSION }} | |
- name: Setup caches | |
uses: actions/cache@v2 | |
with: | |
path: | | |
~/.local/share/virtualenvs | |
~/.cache/pre-commit | |
~/.cache/pip | |
key: ${{ runner.os }}-${{ env.PYTHON_VERSION }}-venv-${{ hashFiles('**/Pipfile*') }}-${{ hashFiles('**/.pre-commit-config.yaml*') }} | |
restore-keys: | | |
${{ runner.os }}-${{ env.PYTHON_VERSION }}-venv | |
- name: Install environment | |
run: | | |
pip install pipenv | |
pipenv install --dev --deploy | |
- name: Test installed package | |
run: | | |
pipenv run pip install . | |
pipenv run pytest | |
release: | |
name: Create release | |
runs-on: ubuntu-latest | |
needs: testing | |
steps: | |
- name: Create GitHub release | |
uses: actions/create-release@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
tag_name: ${{ github.event.inputs.tag }} | |
release_name: ${{ github.event.inputs.tag }} | |
build: | |
name: Build package | |
runs-on: ubuntu-latest | |
needs: release | |
steps: | |
- name: Checkout source | |
uses: actions/checkout@v2 | |
with: | |
fetch-depth: 0 | |
- name: Install pypa/build | |
run: | | |
pip install build | |
python -m build | |
- uses: actions/upload-artifact@v2 | |
with: | |
name: package | |
path: dist/ | |
publish: | |
name: Publish on TestPyPi | |
runs-on: ubuntu-latest | |
needs: build | |
steps: | |
- name: Checkout source | |
uses: actions/checkout@v2 | |
with: | |
fetch-depth: 0 | |
- name: Download built artifact | |
uses: actions/download-artifact@v2 | |
with: | |
name: package | |
path: dist | |
- name: Publish on TestPyPi | |
if: ${{ github.event.inputs.package_repository == 'testpypi' }} | |
uses: pypa/gh-action-pypi-publish@release/v1 | |
with: | |
password: ${{ secrets.TEST_PYPI_API_TOKEN }} | |
repository_url: https://test.pypi.org/legacy/ | |
- name: Publish on PyPi | |
if: ${{ github.event.inputs.package_repository == 'pypi' }} | |
uses: pypa/gh-action-pypi-publish@release/v1 | |
with: | |
password: ${{ secrets.PYPI_API_TOKEN }} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment