diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml deleted file mode 100644 index f1f2631..0000000 --- a/.github/workflows/publish.yml +++ /dev/null @@ -1,29 +0,0 @@ -name: publish - -on: - release: - types: [published] - -permissions: - contents: read - -jobs: - build-publish: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - - name: Set up Python - uses: actions/setup-python@v5 - with: - python-version: "3.12" - - - name: Build wheel/sdist - run: | - python -m pip install --upgrade pip build - python -m build - - - name: Publish to PyPI - uses: pypa/gh-action-pypi-publish@v1.10.3 - with: - password: ${{ secrets.PYPI_API_TOKEN }} diff --git a/.github/workflows/release-please.yml b/.github/workflows/release-please.yml index 0c41638..9224067 100644 --- a/.github/workflows/release-please.yml +++ b/.github/workflows/release-please.yml @@ -12,9 +12,66 @@ permissions: jobs: release-please: runs-on: ubuntu-latest + outputs: + release_created: ${{ steps.release.outputs.release_created }} + tag_name: ${{ steps.release.outputs.tag_name }} steps: - name: Run release-please + id: release uses: google-github-actions/release-please-action@v4 with: config-file: .github/release-please-config.json manifest-file: .release-please-manifest.json + + # Checkout code only if a release was created + - name: Checkout code + if: ${{ steps.release.outputs.release_created }} + uses: actions/checkout@v4 + + # Set up Python only if a release was created + - name: Set up Python + if: ${{ steps.release.outputs.release_created }} + uses: actions/setup-python@v5 + with: + python-version: "3.12" + + # Build the package only if a release was created + - name: Build wheel/sdist + if: ${{ steps.release.outputs.release_created }} + run: | + python -m pip install --upgrade pip build + python -m build + + # Publish to PyPI only if a release was created + - name: Publish to PyPI + if: ${{ steps.release.outputs.release_created }} + uses: pypa/gh-action-pypi-publish@v1.10.3 + with: + password: ${{ secrets.PYPI_API_TOKEN }} + + # Optional: Add a comment to the release with PyPI link + - name: Add PyPI link to release + if: ${{ steps.release.outputs.release_created }} + uses: actions/github-script@v7 + with: + script: | + const tagName = '${{ steps.release.outputs.tag_name }}'; + const version = tagName.replace(/^v/, ''); + const pypiUrl = `https://pypi.org/project/insdc-benchmarking-scripts/${version}/`; + + // Get the release by tag + const { data: release } = await github.rest.repos.getReleaseByTag({ + owner: context.repo.owner, + repo: context.repo.repo, + tag: tagName + }); + + // Update release body with PyPI link + const updatedBody = `${release.body}\n\n---\n\n📦 **PyPI Package:** ${pypiUrl}`; + + await github.rest.repos.updateRelease({ + owner: context.repo.owner, + repo: context.repo.repo, + release_id: release.id, + body: updatedBody + });