Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preliminary pypi-upload action #36

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 74 additions & 0 deletions pypi-upload/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
name: "Setup Python"

description: 'Set up a specific version of Python and add the command-line tools to the PATH.'

inputs:
artifacts:
description: "The artifacts to upload. Will be processed by bash so wildcards are allowed as in the default value `dist/*`."
required: false
default: "dist/*"
pypi_password:
description: "Password for uploading to PyPI. This should generally be from GitHub secrets and be an API token."
required: true
test_pypi_password:
description: "Password for uploading to PyPI. This should generally be from GitHub secrets and be an API token."
required: true
install_requirements:
description: "Generally requirements should be installed by the containing package so they can be pinned. If that is not being done then this action can create a virtual environment for itself."
required: false
default: "false"

runs:
using: "composite"
steps:
- name: Create virtual environment
if: ${{ fromJSON(inputs.install_requirements) }}
id: create_virtual_environment
shell: bash
run: |
TEMPORARY_DIRECTORY=$(mktemp --directory)
cd "${TEMPORARY_DIRECTORY}"
python -m venv venv
cd venv
echo ::set-output name=root::$(pwd)

# TODO: can, or should, this be referencing by path?
- uses: chia-network/actions/activate-venv@main
if: ${{ fromJSON(inputs.install_requirements) }}
with:
directories: ${{ toJSON([steps.create_virtual_environment.root]) }}

- name: Install requirements
if: ${{ fromJSON(inputs.install_requirements) }}
shell: bash
run: |
pip install twine

- name: Test for secrets access
id: check_secrets
shell: bash
run: |
unset HAS_SECRET
if [ -n "$SECRET" ]; then HAS_SECRET='true' ; fi
echo ::set-output name=HAS_SECRET::${HAS_SECRET}
env:
SECRET: "${{ inputs.test_pypi_password }}"

- name: Publish distribution to PyPI
if: startsWith(github.event.ref, 'refs/tags') && steps.check_secrets.outputs.HAS_SECRET
env:
TWINE_USERNAME: __token__
TWINE_NON_INTERACTIVE: 1
TWINE_PASSWORD: "${{ inputs.pypi_password }}"
run: twine upload --non-interactive --skip-existing --verbose '${{ inputs.artifacts }}'

- name: Publish distribution to Test PyPI
if: steps.check_secrets.outputs.HAS_SECRET
env:
TWINE_REPOSITORY_URL: https://test.pypi.org/legacy/
TWINE_USERNAME: __token__
TWINE_NON_INTERACTIVE: 1
TWINE_PASSWORD: "${{ inputs.test_pypi_password }}"
run: twine upload --non-interactive --skip-existing --verbose '${{ inputs.artifacts }}'

# TODO: deactivate the environment