diff --git a/.github/resources/setup-mongodb.sh b/.github/resources/setup-mongodb.sh new file mode 100755 index 0000000..4bde268 --- /dev/null +++ b/.github/resources/setup-mongodb.sh @@ -0,0 +1,17 @@ +#!/bin/sh + + +# create database and collection +printf "use pgtest\ndb.createCollection('pgtesttable')" | mongo + + +# create user +printf "use pgtest\ndb.createUser({ user: 'test', pwd: 'connecttest', roles: [ 'readWrite' ] })" | mongo + + +# insert data into collection +printf "use pgtest\ndb.pgtesttable.insert( { question: '42', answer: 'the ultimative answer' } )" | mongo + + +# read data from collection +printf "use pgtest\ndb.pgtesttable.find()" | mongo diff --git a/.github/resources/test-mongodb.sh b/.github/resources/test-mongodb.sh new file mode 100755 index 0000000..a77683d --- /dev/null +++ b/.github/resources/test-mongodb.sh @@ -0,0 +1,12 @@ +#!/bin/sh + +psql < /etc/apt/sources.list.d/pgdg.list' + + - name: Update repository + run: sudo apt-get update + + # install the requested version + - name: Install PostgreSQL + run: sudo apt-get install -y postgresql-${{ matrix.postgresql }} postgresql-server-dev-${{ matrix.postgresql }} postgresql-client-${{ matrix.postgresql }} + + # debug output + - name: Path of pg_config + run: which pg_config + + - name: pg_config output + run: pg_config + + - name: Update pg_hba.conf + run: sudo bash -c "echo 'local all all trust' > /etc/postgresql/${{ matrix.postgresql }}/main/pg_hba.conf" + + - name: Update pg_hba.conf + run: sudo bash -c "echo 'host all all 0/0 trust' >> /etc/postgresql/${{ matrix.postgresql }}/main/pg_hba.conf" + + - name: Restart PostgreSQL + run: sudo service postgresql reload + + + # do the actual compilation + - name: Configure the extension + run: cd ${{ steps.pwd.outputs.PWD }} && ./autogen.sh --with-master + + - name: Compile the extension + run: cd ${{ steps.pwd.outputs.PWD }} && make + + # install extension + - name: Install the extension + run: cd ${{ steps.pwd.outputs.PWD }} && sudo make install + + + # some new libraries installed in /usr/local/lib + # linker cache needs to be updated, otherwise these libs are not found later on + - name: ldconfig + run: sudo ldconfig + + + # start testing + + - name: Get current branch name + run: echo "::set-output name=Packages::$(git branch --show-current)" + id: current_branch + + # in a PR this version might be different + - name: Get current extension version + run: echo "::set-output name=Version::$(cat $EXTENSION_SUBDIRECTORY$EXTENSION_NAME.control | grep default_version | sed 's/[^0-9\.]*//g')" + id: current_extension_version + + # the version from the branch in $EXTENSION_BRANCH + - name: Get installed extension version + run: echo "::set-output name=Version::$(git show origin/$EXTENSION_BRANCH:$EXTENSION_SUBDIRECTORY$EXTENSION_NAME.control | grep default_version | sed 's/[^0-9\.]*//g')" + id: installed_extension_version + + - name: Show versions + run: echo "${{ steps.installed_extension_version.outputs.Version }} - ${{ steps.current_extension_version.outputs.Version }}" + + - name: Test current version string + run: exit 1 + if: steps.current_extension_version.outputs.Version == '' + + - name: Test installed version string + run: exit 1 + if: steps.installed_extension_version.outputs.Version == '' + + - name: Create test database + run: createdb -U postgres $EXTENSION_DB + + # install the version from $EXTENSION_BRANCH + - name: Install extension in database + run: psql -U postgres -c "CREATE EXTENSION $EXTENSION_NAME VERSION '${{ steps.installed_extension_version.outputs.Version }}'" $EXTENSION_DB + + - name: Get extension version installed in the database - Step 1 + run: psql -U postgres -A -q -t -o /tmp/installed_version_step_1.txt -c "SELECT extversion FROM pg_catalog.pg_extension WHERE extname='$EXTENSION_NAME'" $EXTENSION_DB + + - name: Get extension version installed in the database - Step 2 + run: echo "::set-output name=Version::$(cat /tmp/installed_version_step_1.txt)" + id: installed_version_step_1 + + - name: Show installed version - after extension install + run: echo "${{ steps.installed_version_step_1.outputs.Version }}" + + # if this is a PR, the version might be different - try an extension upgrade in this case + - name: Upgrade extension in database + run: psql -U postgres -c "ALTER EXTENSION $EXTENSION_NAME UPDATE TO '${{ steps.current_extension_version.outputs.Version }}'" $EXTENSION_DB + if: steps.installed_extension_version.outputs.Version != steps.current_extension_version.outputs.Version + + - name: Get extension version installed in the database - Step 1 + run: psql -U postgres -A -q -t -o /tmp/installed_version_step_2.txt -c "SELECT extversion FROM pg_catalog.pg_extension WHERE extname='$EXTENSION_NAME'" $EXTENSION_DB + + - name: Get extension version installed in the database - Step 2 + run: echo "::set-output name=Version::$(cat /tmp/installed_version_step_2.txt)" + id: installed_version_step_2 + + - name: Show installed version - after extension update + run: echo "${{ steps.installed_version_step_2.outputs.Version }}" + + - name: Run test query + run: psql -U postgres -c "$EXTENSION_TEST_QUERY" $EXTENSION_DB + if: env.EXTENSION_TEST_QUERY != '' + + + # run FDW tests + - name: Run mondo_fdw tests + run: sudo -iu postgres ${{ steps.pwd.outputs.PWD }}/.github/resources/test-mongodb.sh