From be0170e96098d2f67cf8fe0aa9875e224005d16e Mon Sep 17 00:00:00 2001 From: Elvis Pranskevichus Date: Fri, 18 Oct 2024 15:08:02 -0700 Subject: [PATCH] Fix release workflow Install Kerberos deps when testing wheels and make cibuildwheel tests run properly. --- .github/workflows/install-krb5.sh | 42 ++++++++++-- .github/workflows/install-postgres.sh | 93 +++++++++++++++------------ .github/workflows/release.yml | 29 ++++++--- .github/workflows/tests.yml | 4 +- asyncpg/cluster.py | 10 ++- pyproject.toml | 6 +- 6 files changed, 125 insertions(+), 59 deletions(-) diff --git a/.github/workflows/install-krb5.sh b/.github/workflows/install-krb5.sh index 093b8519..bdb5744d 100755 --- a/.github/workflows/install-krb5.sh +++ b/.github/workflows/install-krb5.sh @@ -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 diff --git a/.github/workflows/install-postgres.sh b/.github/workflows/install-postgres.sh index 4ffbb4d6..733c7033 100755 --- a/.github/workflows/install-postgres.sh +++ b/.github/workflows/install-postgres.sh @@ -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 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index a32a3aeb..5ea543eb 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -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 @@ -67,7 +67,7 @@ jobs: - uses: actions/upload-artifact@v4 with: - name: dist + name: dist-sdist path: dist/*.tar.* build-wheels-matrix: @@ -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 @@ -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: @@ -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 diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index ce06e7f5..f527639a 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -64,7 +64,7 @@ jobs: - name: Install Python Deps if: steps.release.outputs.version == 0 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] @@ -125,7 +125,7 @@ jobs: - name: Install Python Deps if: steps.release.outputs.version == 0 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] diff --git a/asyncpg/cluster.py b/asyncpg/cluster.py index 4467cc2a..860311aa 100644 --- a/asyncpg/cluster.py +++ b/asyncpg/cluster.py @@ -122,9 +122,17 @@ def init(self, **settings): else: extra_args = [] + os.makedirs(self._data_dir, exist_ok=True) + cmd = " ".join( + [self._pg_ctl, 'init', '-D', self._data_dir] + extra_args + ) + print("RUNNING", cmd, "CWD: ", os.getcwd()) 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 diff --git a/pyproject.toml b/pyproject.toml index 4bb9e8f0..057cba59 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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)))" \