diff --git a/README.md b/README.md index fd653b6..1be3c53 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/action.yml b/action.yml index 9609e41..b7deafb 100644 --- a/action.yml +++ b/action.yml @@ -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: @@ -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 }} @@ -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 }}