Skip to content

Commit 434cf32

Browse files
authored
ci: add release please workflow (#486)
1 parent ff9bfd8 commit 434cf32

11 files changed

+116
-42
lines changed

.github/workflows/ci.yml

-35
Original file line numberDiff line numberDiff line change
@@ -30,38 +30,3 @@ jobs:
3030
run: make run_tests
3131
- name: Upload Coverage
3232
uses: codecov/[email protected]
33-
34-
publish:
35-
needs: test
36-
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' }}
37-
runs-on: ubuntu-latest
38-
name: "Bump version, create changelog and publish"
39-
environment:
40-
name: pypi
41-
url: https://pypi.org/p/postgrest
42-
permissions:
43-
id-token: write # IMPORTANT: this permission is mandatory for trusted publishing
44-
contents: write # needed for github actions bot to write to repo
45-
steps:
46-
- name: Clone Repository
47-
uses: actions/checkout@v4
48-
with:
49-
ref: ${{ github.ref }}
50-
fetch-depth: 0
51-
token: ${{ secrets.SILENTWORKS_PAT }}
52-
- name: Python Semantic Release
53-
id: release
54-
uses: python-semantic-release/[email protected]
55-
with:
56-
github_token: ${{ secrets.GITHUB_TOKEN }}
57-
58-
- name: Publish package distributions to PyPI
59-
uses: pypa/gh-action-pypi-publish@release/v1
60-
# NOTE: DO NOT wrap the conditional in ${{ }} as it will always evaluate to true.
61-
# See https://github.com/actions/runner/issues/1173
62-
if: steps.release.outputs.released == 'true'
63-
64-
- name: Python Semantic Release
65-
uses: python-semantic-release/upload-to-gh-release@main
66-
with:
67-
github_token: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/release.yml

+97
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
workflow_dispatch:
8+
9+
permissions:
10+
id-token: write # IMPORTANT: this permission is mandatory for trusted publishing
11+
contents: write # needed for github actions bot to write to repo
12+
pull-requests: write
13+
14+
jobs:
15+
publish:
16+
runs-on: ubuntu-latest
17+
name: "Bump version, create changelog and publish"
18+
environment:
19+
name: pypi
20+
url: https://pypi.org/p/postgrest
21+
steps:
22+
- name: Set up Python 3.11
23+
uses: actions/setup-python@v5
24+
with:
25+
python-version: 3.11
26+
27+
- name: Set up Poetry
28+
uses: abatilo/actions-poetry@v3
29+
with:
30+
poetry-version: 1.8.3
31+
32+
- uses: googleapis/release-please-action@v4
33+
id: release
34+
with:
35+
target-branch: ${{ github.ref_name }}
36+
37+
- uses: actions/checkout@v4
38+
if: ${{ steps.release.outputs.release_created == 'true' || steps.release.outputs.prs_created == 'true' }}
39+
with:
40+
fetch-depth: 0
41+
42+
- if: ${{ steps.release.outputs }}
43+
id: versions
44+
run: |
45+
set -ex
46+
47+
RELEASE_CANDIDATE=true
48+
NOT_RELEASE_CANDIDATE='${{ steps.release.outputs.release_created }}'
49+
if [ "$NOT_RELEASE_CANDIDATE" == "true" ]
50+
then
51+
RELEASE_CANDIDATE=false
52+
fi
53+
54+
MAIN_RELEASE_VERSION=x
55+
RELEASE_VERSION=y
56+
57+
if [ "$RELEASE_CANDIDATE" == "true" ]
58+
then
59+
# Release please doesn't tell you the candidate version when it
60+
# creates the PR, so we have to take it from the title.
61+
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]+/)))")
62+
63+
# Use git describe tags to identify the number of commits the branch
64+
# is ahead of the most recent non-release-candidate tag, which is
65+
# part of the rc.<commits> value.
66+
RELEASE_VERSION=$MAIN_RELEASE_VERSION-rc.$(node -e "console.log('$(git describe --tags --exclude rc*)'.split('-')[1])")
67+
68+
# release-please only ignores releases that have a form like [A-Z0-9]<version>, so prefixing with rc<version>
69+
RELEASE_NAME="rc$RELEASE_VERSION"
70+
else
71+
MAIN_RELEASE_VERSION=${{ steps.release.outputs.major }}.${{ steps.release.outputs.minor }}.${{ steps.release.outputs.patch }}
72+
RELEASE_VERSION="$MAIN_RELEASE_VERSION"
73+
RELEASE_NAME="v$RELEASE_VERSION"
74+
fi
75+
76+
echo "MAIN_RELEASE_VERSION=${MAIN_RELEASE_VERSION}" >> "${GITHUB_ENV}"
77+
echo "RELEASE_VERSION=${RELEASE_VERSION}" >> "${GITHUB_ENV}"
78+
echo "RELEASE_CANDIDATE=${RELEASE_CANDIDATE}" >> "${GITHUB_ENV}"
79+
echo "RELEASE_NAME=${RELEASE_NAME}" >> "${GITHUB_ENV}"
80+
81+
echo "MAIN_RELEASE_VERSION=${MAIN_RELEASE_VERSION}" >> "${GITHUB_OUTPUT}"
82+
echo "RELEASE_VERSION=${RELEASE_VERSION}" >> "${GITHUB_OUTPUT}"
83+
echo "RELEASE_CANDIDATE=${RELEASE_CANDIDATE}" >> "${GITHUB_OUTPUT}"
84+
echo "RELEASE_NAME=${RELEASE_NAME}" >> "${GITHUB_OUTPUT}"
85+
86+
- name: Install dependencies
87+
run: poetry install
88+
89+
- name: Build package distribution directory
90+
id: build_dist
91+
run: poetry build
92+
93+
- name: Publish package distributions to PyPI
94+
uses: pypa/gh-action-pypi-publish@release/v1
95+
# NOTE: DO NOT wrap the conditional in ${{ }} as it will always evaluate to true.
96+
# See https://github.com/actions/runner/issues/1173
97+
if: ${{ steps.release.outputs.release_created == 'true' || steps.release.outputs.prs_created == 'true' }}

.release-please-manifest.json

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
".": "0.16.9"
3+
}

postgrest/__init__.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
from __future__ import annotations
22

3-
__version__ = "0.16.9"
4-
53
from httpx import Timeout
64

75
from ._async.client import AsyncPostgrestClient
@@ -29,3 +27,4 @@
2927
from .deprecated_client import Client, PostgrestClient
3028
from .deprecated_get_request_builder import GetRequestBuilder
3129
from .exceptions import APIError
30+
from .version import __version__

postgrest/_async/client.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@
55
from deprecation import deprecated
66
from httpx import Headers, QueryParams, Timeout
77

8-
from .. import __version__
98
from ..base_client import BasePostgrestClient
109
from ..constants import (
1110
DEFAULT_POSTGREST_CLIENT_HEADERS,
1211
DEFAULT_POSTGREST_CLIENT_TIMEOUT,
1312
)
1413
from ..types import CountMethod
1514
from ..utils import AsyncClient
15+
from ..version import __version__
1616
from .request_builder import AsyncRequestBuilder, AsyncRPCFilterRequestBuilder
1717

1818
_TableT = Dict[str, Any]

postgrest/_sync/client.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@
55
from deprecation import deprecated
66
from httpx import Headers, QueryParams, Timeout
77

8-
from .. import __version__
98
from ..base_client import BasePostgrestClient
109
from ..constants import (
1110
DEFAULT_POSTGREST_CLIENT_HEADERS,
1211
DEFAULT_POSTGREST_CLIENT_TIMEOUT,
1312
)
1413
from ..types import CountMethod
1514
from ..utils import SyncClient
15+
from ..version import __version__
1616
from .request_builder import SyncRequestBuilder, SyncRPCFilterRequestBuilder
1717

1818
_TableT = Dict[str, Any]

postgrest/deprecated_client.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
from deprecation import deprecated
44

5-
from . import __version__
65
from ._async.client import AsyncPostgrestClient
6+
from .version import __version__
77

88

99
class Client(AsyncPostgrestClient):

postgrest/deprecated_get_request_builder.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
from deprecation import deprecated
44

5-
from . import __version__
65
from ._async.request_builder import AsyncSelectRequestBuilder
6+
from .version import __version__
77

88

99
class GetRequestBuilder(AsyncSelectRequestBuilder):

postgrest/version.py

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
__version__ = "0.16.9" # {x-release-please-version}

pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "postgrest"
3-
version = "0.16.9"
3+
version = "0.16.9" # {x-release-please-version}
44
description = "PostgREST client for Python. This library provides an ORM interface to PostgREST."
55
authors = ["Lương Quang Mạnh <[email protected]>", "Joel Lee <[email protected]>", "Anand", "Oliver Rice", "Andrew Smith <[email protected]>"]
66
homepage = "https://github.com/supabase-community/postgrest-py"

release-please-config.json

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"last-release-sha": "9c1268e8011cf141f85cf2bbac682f86acfd06fa",
3+
"packages": {
4+
".": {
5+
"changelog-path": "CHANGELOG.md",
6+
"release-type": "python"
7+
}
8+
}
9+
}

0 commit comments

Comments
 (0)