diff --git a/template/{% if enable_github_action %}.github{% endif%}/workflows/release.yaml.jinja b/template/{% if enable_github_action %}.github{% endif%}/workflows/release.yaml.jinja index 4d298ac..6fa65a9 100644 --- a/template/{% if enable_github_action %}.github{% endif%}/workflows/release.yaml.jinja +++ b/template/{% if enable_github_action %}.github{% endif%}/workflows/release.yaml.jinja @@ -16,6 +16,10 @@ jobs: permissions: contents: write + outputs: + released: {% raw %}${{ steps.release.outputs.released }}{% endraw %} + tag: {% raw %}${{ steps.release.outputs.tag }}{% endraw %} + steps: {# Note: We checkout the repository at the branch that triggered the workflow @@ -41,3 +45,36 @@ jobs: github_token: {% raw %}${{ secrets.GITHUB_TOKEN }}{% endraw %} git_committer_name: "github-actions" git_committer_email: "actions@users.noreply.github.com" + +{% if publish_to_pypi %} + publish: + needs: release + if: needs.release.outputs.released == 'true' + runs-on: ubuntu-latest + + permissions: + contents: write + {# IMPORTANT: this permission is mandatory for Trusted Publishing #} + id-token: write + + environment: + name: pypi + url: https://pypi.org/p/{{ project_name }} + + steps: + - name: Check out at new tag + uses: actions/checkout@v4 + with: + ref: {% raw %}${{ needs.release.outputs.tag }}{% endraw %} + + - name: Set up the environment + uses: ./.github/actions/setup-python-env + + - name: Build Package + run: make build + + - name: Publish package distributions to PyPI + uses: pypa/gh-action-pypi-publish@v1.13.0 + with: + packages-dir: dist +{% endif %} diff --git a/template/{% if enable_github_action %}.github{% endif%}/workflows/{% if publish_to_pypi %}publish.yaml{% endif %}.jinja b/template/{% if enable_github_action %}.github{% endif%}/workflows/{% if publish_to_pypi %}publish.yaml{% endif %}.jinja deleted file mode 100644 index bf8b826..0000000 --- a/template/{% if enable_github_action %}.github{% endif%}/workflows/{% if publish_to_pypi %}publish.yaml{% endif %}.jinja +++ /dev/null @@ -1,38 +0,0 @@ -name: publish - -on: - release: - types: [published] - -permissions: - contents: read - -jobs: - publish: - runs-on: ubuntu-latest - - permissions: - contents: write - {# IMPORTANT: this permission is mandatory for Trusted Publishing #} - id-token: write - - environment: - name: pypi - url: https://pypi.org/p/{{ project_name }} - - steps: - - name: Check out at new tag - uses: actions/checkout@v4 - with: - ref: {% raw %}${{ github.event.release.tag_name }}{% endraw %} - - - name: Set up the environment - uses: ./.github/actions/setup-python-env - - - name: Build Package - run: make build - - - name: Publish package distributions to PyPI - uses: pypa/gh-action-pypi-publish@v1.13.0 - with: - packages-dir: dist