From 9dbe8c67575c31c2f7cb410d31900488578a8ce1 Mon Sep 17 00:00:00 2001 From: Riccardo Magliocchetti Date: Sun, 28 Feb 2021 17:32:54 +0100 Subject: ci: first stab at running CI as github actions Props to Adam Chainz for sharing its setup. --- .github/workflows/docs.yml | 17 +++++++++++++++++ .github/workflows/tests.yml | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 .github/workflows/docs.yml create mode 100644 .github/workflows/tests.yml diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml new file mode 100644 index 0000000..5cf7f81 --- /dev/null +++ b/.github/workflows/docs.yml @@ -0,0 +1,17 @@ +name: Build documentation + +on: + push: + branches: [ master ] + +jobs: + docs: + runs-on: ubuntu-18.04 + + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-python@v2 + - name: install requirements + run: pip install --upgrade pip setuptools wheel + - name: run tests + run: TRAVIS_PYTHON_VERSION=3.6 ./scripts/travis_update_docs.sh diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 0000000..4775380 --- /dev/null +++ b/.github/workflows/tests.yml @@ -0,0 +1,37 @@ +name: Tests + +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] + +jobs: + tests: + name: Python ${{ matrix.python-version }} + runs-on: ubuntu-18.04 + + strategy: + fail-fast: false + matrix: + python-version: + - 2.7 + - 3.6 + - 3.7 + - 3.8 + + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-python@v2 + with: + python-version: ${{ matrix.python-version }} + - name: install requirements + run: pip install --upgrade pip setuptools wheel + - name: install local project + run: pip install . + - name: cleanup local egg info + run: rm -rf psycopg2.egg-info + - name: setup test databases + run: sudo ./scripts/travis_prepare.sh + - name: run tests + run: ./scripts/travis_test.sh -- cgit v1.2.1 From 5d19c6ef7e65d65fba3cf974db6987f0d1cc7374 Mon Sep 17 00:00:00 2001 From: Daniele Varrazzo Date: Sat, 22 May 2021 15:40:53 +0200 Subject: Update GitHub Actions as on branch main_2_8 Drop Python version not supported on master. Drop Travis workflow on master branch too. --- .github/workflows/docs.yml | 17 ++--- .github/workflows/tests.yml | 71 ++++++++++++------- .travis.yml | 34 --------- scripts/travis_prepare.sh | 156 ------------------------------------------ scripts/travis_test.sh | 87 ----------------------- scripts/travis_update_docs.sh | 13 +--- tox.ini | 3 +- 7 files changed, 62 insertions(+), 319 deletions(-) delete mode 100644 .travis.yml delete mode 100755 scripts/travis_prepare.sh delete mode 100755 scripts/travis_test.sh diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index 5cf7f81..6533220 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -2,16 +2,17 @@ name: Build documentation on: push: - branches: [ master ] + branches: + - maint_2_8 jobs: docs: - runs-on: ubuntu-18.04 + runs-on: ubuntu-20.04 steps: - - uses: actions/checkout@v2 - - uses: actions/setup-python@v2 - - name: install requirements - run: pip install --upgrade pip setuptools wheel - - name: run tests - run: TRAVIS_PYTHON_VERSION=3.6 ./scripts/travis_update_docs.sh + - uses: actions/checkout@v2 + - name: Trigger docs build + run: ./scripts/travis_update_docs.sh + env: + TRAVIS_BRANCH: maint_2_8 + TRAVIS_TOKEN: ${{ secrets.TRAVIS_TOKEN }} diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 4775380..1364105 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -2,36 +2,61 @@ name: Tests on: push: - branches: [ master ] pull_request: - branches: [ master ] jobs: tests: - name: Python ${{ matrix.python-version }} - runs-on: ubuntu-18.04 + name: Unit tests run + runs-on: ubuntu-20.04 strategy: fail-fast: false matrix: - python-version: - - 2.7 - - 3.6 - - 3.7 - - 3.8 + include: + - python: 3.6 + postgres: 10 + - python: 3.7 + postgres: 11 + - python: 3.8 + postgres: 12 + - python: 3.9 + postgres: 13 + + # Opposite extremes of the supported Py/PG range, other architecture + - python: 3.6 + postgres: 13 + architecture: 'x86' + - python: 3.9 + postgres: 9.5 + architecture: 'x86' + + env: + PSYCOPG2_TESTDB: postgres + PSYCOPG2_TESTDB_HOST: 127.0.0.1 + PSYCOPG2_TESTDB_USER: postgres + PSYCOPG2_TESTDB_PASSWORD: password + + services: + postgresql: + image: postgres:${{ matrix.postgres }} + env: + POSTGRES_PASSWORD: password + ports: + - 5432:5432 + # Set health checks to wait until postgres has started + options: >- + --health-cmd pg_isready + --health-interval 10s + --health-timeout 5s + --health-retries 5 steps: - - uses: actions/checkout@v2 - - uses: actions/setup-python@v2 - with: - python-version: ${{ matrix.python-version }} - - name: install requirements - run: pip install --upgrade pip setuptools wheel - - name: install local project - run: pip install . - - name: cleanup local egg info - run: rm -rf psycopg2.egg-info - - name: setup test databases - run: sudo ./scripts/travis_prepare.sh - - name: run tests - run: ./scripts/travis_test.sh + - uses: actions/checkout@v2 + - uses: actions/setup-python@v2 + with: + python-version: ${{ matrix.python }} + - name: Install tox + run: pip install tox + - name: Run tests + run: tox -e ${{ matrix.python }} + timeout-minutes: 5 diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index f79ae81..0000000 --- a/.travis.yml +++ /dev/null @@ -1,34 +0,0 @@ -# Travis CI configuration file for psycopg2 - -language: python - -dist: bionic - -arch: - - amd64 - - arm64 - -python: - - 3.6 - - 3.7 - - 3.8 - - 3.9 - -install: - - sudo apt-get install -y bc - - pip install -U pip setuptools wheel - - pip install . - - rm -rf psycopg2.egg-info - - sudo scripts/travis_prepare.sh - -script: - - scripts/travis_test.sh - -deploy: - - provider: script - script: bash scripts/travis_update_docs.sh - on: - branch: master - -notifications: - email: false diff --git a/scripts/travis_prepare.sh b/scripts/travis_prepare.sh deleted file mode 100755 index f6f7611..0000000 --- a/scripts/travis_prepare.sh +++ /dev/null @@ -1,156 +0,0 @@ -#!/bin/bash - -set -e -x - -# Prepare the test databases in Travis CI. -# -# The script should be run with sudo. -# The script is not idempotent: it assumes the machine in a clean state -# and is designed for a sudo-enabled Trusty environment. -# -# The variables TEST_PAST, TEST_FUTURE, DONT_TEST_PRESENT can be used to test -# against unsupported Postgres versions and skip tests with supported ones. -# -# The variables can be set in the travis configuration -# (https://travis-ci.org/psycopg/psycopg2/settings) -export TEST_PAST=${TEST_PAST:-0} -export TEST_FUTURE=${TEST_FUTURE:-0} -export TEST_VERBOSE=${TEST_VERBOSE:-0} -export PSYCOPG2_TEST_FAST=${PSYCOPG2_TEST_FAST:-0} -export TEST_PRESENT=${TEST_PRESENT:-1} - -set_param () { - # Set a parameter in a postgresql.conf file - param=$1 - value=$2 - - sed -i "s/^\s*#\?\s*$param.*/$param = $value/" "$DATADIR/postgresql.conf" -} - -create () { - export VERSION=$1 - export PACKAGE=${2:-$VERSION} - - # Version as number: 9.6 -> 906; 11 -> 1100 - export VERNUM=$(echo $VERSION \ - | sed 's/\([0-9]\+\)\(\.\([0-9]\+\)\)\?/100 * \1 + 0\3/' | bc) - - # Port number: 9.6 -> 50906 - export PORT=$(( 50000 + $VERNUM )) - - export DATADIR="/var/lib/postgresql/$PACKAGE/psycopg" - export PGDIR="/usr/lib/postgresql/$PACKAGE" - export PGBIN="$PGDIR/bin" - - # install postgres versions not available on the image - if [[ ! -d "${PGDIR}" ]]; then - if (( "$VERNUM" >= 904 )); then - # A versiou supported by postgres - if [[ ! "${apt_updated:-}" ]]; then - apt_updated="yeah" - sudo apt-get update -y - fi - sudo apt-get install -y \ - postgresql-server-dev-${VERSION} postgresql-${VERSION} - else - # A dinosaur - wget -O - \ - https://upload.psycopg.org/postgresql/postgresql-${PACKAGE}-$(lsb_release -cs).tar.bz2 \ - | sudo tar xjf - -C /usr/lib/postgresql - fi - fi - - sudo -u postgres "$PGBIN/initdb" -D "$DATADIR" - - set_param port "$PORT" - if (( "$VERNUM" >= 800 )); then - set_param listen_addresses "'*'" - else - set_param tcpip_socket true - fi - - # for two-phase commit testing - if (( "$VERNUM" >= 801 )); then set_param max_prepared_transactions 10; fi - - # for replication testing - if (( "$VERNUM" >= 900 )); then set_param max_wal_senders 5; fi - if (( "$VERNUM" >= 904 )); then set_param max_replication_slots 5; fi - - if (( "$VERNUM" >= 904 )); then - set_param wal_level logical - elif (( "$VERNUM" >= 900 )); then - set_param wal_level hot_standby - fi - - if (( "$VERNUM" >= 900 )); then - echo "host replication travis 0.0.0.0/0 trust" >> "$DATADIR/pg_hba.conf" - fi - - # start the server, wait for start - sudo -u postgres "$PGBIN/pg_ctl" -w -l /dev/null -D "$DATADIR" start - - # create the test database - DBNAME=psycopg2_test - CONNINFO="user=postgres host=localhost port=$PORT dbname=template1" - - if (( "$VERNUM" >= 901 )); then - psql -c "create user travis createdb createrole replication" "$CONNINFO" - elif (( "$VERNUM" >= 801 )); then - psql -c "create user travis createdb createrole" "$CONNINFO" - else - psql -c "create user travis createdb createuser" "$CONNINFO" - fi - - psql -c "create database $DBNAME with owner travis" "$CONNINFO" - - # configure global objects on the test database - CONNINFO="user=postgres host=localhost port=$PORT dbname=$DBNAME" - - if (( "$VERNUM" >= 901 )); then - psql -c "create extension hstore" "$CONNINFO" - elif (( "$VERNUM" >= 803 )); then - psql -f "$PGDIR/share/contrib/hstore.sql" "$CONNINFO" - fi - - if (( "$VERNUM" == 901 )); then - psql -c "create extension json" "$CONNINFO" - fi -} - -# Would give a permission denied error in the travis build dir -cd / - -if (( "$TEST_PRESENT" )); then - if [[ ${TRAVIS_CPU_ARCH} == "arm64" ]]; then - # Postgres versions supported by ARM64 - create 10 - else - create 13 - create 12 - create 11 - create 10 - create 9.6 - create 9.5 - create 9.4 - fi -fi -# Unsupported postgres versions that we still support -# Images built by https://github.com/psycopg/psycopg2-wheels/tree/build-dinosaurs -if (( "$TEST_PAST" )); then - create 7.4 - create 8.0 - create 8.1 - create 8.2 - create 8.3 - create 8.4 - create 9.0 - create 9.1 - create 9.2 - create 9.3 -fi - -# Postgres built from master -if (( "$TEST_FUTURE" )); then - # create 14 14-master - true -fi diff --git a/scripts/travis_test.sh b/scripts/travis_test.sh deleted file mode 100755 index 3c6b235..0000000 --- a/scripts/travis_test.sh +++ /dev/null @@ -1,87 +0,0 @@ -#!/bin/bash - -# Run the tests in all the databases -# The script is designed for a Trusty environment. -# -# The variables TEST_PAST, TEST_FUTURE, DONT_TEST_PRESENT can be used to test -# against unsupported Postgres versions and skip tests with supported ones. -# -# The variables TEST_VERBOSE enables verbose test log. -# -# The variables can be set in the travis configuration -# (https://travis-ci.org/psycopg/psycopg2/settings) - -set -e -x - -export TEST_PAST=${TEST_PAST:-0} -export TEST_FUTURE=${TEST_FUTURE:-0} -export TEST_VERBOSE=${TEST_VERBOSE:-0} -export PSYCOPG2_TEST_FAST=${PSYCOPG2_TEST_FAST:-0} -export TEST_PRESENT=${TEST_PRESENT:-1} - -run_test () { - VERSION=$1 - DBNAME=psycopg2_test - if (( "$TEST_VERBOSE" )); then - VERBOSE=--verbose - else - VERBOSE= - fi - - # Port number: 9.6 -> 50906 - port=$(echo $VERSION \ - | sed 's/\([0-9]\+\)\(\.\([0-9]\+\)\)\?/50000 + 100 * \1 + 0\3/' | bc) - - printf "\n\nRunning tests against PostgreSQL $VERSION (port $port)\n\n" - export PSYCOPG2_TESTDB=$DBNAME - export PSYCOPG2_TESTDB_HOST=localhost - export PSYCOPG2_TESTDB_PORT=$port - export PSYCOPG2_TESTDB_USER=travis - export PSYCOPG2_TEST_REPL_DSN= - unset PSYCOPG2_TEST_GREEN - python -c \ - "import tests; tests.unittest.main(defaultTest='tests.test_suite')" \ - $VERBOSE - - printf "\n\nRunning tests against PostgreSQL $VERSION (green mode)\n\n" - export PSYCOPG2_TEST_GREEN=1 - python -c \ - "import tests; tests.unittest.main(defaultTest='tests.test_suite')" \ - $VERBOSE -} - -if (( "$TEST_PRESENT" )); then - if [[ "${TRAVIS_CPU_ARCH}" == "arm64" ]]; then - # Postgres versions supported by ARM64 - run_test 10 - else - # Postgres versions supported by Travis CI - run_test 13 - run_test 12 - run_test 11 - run_test 10 - run_test 9.6 - run_test 9.5 - run_test 9.4 - fi -fi -# Unsupported postgres versions that we still support -# Images built by https://github.com/psycopg/psycopg2-wheels/tree/build-dinosaurs -if (( "$TEST_PAST" )); then - run_test 9.3 - run_test 9.2 - run_test 9.1 - run_test 9.0 - run_test 8.4 - run_test 8.3 - run_test 8.2 - run_test 8.1 - run_test 8.0 - run_test 7.4 -fi - -# Postgres built from master -if (( "$TEST_FUTURE" )); then - # create 14 14-master - true -fi diff --git a/scripts/travis_update_docs.sh b/scripts/travis_update_docs.sh index 80aceab..c45ccc8 100755 --- a/scripts/travis_update_docs.sh +++ b/scripts/travis_update_docs.sh @@ -5,7 +5,7 @@ set -euo pipefail -# The travis token can be set at https://travis-ci.org/psycopg/psycopg2/settings +# The travis token can be set at https://github.com/psycopg/psycopg2/settings/secrets/actions # and can be set on a selected branch only (which should match the DOC_BRANCH # in the psycopg-website Makefile, or it won't refresh a thing). if [ -z "${TRAVIS_TOKEN:-}" ]; then @@ -13,18 +13,11 @@ if [ -z "${TRAVIS_TOKEN:-}" ]; then exit 0 fi -# Avoid to rebuild the website for each matrix entry. -want_python="3.6" -if [ "${TRAVIS_PYTHON_VERSION}" != "${want_python}" ]; then - echo "skipping docs update: only updated on Python ${want_python} build" >&2 - exit 0 -fi - echo "triggering psycopg-website rebuild" >&2 curl -s -X POST \ -H "Content-Type: application/json" \ -H "Accept: application/json" \ -H "Travis-API-Version: 3" \ -H "Authorization: token ${TRAVIS_TOKEN}" \ - -d '{ "request": { "branch":"master" }}' \ - https://api.travis-ci.org/repo/psycopg%2Fpsycopg-website/requests + -d "{\"request\": {\"branch\": \"${TRAVIS_BRANCH}\"}}" \ + https://api.travis-ci.com/repo/psycopg%2Fpsycopg-website/requests diff --git a/tox.ini b/tox.ini index a2ab53c..74faa1a 100644 --- a/tox.ini +++ b/tox.ini @@ -1,9 +1,10 @@ [tox] -envlist = py{36,37,38,39} +envlist = {3.6,3.7,3.8,3.9} [testenv] commands = make check whitelist_externals = make +passenv = PG* PSYCOPG2_TEST* [flake8] max-line-length = 85 -- cgit v1.2.1 From 09d6e3cf64b926522c72ae3f89085fc92a8bc322 Mon Sep 17 00:00:00 2001 From: Daniele Varrazzo Date: Sat, 22 May 2021 17:17:46 +0200 Subject: Use GitHub Actions badge in the readme --- README.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.rst b/README.rst index acf56a6..c9747da 100644 --- a/README.rst +++ b/README.rst @@ -61,11 +61,11 @@ production it is advised to use the package built from sources. .. _install: https://www.psycopg.org/docs/install.html#install-from-source .. _faq: https://www.psycopg.org/docs/faq.html#faq-compile -:Linux/OSX: |travis| +:Linux/OSX: |gh-actions| :Windows: |appveyor| -.. |travis| image:: https://travis-ci.org/psycopg/psycopg2.svg?branch=master - :target: https://travis-ci.org/psycopg/psycopg2 +.. |gh-actions| image:: https://github.com/psycopg/psycopg2/actions/workflows/tests.yml/badge.svg + :target: https://github.com/psycopg/psycopg2/actions/workflows/tests.yml :alt: Linux and OSX build status .. |appveyor| image:: https://ci.appveyor.com/api/projects/status/github/psycopg/psycopg2?branch=master&svg=true -- cgit v1.2.1