From 5931173d6b73e902e0585a782f0819428b8c7781 Mon Sep 17 00:00:00 2001 From: David Gidwani Date: Thu, 25 Jan 2024 15:12:46 -0500 Subject: [PATCH] build: :package: improve release CI/CD --- .github/workflows/wheels.yml | 47 ++++++++++++++++++++++++++++++------ pyproject.toml | 4 +++ 2 files changed, 43 insertions(+), 8 deletions(-) diff --git a/.github/workflows/wheels.yml b/.github/workflows/wheels.yml index 07e0df5..f60ea55 100644 --- a/.github/workflows/wheels.yml +++ b/.github/workflows/wheels.yml @@ -1,4 +1,4 @@ -name: Build wheels and source distribution +name: Build on: push: branches: @@ -214,19 +214,34 @@ jobs: name: Publish package runs-on: ubuntu-latest concurrency: release - if: github.event_name == 'push' && github.ref == 'refs/heads/main' + if: github.event_name == 'push' && github.repository == 'darvid/python-hyperscan' needs: [build_wheels, build_sdist] permissions: id-token: write + pull-requests: write contents: write steps: - name: Checkout python-hyperscan uses: actions/checkout@v4 with: + ref: main fetch-depth: 0 + - uses: chainguard-dev/actions/setup-gitsign@main + + - name: Check if release needed + id: release + uses: python-semantic-release/python-semantic-release@v8.7.2 + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + root_options: "-vv --noop" + # python-semantic-release displays what it would have + # committed if commit is true and noop is set + commit: "true" + - name: Download artifacts uses: actions/download-artifact@v4 + if: steps.release.outputs.released == 'true' - name: Prepare dist run: | @@ -234,20 +249,36 @@ jobs: mv ./wheel-*/*.whl dist/ mv ./sdist/*.tar.gz dist/ + - name: Create release branch + if: steps.release.outputs.released == 'true' + run: | + # use the same default branch name that create-pull-request uses + git checkout -b create-pull-request/patch + git branch --set-origin-to=origin/create-pull-request/patch + - name: Semantic release - id: release - uses: python-semantic-release/python-semantic-release@v8.0.0 + uses: python-semantic-release/python-semantic-release@v8.7.2 + if: steps.release.outputs.released == 'true' with: github_token: ${{ secrets.GITHUB_TOKEN }} + root_options: "-vv" - - name: Publish package distributions to PyPI + - name: Create PR + uses: peter-evans/create-pull-request@v4.0.2 if: steps.release.outputs.released == 'true' - uses: pypa/gh-action-pypi-publish@release/v1 with: - skip-existing: true + title: "Release ${{ steps.release.outputs.version }}" - name: Publish package distributions to GitHub Releases - # if: steps.release.outputs.released == 'true' + if: steps.release.outputs.released == 'true' uses: python-semantic-release/upload-to-gh-release@main with: github_token: ${{ secrets.GITHUB_TOKEN }} + tag: ${{ steps.release.outputs.tag }} + + - name: Publish package distributions to PyPI + if: steps.release.outputs.released == 'true' + uses: pypa/gh-action-pypi-publish@release/v1 + with: + skip-existing: true + verbose: true diff --git a/pyproject.toml b/pyproject.toml index ba30fff..c9d7bbc 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -108,6 +108,10 @@ version_variables = [ "pdm_build.py:__version__", ] +[tool.semantic_release.branches.release] +match = 'release/v?[\\d\\.\\-]+' +prerelease = false + [tool.semantic_release.commit_parser_options] major_tags = [":boom:"] minor_tags = [