Skip to content

test(search): make /api/search e2e tests self-contained (fix red develop after #52) #80

test(search): make /api/search e2e tests self-contained (fix red develop after #52)

test(search): make /api/search e2e tests self-contained (fix red develop after #52) #80

Workflow file for this run

name: build
on:
push:
branches: [develop]
pull_request:
branches: [develop]
workflow_dispatch:
permissions:
contents: read
packages: read
jobs:
build-and-test:
name: Build XAR and run Cypress e2e tests
runs-on: ubuntu-latest
timeout-minutes: 30
services:
existdb:
image: existdb/existdb:latest
ports:
- 8080:8080
- 8443:8443
# Note: no docker --health-cmd here. The existdb image lacks curl/wget,
# so any HTTP-based HEALTHCHECK would exit 127 every retry and fail
# service init. Readiness is polled from the runner in a later step.
steps:
- uses: actions/checkout@v6
- name: Set up JDK 21
uses: actions/setup-java@v5
with:
distribution: zulu
java-version: '21'
- name: Restore Maven cache
uses: actions/cache@v5
with:
path: ~/.m2/repository
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
restore-keys: ${{ runner.os }}-m2-
- name: Configure Maven settings for GitHub Packages
run: |
mkdir -p ~/.m2
OWNER=$(echo "${{ github.repository_owner }}" | tr '[:upper:]' '[:lower:]')
cat > ~/.m2/settings.xml <<EOF
<settings xmlns="http://maven.apache.org/SETTINGS/1.2.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.2.0 https://maven.apache.org/xsd/settings-1.2.0.xsd">
<servers>
<server>
<id>github</id>
<username>${OWNER}</username>
<password>${{ secrets.GITHUB_TOKEN }}</password>
</server>
</servers>
</settings>
EOF
- name: Build XAR
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
MAVEN_OPTS: -DtrimStackTrace=false
run: mvn -V -B --no-transfer-progress package
- name: Wait for eXist to be ready
run: |
for i in {1..60}; do
if curl -sf http://localhost:8080/exist/rest/db/ >/dev/null 2>&1; then
echo "eXist is up"
exit 0
fi
echo "Waiting for eXist... ($i/60)"
sleep 5
done
echo "eXist did not become ready in time"
exit 1
- name: Install roaster (XQuery dependency of existdb-openapi)
run: |
npx --yes @existdb/xst@^4 package install from-registry \
http://e-editiones.org/roaster \
--registry https://exist-db.org/exist/apps/public-repo/
env:
EXISTDB_SERVER: http://localhost:8080
EXISTDB_USER: admin
EXISTDB_PASS: ""
- name: Deploy existdb-openapi XAR
run: |
# --force: the existdb/existdb:latest image pre-installs existdb-openapi, and
# xst skips a same-version install. Without --force the freshly built XAR is
# not deployed and the tests run against the pre-installed package.
npx --yes @existdb/xst@^4 package install local target/existdb-openapi-*.xar --force
env:
EXISTDB_SERVER: http://localhost:8080
EXISTDB_USER: admin
EXISTDB_PASS: ""
# The existdb/existdb image ships with existdb-openapi pre-installed.
# `xst package install` replaces the .xar on disk and updates the
# EXPath repo metadata, but Java's classloader has already cached
# the previous JAR's classes by name. URLClassLoader caches classes
# by fully-qualified name and has no API to unload them — so adding
# the new JAR's URL doesn't displace the already-loaded class for
# e.g. org.exist.xquery.modules.openapi.cursor.Eval. This is a
# general property of how eXist's single shared EXistClassLoader
# handles package replacement (verified in exist-core's
# ClasspathHelper + ExistRepository); a JVM restart is the only way
# to pick up the new classes. Without this step the test container
# silently keeps serving the pre-installed package's Java code.
- name: Restart eXist to load updated Java classes
run: |
docker restart "$(docker ps --filter 'ancestor=existdb/existdb:latest' -q | head -1)"
- name: Wait for eXist to be ready (after restart)
run: |
for i in {1..60}; do
if curl -sf http://localhost:8080/exist/rest/db/ >/dev/null 2>&1; then
echo "eXist is up"
exit 0
fi
echo "Waiting for eXist... ($i/60)"
sleep 5
done
echo "eXist did not become ready in time"
exit 1
- name: Run Cypress e2e tests via Maven
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
MAVEN_OPTS: -DtrimStackTrace=false
run: mvn -V -B --no-transfer-progress verify -Pe2e-tests
- name: Upload XAR artifact
if: always()
uses: actions/upload-artifact@v7
with:
name: existdb-openapi-xar
path: target/*.xar
if-no-files-found: warn
- name: Upload Cypress artifacts on failure
if: failure()
uses: actions/upload-artifact@v7
with:
name: cypress-output
path: |
target/cypress/screenshots/
target/cypress/videos/
if-no-files-found: ignore