Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: add release please workflow #486

Merged
merged 3 commits into from
Aug 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 0 additions & 35 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,38 +30,3 @@ jobs:
run: make run_tests
- name: Upload Coverage
uses: codecov/[email protected]

publish:
needs: test
if: ${{ !startsWith(github.event.head_commit.message, 'bump') && !startsWith(github.event.head_commit.message, 'chore') && github.ref == 'refs/heads/master' && contains(fromJSON('["push", "workflow_dispatch"]'), github.event_name) && github.repository_owner == 'supabase' }}
runs-on: ubuntu-latest
name: "Bump version, create changelog and publish"
environment:
name: pypi
url: https://pypi.org/p/postgrest
permissions:
id-token: write # IMPORTANT: this permission is mandatory for trusted publishing
contents: write # needed for github actions bot to write to repo
steps:
- name: Clone Repository
uses: actions/checkout@v4
with:
ref: ${{ github.ref }}
fetch-depth: 0
token: ${{ secrets.SILENTWORKS_PAT }}
- name: Python Semantic Release
id: release
uses: python-semantic-release/[email protected]
with:
github_token: ${{ secrets.GITHUB_TOKEN }}

- name: Publish package distributions to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
# NOTE: DO NOT wrap the conditional in ${{ }} as it will always evaluate to true.
# See https://github.com/actions/runner/issues/1173
if: steps.release.outputs.released == 'true'

- name: Python Semantic Release
uses: python-semantic-release/upload-to-gh-release@main
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
97 changes: 97 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
name: Release

on:
push:
branches:
- master
workflow_dispatch:

permissions:
id-token: write # IMPORTANT: this permission is mandatory for trusted publishing
contents: write # needed for github actions bot to write to repo
pull-requests: write

jobs:
publish:
runs-on: ubuntu-latest
name: "Bump version, create changelog and publish"
environment:
name: pypi
url: https://pypi.org/p/postgrest
steps:
- name: Set up Python 3.11
uses: actions/setup-python@v5
with:
python-version: 3.11

- name: Set up Poetry
uses: abatilo/actions-poetry@v3
with:
poetry-version: 1.8.3

- uses: googleapis/release-please-action@v4
id: release
with:
target-branch: ${{ github.ref_name }}

- uses: actions/checkout@v4
if: ${{ steps.release.outputs.release_created == 'true' || steps.release.outputs.prs_created == 'true' }}
with:
fetch-depth: 0

- if: ${{ steps.release.outputs }}
id: versions
run: |
set -ex

RELEASE_CANDIDATE=true
NOT_RELEASE_CANDIDATE='${{ steps.release.outputs.release_created }}'
if [ "$NOT_RELEASE_CANDIDATE" == "true" ]
then
RELEASE_CANDIDATE=false
fi

MAIN_RELEASE_VERSION=x
RELEASE_VERSION=y

if [ "$RELEASE_CANDIDATE" == "true" ]
then
# Release please doesn't tell you the candidate version when it
# creates the PR, so we have to take it from the title.
MAIN_RELEASE_VERSION=$(node -e "console.log('${{ steps.release.outputs.pr && fromJSON(steps.release.outputs.pr).title }}'.split(' ').reverse().find(x => x.match(/[0-9]+[.][0-9]+[.][0-9]+/)))")

# Use git describe tags to identify the number of commits the branch
# is ahead of the most recent non-release-candidate tag, which is
# part of the rc.<commits> value.
RELEASE_VERSION=$MAIN_RELEASE_VERSION-rc.$(node -e "console.log('$(git describe --tags --exclude rc*)'.split('-')[1])")

# release-please only ignores releases that have a form like [A-Z0-9]<version>, so prefixing with rc<version>
RELEASE_NAME="rc$RELEASE_VERSION"
else
MAIN_RELEASE_VERSION=${{ steps.release.outputs.major }}.${{ steps.release.outputs.minor }}.${{ steps.release.outputs.patch }}
RELEASE_VERSION="$MAIN_RELEASE_VERSION"
RELEASE_NAME="v$RELEASE_VERSION"
fi

echo "MAIN_RELEASE_VERSION=${MAIN_RELEASE_VERSION}" >> "${GITHUB_ENV}"
echo "RELEASE_VERSION=${RELEASE_VERSION}" >> "${GITHUB_ENV}"
echo "RELEASE_CANDIDATE=${RELEASE_CANDIDATE}" >> "${GITHUB_ENV}"
echo "RELEASE_NAME=${RELEASE_NAME}" >> "${GITHUB_ENV}"

echo "MAIN_RELEASE_VERSION=${MAIN_RELEASE_VERSION}" >> "${GITHUB_OUTPUT}"
echo "RELEASE_VERSION=${RELEASE_VERSION}" >> "${GITHUB_OUTPUT}"
echo "RELEASE_CANDIDATE=${RELEASE_CANDIDATE}" >> "${GITHUB_OUTPUT}"
echo "RELEASE_NAME=${RELEASE_NAME}" >> "${GITHUB_OUTPUT}"

- name: Install dependencies
run: poetry install

- name: Build package distribution directory
id: build_dist
run: poetry build

- name: Publish package distributions to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
# NOTE: DO NOT wrap the conditional in ${{ }} as it will always evaluate to true.
# See https://github.com/actions/runner/issues/1173
if: ${{ steps.release.outputs.release_created == 'true' || steps.release.outputs.prs_created == 'true' }}
3 changes: 3 additions & 0 deletions .release-please-manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
".": "0.16.9"
}
3 changes: 1 addition & 2 deletions postgrest/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
from __future__ import annotations

__version__ = "0.16.9"

from httpx import Timeout

from ._async.client import AsyncPostgrestClient
Expand Down Expand Up @@ -29,3 +27,4 @@
from .deprecated_client import Client, PostgrestClient
from .deprecated_get_request_builder import GetRequestBuilder
from .exceptions import APIError
from .version import __version__
2 changes: 1 addition & 1 deletion postgrest/_async/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
from deprecation import deprecated
from httpx import Headers, QueryParams, Timeout

from .. import __version__
from ..base_client import BasePostgrestClient
from ..constants import (
DEFAULT_POSTGREST_CLIENT_HEADERS,
DEFAULT_POSTGREST_CLIENT_TIMEOUT,
)
from ..types import CountMethod
from ..utils import AsyncClient
from ..version import __version__
from .request_builder import AsyncRequestBuilder, AsyncRPCFilterRequestBuilder

_TableT = Dict[str, Any]
Expand Down
2 changes: 1 addition & 1 deletion postgrest/_sync/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
from deprecation import deprecated
from httpx import Headers, QueryParams, Timeout

from .. import __version__
from ..base_client import BasePostgrestClient
from ..constants import (
DEFAULT_POSTGREST_CLIENT_HEADERS,
DEFAULT_POSTGREST_CLIENT_TIMEOUT,
)
from ..types import CountMethod
from ..utils import SyncClient
from ..version import __version__
from .request_builder import SyncRequestBuilder, SyncRPCFilterRequestBuilder

_TableT = Dict[str, Any]
Expand Down
2 changes: 1 addition & 1 deletion postgrest/deprecated_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

from deprecation import deprecated

from . import __version__
from ._async.client import AsyncPostgrestClient
from .version import __version__


class Client(AsyncPostgrestClient):
Expand Down
2 changes: 1 addition & 1 deletion postgrest/deprecated_get_request_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

from deprecation import deprecated

from . import __version__
from ._async.request_builder import AsyncSelectRequestBuilder
from .version import __version__


class GetRequestBuilder(AsyncSelectRequestBuilder):
Expand Down
1 change: 1 addition & 0 deletions postgrest/version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__version__ = "0.16.9" # {x-release-please-version}
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "postgrest"
version = "0.16.9"
version = "0.16.9" # {x-release-please-version}
description = "PostgREST client for Python. This library provides an ORM interface to PostgREST."
authors = ["Lương Quang Mạnh <[email protected]>", "Joel Lee <[email protected]>", "Anand", "Oliver Rice", "Andrew Smith <[email protected]>"]
homepage = "https://github.com/supabase-community/postgrest-py"
Expand Down
9 changes: 9 additions & 0 deletions release-please-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"last-release-sha": "9c1268e8011cf141f85cf2bbac682f86acfd06fa",
"packages": {
".": {
"changelog-path": "CHANGELOG.md",
"release-type": "python"
}
}
}
Loading