Skip to content

Commit

Permalink
Add PyPI upload actions (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
brynpickering authored Sep 26, 2023
1 parent 86086c2 commit 6ade446
Show file tree
Hide file tree
Showing 2 changed files with 136 additions and 0 deletions.
74 changes: 74 additions & 0 deletions .github/workflows/pip-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
name: Reusable conda package builder

on:
workflow_call:
inputs:
package_name:
description: "Name of Python package name being built"
required: true
type: string
version:
description: "Version to be packaged and uploaded"
required: false
type: string
default: ${{ github.ref_name }}
secrets:
TEST_PYPI_API_TOKEN:
required: true

defaults:
run:
shell: bash -l {0}

jobs:
pip-build:
runs-on: ubuntu-latest
steps:
- name: check if TEST_PYPI_API_TOKEN exists
env:
# cannot use secrets directly in conditionals
# see https://docs.github.com/en/actions/security-guides/using-secrets-in-github-actions#using-secrets-in-a-workflow
test_pypi_token: ${{ secrets.TEST_PYPI_API_TOKEN }}
if: env.test_pypi_token == ''
run: |
echo "the secret \"TEST_PYPI_API_TOKEN\" is not available, so the pypi package cannot be uploaded to the test index site."
echo "Please go to \"settings \> secrets \> actions\" to create it before trying to build the pip package."
exit 1
- uses: actions/checkout@v3
- uses: mamba-org/setup-micromamba@v1
with:
micromamba-version: latest
environment-name: pipbuild
create-args: >-
python=3.11
pip
build
post-cleanup: all
cache-environment: true

- name: Build package
run: python -m build

- name: Publish distribution 📦 to TestPyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.TEST_PYPI_API_TOKEN }}
repository-url: https://test.pypi.org/legacy/

- name: Get version without the v
run: |
TAG=${{ inputs.version }}
echo "VERSION=${TAG#v}" >> $GITHUB_ENV
- name: try installing from TestPyPI
run: |
cd ${{ runner.temp }}
pip install -i https://test.pypi.org/simple/ --no-deps ${{ inputs.package_name }}==${{ env.VERSION }}
- name: Create built package artifact ready for upload on release
uses: actions/upload-artifact@v3
with:
name: pip-build-${{ inputs.package_name }}-${{ inputs.version }}
path: dist/*
retention-days: 7
62 changes: 62 additions & 0 deletions .github/workflows/pip-upload.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
on:
workflow_call:
inputs:
package_name:
description: "Name of Python package name being uploaded"
required: true
type: string
build_workflow:
description: "Name of workflow file used to build the package initially, if different from current workflow"
required: false
type: string
default: ""
version:
description: "Version to be packaged and uploaded"
required: false
type: string
default: ${{ github.ref_name }}
secrets:
PYPI_API_TOKEN:
required: true

defaults:
run:
shell: bash -l {0}

jobs:
pip-publish:
runs-on: ubuntu-latest
env:
PACKAGENAME: "pip-build-${{ inputs.package_name }}-${{ inputs.version }}"

steps:
- name: check if PYPI_API_TOKEN exists
env:
# cannot use secrets directly in conditionals
# see https://docs.github.com/en/actions/security-guides/using-secrets-in-github-actions#using-secrets-in-a-workflow
pypi_token: ${{ secrets.PYPI_API_TOKEN }}
if: env.pypi_token == ''
run: |
echo "the secret \"PYPI_API_TOKEN\" is not available, so the pypi package cannot be uploaded to the test index site."
echo "Please go to \"settings \> secrets \> actions\" to create it before trying to build the pip package."
exit 1
- name: Download built package from another workflow
if: inputs.build_workflow != ''
uses: dawidd6/action-download-artifact@v2
with:
name: ${{ env.PACKAGENAME }}
workflow: ${{ inputs.build_workflow }}
path: dist/

- name: Download built package from same workflow
if: inputs.build_workflow == ''
uses: actions/download-artifact@v3
with:
name: ${{ env.PACKAGENAME }}
path: dist/

- name: Publish distribution 📦 to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.PYPI_API_TOKEN }}

0 comments on commit 6ade446

Please sign in to comment.