branch: elpa/emacsql commit 29194a63ede3ee24c7457c2fde03b0f1320ca4b1 Author: Stefan Arentz <ste...@arentz.ca> Commit: Jonas Bernoulli <jo...@bernoul.li>
ci: Add test workflow Co-developed-by: Jonas Bernoulli <jo...@bernoul.li> --- .github/workflows/test.yml | 113 ++++++++++++++++++++++++++++++++++++++++ tests/emacsql-external-tests.el | 56 +++++++++++++++----- 2 files changed, 157 insertions(+), 12 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000000..f0da632529 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,113 @@ +name: Test +permissions: read-all +on: [ push, pull_request ] +env: + pwd: ${{ github.event.repository.name }} +jobs: + matrix: + name: 'Get matrix' + runs-on: ubuntu-latest + outputs: + matrix: ${{ steps.matrix.outputs.matrix }} + steps: + - name: 'Install Emacs' + uses: purcell/setup-emacs@master + with: + version: 28.2 + - name: 'Install workflow scripts' + uses: actions/checkout@v3 + with: + repository: emacscollective/workflows + ref: ${{ inputs.workflow_ref }} + path: _scripts + persist-credentials: false + - name: 'Checkout ${{ github.repository }}' + uses: actions/checkout@v3 + with: + path: ${{ env.pwd }} + persist-credentials: false + - name: 'Get matrix' + id: matrix + working-directory: ${{ env.pwd }} + run: | + ../_scripts/bin/get-matrix >> $GITHUB_OUTPUT + echo "• get-matrix: emacscollective/workflows@${{ inputs.workflow_ref }}" + main: + name: 'Test using Emacs ${{ matrix.emacs }}' + runs-on: ubuntu-latest + needs: matrix + strategy: + fail-fast: false + matrix: + emacs: ${{ fromJson(needs.matrix.outputs.matrix) }} + services: + postgres: + image: postgres:14 + env: + POSTGRES_PASSWORD: postgres + POSTGRES_HOST_AUTH_METHOD: trust + options: >- + --health-cmd pg_isready + --health-interval 10s + --health-timeout 5s + --health-retries 5 + ports: + - 5432:5432 + mysql: + image: mysql:8.0 + env: + MYSQL_ROOT_PASSWORD: emacsql + MYSQL_DATABASE: emacsql + MYSQL_USER: emacsql + MYSQL_PASSWORD: emacsql + ports: + - 3306:3306 + options: >- + --health-cmd="mysqladmin ping" + --health-interval=10s + --health-timeout=5s + --health-retries=3 + steps: + - name: 'Install Emacs' + uses: purcell/setup-emacs@master + with: + version: ${{ matrix.emacs }} + - name: 'Checkout scripts' + uses: actions/checkout@v3 + with: + repository: emacscollective/workflows + ref: ${{ inputs.workflow_ref }} + path: _scripts + persist-credentials: false + - name: 'Checkout ${{ github.repository }}' + uses: actions/checkout@v3 + with: + path: ${{ env.pwd }} + persist-credentials: false + - name: 'Install dependencies' + working-directory: ${{ env.pwd }} + run: ../_scripts/bin/install-deps + - name: 'Build Sqlite3' + working-directory: sqlite3 + run: make all + - name: 'Build Emacsql' + run: make all + working-directory: ${{ env.pwd }} + - name: 'Test Emacsql' + run: make test + working-directory: ${{ env.pwd }} + env: + MYSQL_DATABASE: emacsql + MYSQL_USER: emacsql + MYSQL_PASSWORD: emacsql + MYSQL_HOST: 127.0.0.1 + MYSQL_PORT: 3306 + PSQL_DATABASE: postgres + PSQL_USER: postgres + PSQL_HOST: 127.0.0.1 + PSQL_PORT: 5432 + # PG_DATABASE: postgres + # PG_USER: postgres + # PG_PASSWORD: postgres + # PG_HOST: 127.0.0.1 + # PG_PORT: 5432 diff --git a/tests/emacsql-external-tests.el b/tests/emacsql-external-tests.el index 7095287410..8e32aae187 100644 --- a/tests/emacsql-external-tests.el +++ b/tests/emacsql-external-tests.el @@ -9,10 +9,16 @@ (require 'emacsql) (require 'emacsql-sqlite) +;; FIXME(CI) this is currently not tested because the Emacs +;; snapshot hasn't been compiled with sqlite support. (when (require 'sqlite nil t) (require 'emacsql-sqlite-builtin)) -(when (require 'sqlite3 nil t) (require 'emacsql-sqlite-module)) +;; FIXME(CI) libsqlite3.so.0 cannot be found, even though +;; it appears to be installed in the correct location. +(unless (equal (getenv "CI") "true") + (when (require 'sqlite3 nil t) (require 'emacsql-sqlite-module))) (require 'emacsql-mysql) (require 'emacsql-psql) +;; FIXME(CI) broken and thus disabled in test.yml. (when (require 'pg nil t) (require 'emacsql-pg)) (defvar emacsql-tests-timeout 4 @@ -20,22 +26,48 @@ (defvar emacsql-tests-connection-factories (let ((factories ()) - (pgdatabase (getenv "PGDATABASE")) - (pguser (getenv "PGUSER")) - (mysql-dbname (getenv "MYSQL_DBNAME"))) + (mysql-database (getenv "MYSQL_DATABASE")) + (mysql-user (getenv "MYSQL_USER")) + (mysql-password (getenv "MYSQL_PASSWORD")) + (mysql-host (getenv "MYSQL_HOST")) + (mysql-port (getenv "MYSQL_PORT")) + (psql-database (getenv "PSQL_DATABASE")) + (psql-user (getenv "PSQL_USER")) + (psql-host (getenv "PSQL_HOST")) + (psql-port (getenv "PSQL_PORT")) + (pg-database (getenv "PG_DATABASE")) + (pg-user (getenv "PG_USER")) + (pg-password (getenv "PG_PASSWORD")) + (pg-host (getenv "PG_HOST")) + (pg-port (getenv "PG_PORT"))) (cl-labels ((reg (name &rest args) (push (cons name (apply #'apply-partially args)) factories))) (reg "sqlite" #'emacsql-sqlite nil) - (when (featurep 'emacsql-sqlite-builtin) + (when (and (featurep 'emacsql-sqlite-builtin) + (fboundp 'sqlite-available-p) + (sqlite-available-p)) (reg "sqlite-builtin" 'emacsql-sqlite-builtin nil)) - (when (featurep 'emacsql-sqlite-module) + (when (and (featurep 'emacsql-sqlite-module) + (boundp 'module-file-suffix) + module-file-suffix) (reg "sqlite-module" 'emacsql-sqlite-module nil)) - (when mysql-dbname - (reg "mysql" #'emacsql-mysql mysql-dbname)) - (when pgdatabase - (reg "psql" #'emacsql-psql pgdatabase)) - (when (and pgdatabase pguser) - (reg "pg" 'emacsql-pg pgdatabase pguser))) + (when (and mysql-database mysql-user mysql-host mysql-password mysql-port) + (reg "mysql" #'emacsql-mysql mysql-database + :user mysql-user + :host mysql-host + :password mysql-password + :port mysql-port)) + (when (and psql-database psql-user psql-host psql-port) + (reg "psql" #'emacsql-psql psql-database + :username psql-user + :hostname psql-host + :port psql-port)) + (when (and pg-database pg-user pg-password pg-host pg-port + (fboundp 'emacsql-pg)) + (reg "pg" #'emacsql-pg pg-database pg-user + :host pg-host + :password pg-password + :port pg-port))) (nreverse factories)) "List of connection factories to use in unit tests.")