Skip to content

Commit

Permalink
Fix release workflow
Browse files Browse the repository at this point in the history
Install Kerberos deps when testing wheels and make cibuildwheel tests
run properly.
  • Loading branch information
elprans committed Oct 19, 2024
1 parent f6ec755 commit a25316b
Show file tree
Hide file tree
Showing 7 changed files with 149 additions and 73 deletions.
42 changes: 37 additions & 5 deletions .github/workflows/install-krb5.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,42 @@
#!/bin/bash

set -Eexuo pipefail
shopt -s nullglob

if [ "$RUNNER_OS" == "Linux" ]; then
# Assume Ubuntu since this is the only Linux used in CI.
sudo apt-get update
sudo apt-get install -y --no-install-recommends \
libkrb5-dev krb5-user krb5-kdc krb5-admin-server
if [[ $OSTYPE == linux* ]]; then
if [ "$(id -u)" = "0" ]; then
SUDO=
else
SUDO=sudo
fi

if [ -e /etc/os-release ]; then
source /etc/os-release
elif [ -e /etc/centos-release ]; then
ID="centos"
VERSION_ID=$(cat /etc/centos-release | cut -f3 -d' ' | cut -f1 -d.)
else
echo "install-krb5.sh: cannot determine which Linux distro this is" >&2
exit 1
fi

if [ "${ID}" = "debian" -o "${ID}" = "ubuntu" ]; then
export DEBIAN_FRONTEND=noninteractive

$SUDO apt-get update
$SUDO apt-get install -y --no-install-recommends \
libkrb5-dev krb5-user krb5-kdc krb5-admin-server
elif [ "${ID}" = "almalinux" ]; then
$SUDO dnf install -y krb5-server krb5-workstation krb5-libs krb5-devel
elif [ "${ID}" = "centos" ]; then
$SUDO yum install -y krb5-server krb5-workstation krb5-libs krb5-devel
elif [ "${ID}" = "alpine" ]; then
$SUDO apk add krb5 krb5-server krb5-dev
else
echo "install-krb5.sh: Unsupported linux distro: ${distro}" >&2
exit 1
fi
else
echo "install-krb5.sh: unsupported OS: ${OSTYPE}" >&2
exit 1
fi
93 changes: 51 additions & 42 deletions .github/workflows/install-postgres.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,51 +3,60 @@
set -Eexuo pipefail
shopt -s nullglob

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

if [ -e /etc/os-release ]; then
source /etc/os-release
elif [ -e /etc/centos-release ]; then
ID="centos"
VERSION_ID=$(cat /etc/centos-release | cut -f3 -d' ' | cut -f1 -d.)
else
echo "install-postgres.sh: cannot determine which Linux distro this is" >&2
exit 1
fi
if [ -e /etc/os-release ]; then
source /etc/os-release
elif [ -e /etc/centos-release ]; then
ID="centos"
VERSION_ID=$(cat /etc/centos-release | cut -f3 -d' ' | cut -f1 -d.)
else
echo "install-postgres.sh: cannot determine which Linux distro this is" >&2
exit 1
fi

if [ "${ID}" = "debian" -o "${ID}" = "ubuntu" ]; then
export DEBIAN_FRONTEND=noninteractive

if [ "${ID}" = "debian" -o "${ID}" = "ubuntu" ]; then
export DEBIAN_FRONTEND=noninteractive

apt-get install -y --no-install-recommends curl gnupg ca-certificates
curl https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add -
mkdir -p /etc/apt/sources.list.d/
echo "deb https://apt.postgresql.org/pub/repos/apt/ ${VERSION_CODENAME}-pgdg main" \
>> /etc/apt/sources.list.d/pgdg.list
apt-get update
apt-get install -y --no-install-recommends \
"postgresql-${PGVERSION}" \
"postgresql-contrib-${PGVERSION}"
elif [ "${ID}" = "almalinux" ]; then
yum install -y \
"postgresql-server" \
"postgresql-devel" \
"postgresql-contrib"
elif [ "${ID}" = "centos" ]; then
el="EL-${VERSION_ID%.*}-$(arch)"
baseurl="https://download.postgresql.org/pub/repos/yum/reporpms"
yum install -y "${baseurl}/${el}/pgdg-redhat-repo-latest.noarch.rpm"
if [ ${VERSION_ID%.*} -ge 8 ]; then
dnf -qy module disable postgresql
apt-get install -y --no-install-recommends curl gnupg ca-certificates
curl https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add -
mkdir -p /etc/apt/sources.list.d/
echo "deb https://apt.postgresql.org/pub/repos/apt/ ${VERSION_CODENAME}-pgdg main" \
>> /etc/apt/sources.list.d/pgdg.list
apt-get update
apt-get install -y --no-install-recommends \
"postgresql-${PGVERSION}" \
"postgresql-contrib-${PGVERSION}"
elif [ "${ID}" = "almalinux" ]; then
yum install -y \
"postgresql-server" \
"postgresql-devel" \
"postgresql-contrib"
elif [ "${ID}" = "centos" ]; then
el="EL-${VERSION_ID%.*}-$(arch)"
baseurl="https://download.postgresql.org/pub/repos/yum/reporpms"
yum install -y "${baseurl}/${el}/pgdg-redhat-repo-latest.noarch.rpm"
if [ ${VERSION_ID%.*} -ge 8 ]; then
dnf -qy module disable postgresql
fi
yum install -y \
"postgresql${PGVERSION}-server" \
"postgresql${PGVERSION}-contrib"
ln -s "/usr/pgsql-${PGVERSION}/bin/pg_config" "/usr/local/bin/pg_config"
elif [ "${ID}" = "alpine" ]; then
apk add shadow postgresql postgresql-dev postgresql-contrib
else
echo "install-postgres.sh: unsupported Linux distro: ${distro}" >&2
exit 1
fi
yum install -y \
"postgresql${PGVERSION}-server" \
"postgresql${PGVERSION}-contrib"
ln -s "/usr/pgsql-${PGVERSION}/bin/pg_config" "/usr/local/bin/pg_config"
elif [ "${ID}" = "alpine" ]; then
apk add shadow postgresql postgresql-dev postgresql-contrib

useradd -m -s /bin/bash apgtest

elif [[ $OSTYPE == darwin* ]]; then
brew install postgresql

else
echo "install-postgres.sh: Unsupported distro: ${distro}" >&2
echo "install-postgres.sh: unsupported OS: ${OSTYPE}" >&2
exit 1
fi

useradd -m -s /bin/bash apgtest
29 changes: 21 additions & 8 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ jobs:
- uses: actions/upload-artifact@v4
with:
name: dist
path: dist/
name: dist-version
path: dist/VERSION

build-sdist:
needs: validate-release-request
Expand All @@ -67,7 +67,7 @@ jobs:
- uses: actions/upload-artifact@v4
with:
name: dist
name: dist-sdist
path: dist/*.tar.*

build-wheels-matrix:
Expand Down Expand Up @@ -127,9 +127,19 @@ jobs:

- uses: actions/upload-artifact@v4
with:
name: dist
name: dist-wheels-${{ matrix.only }}
path: wheelhouse/*.whl

merge-artifacts:
runs-on: ubuntu-latest
needs: [build-sdist, build-wheels]
steps:
- name: Merge Artifacts
uses: actions/upload-artifact/merge@v4
with:
name: dist
delete-merged: true

publish-docs:
needs: [build-sdist, build-wheels]
runs-on: ubuntu-latest
Expand Down Expand Up @@ -180,6 +190,12 @@ jobs:
needs: [build-sdist, build-wheels, publish-docs]
runs-on: ubuntu-latest

environment:
name: pypi
url: https://pypi.org/p/asyncpg
permissions:
id-token: write

steps:
- uses: actions/checkout@v4
with:
Expand Down Expand Up @@ -223,7 +239,4 @@ jobs:
- name: Upload to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
user: __token__
password: ${{ secrets.PYPI_TOKEN }}
# password: ${{ secrets.TEST_PYPI_TOKEN }}
# repository_url: https://test.pypi.org/legacy/
attestations: true
20 changes: 10 additions & 10 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,25 +51,25 @@ jobs:
__version__\s*=\s*(?:['"])([[:PEP440:]])(?:['"])
- name: Setup PostgreSQL
if: steps.release.outputs.version == 0 && matrix.os == 'macos-latest'
if: "!steps.release.outputs.is_release && matrix.os == 'macos-latest'"
run: |
brew install postgresql
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
if: steps.release.outputs.version == 0
if: "!steps.release.outputs.is_release"
with:
python-version: ${{ matrix.python-version }}

- name: Install Python Deps
if: steps.release.outputs.version == 0
if: "!steps.release.outputs.is_release"
run: |
.github/workflows/install-krb5.sh
[ "$RUNNER_OS" = "Linux" ] && .github/workflows/install-krb5.sh
python -m pip install -U pip setuptools wheel
python -m pip install -e .[test]
- name: Test
if: steps.release.outputs.version == 0
if: "!steps.release.outputs.is_release"
env:
LOOP_IMPL: ${{ matrix.loop }}
run: |
Expand Down Expand Up @@ -106,7 +106,7 @@ jobs:
__version__\s*=\s*(?:['"])([[:PEP440:]])(?:['"])
- name: Set up PostgreSQL
if: steps.release.outputs.version == 0
if: "!steps.release.outputs.is_release"
env:
PGVERSION: ${{ matrix.postgres-version }}
DISTRO_NAME: focal
Expand All @@ -118,19 +118,19 @@ jobs:
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
if: steps.release.outputs.version == 0
if: "!steps.release.outputs.is_release"
with:
python-version: "3.x"

- name: Install Python Deps
if: steps.release.outputs.version == 0
if: "!steps.release.outputs.is_release"
run: |
.github/workflows/install-krb5.sh
[ "$RUNNER_OS" = "Linux" ] && .github/workflows/install-krb5.sh
python -m pip install -U pip setuptools wheel
python -m pip install -e .[test]
- name: Test
if: steps.release.outputs.version == 0
if: "!steps.release.outputs.is_release"
env:
PGVERSION: ${{ matrix.postgres-version }}
run: |
Expand Down
6 changes: 4 additions & 2 deletions asyncpg/_testbase/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,8 +256,10 @@ def _init_default_cluster(initdb_options=None):
_default_cluster = pg_cluster.RunningCluster()
else:
_default_cluster = _init_cluster(
pg_cluster.TempCluster, cluster_kwargs={},
initdb_options=_get_initdb_options(initdb_options))
pg_cluster.TempCluster,
cluster_kwargs={"data_dir_suffix": ".apgtest"},
initdb_options=_get_initdb_options(initdb_options),
)

return _default_cluster

Expand Down
26 changes: 21 additions & 5 deletions asyncpg/cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,13 @@ def init(self, **settings):
else:
extra_args = []

os.makedirs(self._data_dir, exist_ok=True)
process = subprocess.run(
[self._pg_ctl, 'init', '-D', self._data_dir] + extra_args,
stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
cwd=self._data_dir,
)

output = process.stdout

Expand Down Expand Up @@ -199,7 +203,10 @@ def start(self, wait=60, *, server_settings={}, **opts):
process = subprocess.run(
[self._pg_ctl, 'start', '-D', self._data_dir,
'-o', ' '.join(extra_args)],
stdout=stdout, stderr=subprocess.STDOUT)
stdout=stdout,
stderr=subprocess.STDOUT,
cwd=self._data_dir,
)

if process.returncode != 0:
if process.stderr:
Expand All @@ -218,7 +225,10 @@ def start(self, wait=60, *, server_settings={}, **opts):
self._daemon_process = \
subprocess.Popen(
[self._postgres, '-D', self._data_dir, *extra_args],
stdout=stdout, stderr=subprocess.STDOUT)
stdout=stdout,
stderr=subprocess.STDOUT,
cwd=self._data_dir,
)

self._daemon_pid = self._daemon_process.pid

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

process = subprocess.run(
[self._pg_ctl, 'reload', '-D', self._data_dir],
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
cwd=self._data_dir,
)

stderr = process.stderr

Expand All @@ -245,7 +258,10 @@ def stop(self, wait=60):
process = subprocess.run(
[self._pg_ctl, 'stop', '-D', self._data_dir, '-t', str(wait),
'-m', 'fast'],
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
cwd=self._data_dir,
)

stderr = process.stderr

Expand Down
6 changes: 5 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,17 @@ build-frontend = "build"
test-extras = "test"

[tool.cibuildwheel.macos]
before-all = ".github/workflows/install-postgres.sh"
test-command = "python {project}/tests/__init__.py"

[tool.cibuildwheel.windows]
test-command = "python {project}\\tests\\__init__.py"

[tool.cibuildwheel.linux]
before-all = ".github/workflows/install-postgres.sh"
before-all = """
.github/workflows/install-postgres.sh \
&& .github/workflows/install-krb5.sh \
"""
test-command = """\
PY=`which python` \
&& chmod -R go+rX "$(dirname $(dirname $(dirname $PY)))" \
Expand Down

0 comments on commit a25316b

Please sign in to comment.