From cca2b22fcd5d1dc8703d8c9fe4816660a3f0f252 Mon Sep 17 00:00:00 2001 From: Timon Date: Sun, 6 Apr 2025 18:38:28 +0200 Subject: [PATCH 1/2] docs(github-actions): add packages-dir configuration in monorepo example --- docs/automatic-releases/github-actions.rst | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/docs/automatic-releases/github-actions.rst b/docs/automatic-releases/github-actions.rst index d67f6c590..77eef43a5 100644 --- a/docs/automatic-releases/github-actions.rst +++ b/docs/automatic-releases/github-actions.rst @@ -832,3 +832,10 @@ Publish Action. with: directory: ./project2 github_token: ${{ secrets.GITHUB_TOKEN }} + + # Adjust the packages-dir in the upload step + - name: Publish | Upload package to PyPI + uses: pypa/gh-action-pypi-publish@v1 + if: steps.release.outputs.released == 'true' + with: + packages-dir: project1/dist From 1b86587c940d4252d93f99a83374e81e85b723eb Mon Sep 17 00:00:00 2001 From: codejedi365 Date: Thu, 17 Apr 2025 23:34:54 -0600 Subject: [PATCH 2/2] docs(github-actions): expound on monorepo example to include publishing actions --- docs/automatic-releases/github-actions.rst | 102 ++++++++++++++++----- 1 file changed, 80 insertions(+), 22 deletions(-) diff --git a/docs/automatic-releases/github-actions.rst b/docs/automatic-releases/github-actions.rst index 77eef43a5..e8d0ce636 100644 --- a/docs/automatic-releases/github-actions.rst +++ b/docs/automatic-releases/github-actions.rst @@ -734,10 +734,6 @@ to the GitHub Release Assets as well. git_committer_name: "github-actions" git_committer_email: "actions@users.noreply.github.com" - - name: Publish | Upload package to PyPI - uses: pypa/gh-action-pypi-publish@v1 - if: steps.release.outputs.released == 'true' - - name: Publish | Upload to GitHub Release Assets uses: python-semantic-release/publish-action@v9.21.0 if: steps.release.outputs.released == 'true' @@ -745,6 +741,10 @@ to the GitHub Release Assets as well. github_token: ${{ secrets.GITHUB_TOKEN }} tag: ${{ steps.release.outputs.tag }} + - name: Publish | Upload package to PyPI + uses: pypa/gh-action-pypi-publish@SHA1_HASH # vX.X.X + if: steps.release.outputs.released == 'true' + .. important:: The `concurrency`_ directive is used on the job to prevent race conditions of more than one release job in the case if there are multiple pushes to ``main`` in a short period @@ -816,26 +816,84 @@ For multiple packages, you would need to run the action multiple times, to relea each project. The following example demonstrates how to release two projects in a monorepo. +Remember that for each release of each submodule you will then need to handle publishing +each package separately as well. This is dependent on the result of your build commands. +In the example below, we assume a simple ``build`` module command to build a ``sdist`` +and wheel artifacts into the submodule's ``dist`` directory. + The ``directory`` input directive is also available for the Python Semantic Release Publish Action. .. code:: yaml - - name: Release Project 1 - uses: python-semantic-release/python-semantic-release@v9.21.0 - with: - directory: ./project1 - github_token: ${{ secrets.GITHUB_TOKEN }} - - - name: Release Project 2 - uses: python-semantic-release/python-semantic-release@v9.21.0 - with: - directory: ./project2 - github_token: ${{ secrets.GITHUB_TOKEN }} - - # Adjust the packages-dir in the upload step - - name: Publish | Upload package to PyPI - uses: pypa/gh-action-pypi-publish@v1 - if: steps.release.outputs.released == 'true' - with: - packages-dir: project1/dist + jobs: + + release: + + env: + SUBMODULE_1_DIR: project1 + SUBMODULE_2_DIR: project2 + + steps: + + # ------------------------------------------------------------------- # + # Note the use of different IDs to distinguish which submodule was # + # identified to be released. The subsequent actions then reference # + # their specific release ID to determine if a release occurred. # + # ------------------------------------------------------------------- # + + - name: Release submodule 1 + id: release-submod-1 + uses: python-semantic-release/python-semantic-release@v9.21.0 + with: + directory: ${{ env.SUBMODULE_1_DIR }} + github_token: ${{ secrets.GITHUB_TOKEN }} + + - name: Release submodule 2 + id: release-submod-2 + uses: python-semantic-release/python-semantic-release@v9.21.0 + with: + directory: ${{ env.SUBMODULE_2_DIR }} + github_token: ${{ secrets.GITHUB_TOKEN }} + + # ------------------------------------------------------------------- # + # For each submodule, you will have to publish the package separately # + # and only attempt to publish if the release for that submodule was # + # deemed a release (and the release was successful). # + # ------------------------------------------------------------------- # + + - name: Publish | Upload package 1 to GitHub Release Assets + uses: python-semantic-release/publish-action@v9.21.0 + if: steps.release-submod-1.outputs.released == 'true' + with: + directory: ${{ env.SUBMODULE_1_DIR }} + github_token: ${{ secrets.GITHUB_TOKEN }} + tag: ${{ steps.release-submod-1.outputs.tag }} + + - name: Publish | Upload package 2 to GitHub Release Assets + uses: python-semantic-release/publish-action@v9.21.0 + if: steps.release-submod-2.outputs.released == 'true' + with: + directory: ${{ env.SUBMODULE_2_DIR }} + github_token: ${{ secrets.GITHUB_TOKEN }} + tag: ${{ steps.release-submod-2.outputs.tag }} + + # ------------------------------------------------------------------- # + # Python Semantic Release is not responsible for publishing your # + # python artifacts to PyPI. Use the official PyPA publish action # + # instead. The following steps are an example but is not guaranteed # + # to work as the action is not maintained by the # + # python-semantic-release team. # + # ------------------------------------------------------------------- # + + - name: Publish | Upload package 1 to PyPI + uses: pypa/gh-action-pypi-publish@SHA1_HASH # vX.X.X + if: steps.release-submod-1.outputs.released == 'true' + with: + packages-dir: ${{ format('{}/dist', env.SUBMODULE_1_DIR) }} + + - name: Publish | Upload package 2 to PyPI + uses: pypa/gh-action-pypi-publish@SHA1_HASH # vX.X.X + if: steps.release-submod-2.outputs.released == 'true' + with: + packages-dir: ${{ format('{}/dist', env.SUBMODULE_2_DIR) }}