Skip to content

Commit 815b0de

Browse files
committed
Fix release workflow
Install Kerberos deps when testing wheels and make cibuildwheel tests run properly.
1 parent f6ec755 commit 815b0de

File tree

8 files changed

+164
-83
lines changed

8 files changed

+164
-83
lines changed

.github/workflows/install-krb5.sh

+37-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,42 @@
11
#!/bin/bash
22

33
set -Eexuo pipefail
4+
shopt -s nullglob
45

5-
if [ "$RUNNER_OS" == "Linux" ]; then
6-
# Assume Ubuntu since this is the only Linux used in CI.
7-
sudo apt-get update
8-
sudo apt-get install -y --no-install-recommends \
9-
libkrb5-dev krb5-user krb5-kdc krb5-admin-server
6+
if [[ $OSTYPE == linux* ]]; then
7+
if [ "$(id -u)" = "0" ]; then
8+
SUDO=
9+
else
10+
SUDO=sudo
11+
fi
12+
13+
if [ -e /etc/os-release ]; then
14+
source /etc/os-release
15+
elif [ -e /etc/centos-release ]; then
16+
ID="centos"
17+
VERSION_ID=$(cat /etc/centos-release | cut -f3 -d' ' | cut -f1 -d.)
18+
else
19+
echo "install-krb5.sh: cannot determine which Linux distro this is" >&2
20+
exit 1
21+
fi
22+
23+
if [ "${ID}" = "debian" -o "${ID}" = "ubuntu" ]; then
24+
export DEBIAN_FRONTEND=noninteractive
25+
26+
$SUDO apt-get update
27+
$SUDO apt-get install -y --no-install-recommends \
28+
libkrb5-dev krb5-user krb5-kdc krb5-admin-server
29+
elif [ "${ID}" = "almalinux" ]; then
30+
$SUDO dnf install -y krb5-server krb5-workstation krb5-libs krb5-devel
31+
elif [ "${ID}" = "centos" ]; then
32+
$SUDO yum install -y krb5-server krb5-workstation krb5-libs krb5-devel
33+
elif [ "${ID}" = "alpine" ]; then
34+
$SUDO apk add krb5 krb5-server krb5-dev
35+
else
36+
echo "install-krb5.sh: Unsupported linux distro: ${distro}" >&2
37+
exit 1
38+
fi
39+
else
40+
echo "install-krb5.sh: unsupported OS: ${OSTYPE}" >&2
41+
exit 1
1042
fi

.github/workflows/install-postgres.sh

+51-42
Original file line numberDiff line numberDiff line change
@@ -3,51 +3,60 @@
33
set -Eexuo pipefail
44
shopt -s nullglob
55

6-
PGVERSION=${PGVERSION:-12}
6+
if [[ $OSTYPE == linux* ]]; then
7+
PGVERSION=${PGVERSION:-12}
78

8-
if [ -e /etc/os-release ]; then
9-
source /etc/os-release
10-
elif [ -e /etc/centos-release ]; then
11-
ID="centos"
12-
VERSION_ID=$(cat /etc/centos-release | cut -f3 -d' ' | cut -f1 -d.)
13-
else
14-
echo "install-postgres.sh: cannot determine which Linux distro this is" >&2
15-
exit 1
16-
fi
9+
if [ -e /etc/os-release ]; then
10+
source /etc/os-release
11+
elif [ -e /etc/centos-release ]; then
12+
ID="centos"
13+
VERSION_ID=$(cat /etc/centos-release | cut -f3 -d' ' | cut -f1 -d.)
14+
else
15+
echo "install-postgres.sh: cannot determine which Linux distro this is" >&2
16+
exit 1
17+
fi
18+
19+
if [ "${ID}" = "debian" -o "${ID}" = "ubuntu" ]; then
20+
export DEBIAN_FRONTEND=noninteractive
1721

18-
if [ "${ID}" = "debian" -o "${ID}" = "ubuntu" ]; then
19-
export DEBIAN_FRONTEND=noninteractive
20-
21-
apt-get install -y --no-install-recommends curl gnupg ca-certificates
22-
curl https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add -
23-
mkdir -p /etc/apt/sources.list.d/
24-
echo "deb https://apt.postgresql.org/pub/repos/apt/ ${VERSION_CODENAME}-pgdg main" \
25-
>> /etc/apt/sources.list.d/pgdg.list
26-
apt-get update
27-
apt-get install -y --no-install-recommends \
28-
"postgresql-${PGVERSION}" \
29-
"postgresql-contrib-${PGVERSION}"
30-
elif [ "${ID}" = "almalinux" ]; then
31-
yum install -y \
32-
"postgresql-server" \
33-
"postgresql-devel" \
34-
"postgresql-contrib"
35-
elif [ "${ID}" = "centos" ]; then
36-
el="EL-${VERSION_ID%.*}-$(arch)"
37-
baseurl="https://download.postgresql.org/pub/repos/yum/reporpms"
38-
yum install -y "${baseurl}/${el}/pgdg-redhat-repo-latest.noarch.rpm"
39-
if [ ${VERSION_ID%.*} -ge 8 ]; then
40-
dnf -qy module disable postgresql
22+
apt-get install -y --no-install-recommends curl gnupg ca-certificates
23+
curl https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add -
24+
mkdir -p /etc/apt/sources.list.d/
25+
echo "deb https://apt.postgresql.org/pub/repos/apt/ ${VERSION_CODENAME}-pgdg main" \
26+
>> /etc/apt/sources.list.d/pgdg.list
27+
apt-get update
28+
apt-get install -y --no-install-recommends \
29+
"postgresql-${PGVERSION}" \
30+
"postgresql-contrib-${PGVERSION}"
31+
elif [ "${ID}" = "almalinux" ]; then
32+
yum install -y \
33+
"postgresql-server" \
34+
"postgresql-devel" \
35+
"postgresql-contrib"
36+
elif [ "${ID}" = "centos" ]; then
37+
el="EL-${VERSION_ID%.*}-$(arch)"
38+
baseurl="https://download.postgresql.org/pub/repos/yum/reporpms"
39+
yum install -y "${baseurl}/${el}/pgdg-redhat-repo-latest.noarch.rpm"
40+
if [ ${VERSION_ID%.*} -ge 8 ]; then
41+
dnf -qy module disable postgresql
42+
fi
43+
yum install -y \
44+
"postgresql${PGVERSION}-server" \
45+
"postgresql${PGVERSION}-contrib"
46+
ln -s "/usr/pgsql-${PGVERSION}/bin/pg_config" "/usr/local/bin/pg_config"
47+
elif [ "${ID}" = "alpine" ]; then
48+
apk add shadow postgresql postgresql-dev postgresql-contrib
49+
else
50+
echo "install-postgres.sh: unsupported Linux distro: ${distro}" >&2
51+
exit 1
4152
fi
42-
yum install -y \
43-
"postgresql${PGVERSION}-server" \
44-
"postgresql${PGVERSION}-contrib"
45-
ln -s "/usr/pgsql-${PGVERSION}/bin/pg_config" "/usr/local/bin/pg_config"
46-
elif [ "${ID}" = "alpine" ]; then
47-
apk add shadow postgresql postgresql-dev postgresql-contrib
53+
54+
useradd -m -s /bin/bash apgtest
55+
56+
elif [[ $OSTYPE == darwin* ]]; then
57+
brew install postgresql
58+
4859
else
49-
echo "install-postgres.sh: Unsupported distro: ${distro}" >&2
60+
echo "install-postgres.sh: unsupported OS: ${OSTYPE}" >&2
5061
exit 1
5162
fi
52-
53-
useradd -m -s /bin/bash apgtest

.github/workflows/release.yml

+21-8
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ jobs:
3939
4040
- uses: actions/upload-artifact@v4
4141
with:
42-
name: dist
43-
path: dist/
42+
name: dist-version
43+
path: dist/VERSION
4444

4545
build-sdist:
4646
needs: validate-release-request
@@ -67,7 +67,7 @@ jobs:
6767
6868
- uses: actions/upload-artifact@v4
6969
with:
70-
name: dist
70+
name: dist-sdist
7171
path: dist/*.tar.*
7272

7373
build-wheels-matrix:
@@ -127,9 +127,19 @@ jobs:
127127

128128
- uses: actions/upload-artifact@v4
129129
with:
130-
name: dist
130+
name: dist-wheels-${{ matrix.only }}
131131
path: wheelhouse/*.whl
132132

133+
merge-artifacts:
134+
runs-on: ubuntu-latest
135+
needs: [build-sdist, build-wheels]
136+
steps:
137+
- name: Merge Artifacts
138+
uses: actions/upload-artifact/merge@v4
139+
with:
140+
name: dist
141+
delete-merged: true
142+
133143
publish-docs:
134144
needs: [build-sdist, build-wheels]
135145
runs-on: ubuntu-latest
@@ -180,6 +190,12 @@ jobs:
180190
needs: [build-sdist, build-wheels, publish-docs]
181191
runs-on: ubuntu-latest
182192

193+
environment:
194+
name: pypi
195+
url: https://pypi.org/p/asyncpg
196+
permissions:
197+
id-token: write
198+
183199
steps:
184200
- uses: actions/checkout@v4
185201
with:
@@ -223,7 +239,4 @@ jobs:
223239
- name: Upload to PyPI
224240
uses: pypa/gh-action-pypi-publish@release/v1
225241
with:
226-
user: __token__
227-
password: ${{ secrets.PYPI_TOKEN }}
228-
# password: ${{ secrets.TEST_PYPI_TOKEN }}
229-
# repository_url: https://test.pypi.org/legacy/
242+
attestations: true

.github/workflows/tests.yml

+12-12
Original file line numberDiff line numberDiff line change
@@ -48,28 +48,28 @@ jobs:
4848
missing_version_ok: yes
4949
version_file: asyncpg/_version.py
5050
version_line_pattern: |
51-
__version__\s*=\s*(?:['"])([[:PEP440:]])(?:['"])
51+
__version__(?:\s*:\s*typing\.Final)?\s*=\s*(?:['"])([[:PEP440:]])(?:['"])
5252
5353
- name: Setup PostgreSQL
54-
if: steps.release.outputs.version == 0 && matrix.os == 'macos-latest'
54+
if: "!steps.release.outputs.is_release && matrix.os == 'macos-latest'"
5555
run: |
5656
brew install postgresql
5757
5858
- name: Set up Python ${{ matrix.python-version }}
5959
uses: actions/setup-python@v5
60-
if: steps.release.outputs.version == 0
60+
if: "!steps.release.outputs.is_release"
6161
with:
6262
python-version: ${{ matrix.python-version }}
6363

6464
- name: Install Python Deps
65-
if: steps.release.outputs.version == 0
65+
if: "!steps.release.outputs.is_release"
6666
run: |
67-
.github/workflows/install-krb5.sh
67+
[ "$RUNNER_OS" = "Linux" ] && .github/workflows/install-krb5.sh
6868
python -m pip install -U pip setuptools wheel
6969
python -m pip install -e .[test]
7070
7171
- name: Test
72-
if: steps.release.outputs.version == 0
72+
if: "!steps.release.outputs.is_release"
7373
env:
7474
LOOP_IMPL: ${{ matrix.loop }}
7575
run: |
@@ -103,10 +103,10 @@ jobs:
103103
missing_version_ok: yes
104104
version_file: asyncpg/_version.py
105105
version_line_pattern: |
106-
__version__\s*=\s*(?:['"])([[:PEP440:]])(?:['"])
106+
__version__(?:\s*:\s*typing\.Final)?\s*=\s*(?:['"])([[:PEP440:]])(?:['"])
107107
108108
- name: Set up PostgreSQL
109-
if: steps.release.outputs.version == 0
109+
if: "!steps.release.outputs.is_release"
110110
env:
111111
PGVERSION: ${{ matrix.postgres-version }}
112112
DISTRO_NAME: focal
@@ -118,19 +118,19 @@ jobs:
118118
119119
- name: Set up Python ${{ matrix.python-version }}
120120
uses: actions/setup-python@v5
121-
if: steps.release.outputs.version == 0
121+
if: "!steps.release.outputs.is_release"
122122
with:
123123
python-version: "3.x"
124124

125125
- name: Install Python Deps
126-
if: steps.release.outputs.version == 0
126+
if: "!steps.release.outputs.is_release"
127127
run: |
128-
.github/workflows/install-krb5.sh
128+
[ "$RUNNER_OS" = "Linux" ] && .github/workflows/install-krb5.sh
129129
python -m pip install -U pip setuptools wheel
130130
python -m pip install -e .[test]
131131
132132
- name: Test
133-
if: steps.release.outputs.version == 0
133+
if: "!steps.release.outputs.is_release"
134134
env:
135135
PGVERSION: ${{ matrix.postgres-version }}
136136
run: |

asyncpg/_testbase/__init__.py

+7-9
Original file line numberDiff line numberDiff line change
@@ -226,13 +226,6 @@ def _init_cluster(ClusterCls, cluster_kwargs, initdb_options=None):
226226
return cluster
227227

228228

229-
def _start_cluster(ClusterCls, cluster_kwargs, server_settings,
230-
initdb_options=None):
231-
cluster = _init_cluster(ClusterCls, cluster_kwargs, initdb_options)
232-
cluster.start(port='dynamic', server_settings=server_settings)
233-
return cluster
234-
235-
236229
def _get_initdb_options(initdb_options=None):
237230
if not initdb_options:
238231
initdb_options = {}
@@ -256,8 +249,13 @@ def _init_default_cluster(initdb_options=None):
256249
_default_cluster = pg_cluster.RunningCluster()
257250
else:
258251
_default_cluster = _init_cluster(
259-
pg_cluster.TempCluster, cluster_kwargs={},
260-
initdb_options=_get_initdb_options(initdb_options))
252+
pg_cluster.TempCluster,
253+
cluster_kwargs={
254+
"data_dir_suffix": ".apgtest",
255+
"data_dir_parent": os.getcwd(),
256+
},
257+
initdb_options=_get_initdb_options(initdb_options),
258+
)
261259

262260
return _default_cluster
263261

asyncpg/cluster.py

+21-5
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,13 @@ def init(self, **settings):
122122
else:
123123
extra_args = []
124124

125+
os.makedirs(self._data_dir, exist_ok=True)
125126
process = subprocess.run(
126127
[self._pg_ctl, 'init', '-D', self._data_dir] + extra_args,
127-
stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
128+
stdout=subprocess.PIPE,
129+
stderr=subprocess.STDOUT,
130+
cwd=self._data_dir,
131+
)
128132

129133
output = process.stdout
130134

@@ -199,7 +203,10 @@ def start(self, wait=60, *, server_settings={}, **opts):
199203
process = subprocess.run(
200204
[self._pg_ctl, 'start', '-D', self._data_dir,
201205
'-o', ' '.join(extra_args)],
202-
stdout=stdout, stderr=subprocess.STDOUT)
206+
stdout=stdout,
207+
stderr=subprocess.STDOUT,
208+
cwd=self._data_dir,
209+
)
203210

204211
if process.returncode != 0:
205212
if process.stderr:
@@ -218,7 +225,10 @@ def start(self, wait=60, *, server_settings={}, **opts):
218225
self._daemon_process = \
219226
subprocess.Popen(
220227
[self._postgres, '-D', self._data_dir, *extra_args],
221-
stdout=stdout, stderr=subprocess.STDOUT)
228+
stdout=stdout,
229+
stderr=subprocess.STDOUT,
230+
cwd=self._data_dir,
231+
)
222232

223233
self._daemon_pid = self._daemon_process.pid
224234

@@ -232,7 +242,10 @@ def reload(self):
232242

233243
process = subprocess.run(
234244
[self._pg_ctl, 'reload', '-D', self._data_dir],
235-
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
245+
stdout=subprocess.PIPE,
246+
stderr=subprocess.PIPE,
247+
cwd=self._data_dir,
248+
)
236249

237250
stderr = process.stderr
238251

@@ -245,7 +258,10 @@ def stop(self, wait=60):
245258
process = subprocess.run(
246259
[self._pg_ctl, 'stop', '-D', self._data_dir, '-t', str(wait),
247260
'-m', 'fast'],
248-
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
261+
stdout=subprocess.PIPE,
262+
stderr=subprocess.PIPE,
263+
cwd=self._data_dir,
264+
)
249265

250266
stderr = process.stderr
251267

0 commit comments

Comments
 (0)