Skip to content

Commit

Permalink
More doc
Browse files Browse the repository at this point in the history
  • Loading branch information
Conchylicultor committed May 16, 2022
1 parent 875ab2e commit 6b2cf16
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 17 deletions.
23 changes: 17 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,36 +1,47 @@
# pypi-auto-publish

Build & publish to PyPI everytime the package version is increased.
Trigger a PyPI and GitHub release everytime the package version is increased.

This support any [PEP 518](https://www.python.org/dev/peps/pep-0518/) compliant projects (flit, setuptools, poetry,...).

This action:

* Auto-detect when the package version is increased (in the `pyproject.toml`, `module.__version__` when using flit, `setup`,...)
* Trigger a PyPI release of the project
* Create the associated tag (e.g. `v1.0.0`) and GitHub release.

Example of usage:

```yaml
name: Auto-publish

# Allow to trigger the workflow manually (e.g. when deps changes)
on: [push, workflow_dispatch]

jobs:
# Auto-publish when version is increased
publish-job:
# Only try to publish if branch is `main`
# Only publish on `main` branch
if: github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
timeout-minutes: 30
permissions: # Don't forget permissions
contents: write

steps:
- uses: etils-actions/pypi-auto-publish@main
with:
pypi-token: ${{ secrets.PYPI_API_TOKEN }}
gh-token: ${{ secrets.GITHUB_TOKEN }}
```
You can also chain this job with your unittests to only trigger release if tests passes.
You can also chain this job with your unittests to only trigger release if tests passes (`needs: my-test-job`).

## Inputs

* `pypi-token`: Required: the PyPI token to publish the package
Authorization tokens:

* `pypi-token`: The PyPI token to publish the package. If missing, PyPI release is skipped.
* `gh-token`: GitHub action token. If missing, GitHub release is skipped.
* `release-body` (Optional): GitHub release text
* `pkg-name` (Optional): Package name (auto-detected).

## Outputs
Expand Down
27 changes: 16 additions & 11 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@ branding:
color: orange

inputs:
pkg-name:
description: 'Name of the PyPI package (optional).'
required: false
release:
description: 'Whether to trigger a GitHub release.'
required: false
pypi-token:
description: 'Token of the PyPI account publishing the project.'
required: true
description: 'Token of the PyPI account publishing the project. If missing, PyPI release is skipped.'
required: false
gh-token:
description: 'Github token. Required to trigger the release.'
description: 'Github action token. If missing, GitHub release is skipped.'
required: false
release-body:
description: 'Github action token. If missing, GitHub release is skipped.'
required: false
pkg-name:
description: 'Name of the PyPI package (optional).'
required: false

runs:
Expand Down Expand Up @@ -51,7 +51,9 @@ runs:
shell: bash
# Publish the package (if local `__version__` < pip version)
- if: steps.compare-version.outputs.should-release == 'true'
- if: |
inputs.pypi-token
&& steps.compare-version.outputs.should-release == 'true'
uses: etils-actions/pypi-build-publish@v1
with:
pypi-token: ${{ inputs.pypi-token }}
Expand All @@ -60,9 +62,12 @@ runs:
# * Auto set the body
# * Skip release if `inputs.release=False`
# token: ${{ secrets.GITHUB_TOKEN }}
- if: steps.compare-version.outputs.should-release == 'true'
- if: |
inputs.release-body
&& steps.compare-version.outputs.should-release == 'true'
uses: ncipollo/release-action@v1
with:
commit: ${{ github.sha }}
tag: v${{ steps.compare-version.outputs.version }}
token: ${{ inputs.gh-token }}
body: ${{ inputs.release-body }}

0 comments on commit 6b2cf16

Please sign in to comment.