|
1 | | -/** |
2 | | - * SPDX-FileCopyrightText: 2024 Ferdinand Thiessen <opensource@fthiessen.de> |
3 | | - * SPDX-License-Identifier: AGPL-3.0-or-later |
| 1 | +/*! |
| 2 | + * SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors |
| 3 | + * SPDX-License-Identifier: MIT |
4 | 4 | */ |
5 | 5 |
|
6 | | -import { startNextcloud, stopNextcloud } from '@nextcloud/e2e-test-server/docker' |
| 6 | +import { configureNextcloud, startNextcloud, stopNextcloud, waitOnNextcloud } from '@nextcloud/e2e-test-server/docker' |
7 | 7 | import { readFileSync } from 'fs' |
| 8 | +import { execSync } from 'node:child_process' |
8 | 9 |
|
9 | | -const start = async () => { |
10 | | - return await startNextcloud(getBranch(), true, { |
| 10 | +async function start() { |
| 11 | + const appinfo = readFileSync('appinfo/info.xml').toString() |
| 12 | + const maxVersion = appinfo.match(/<nextcloud min-version="\d+" max-version="(\d\d+)" \/>/)?.[1] |
| 13 | + |
| 14 | + let branch = 'master' |
| 15 | + if (maxVersion) { |
| 16 | + const refs = execSync('git ls-remote --refs').toString('utf-8') |
| 17 | + branch = refs.includes(`refs/heads/stable${maxVersion}`) ? `stable${maxVersion}` : branch |
| 18 | + } |
| 19 | + |
| 20 | + return await startNextcloud(branch, true, { |
11 | 21 | exposePort: 8089, |
12 | 22 | }) |
13 | 23 | } |
14 | 24 |
|
15 | | -const getBranch = () => { |
16 | | - try { |
17 | | - const appinfo = readFileSync('appinfo/info.xml').toString() |
18 | | - const maxVersion = appinfo.match( |
19 | | - /<nextcloud min-version="\d+" max-version="(\d\d+)" \/>/, |
20 | | - )?.[1] |
21 | | - return maxVersion ? `stable${maxVersion}` : undefined |
22 | | - } catch (err) { |
23 | | - if (err.code === 'ENOENT') { |
24 | | - console.warn('No appinfo/info.xml found. Using default server banch.') |
25 | | - } |
26 | | - } |
| 25 | +async function stop() { |
| 26 | + process.stderr.write('Stopping Nextcloud server…\n') |
| 27 | + await stopNextcloud() |
| 28 | + process.exit(0) |
27 | 29 | } |
28 | 30 |
|
| 31 | +process.on('SIGTERM', stop) |
| 32 | +process.on('SIGINT', stop) |
| 33 | + |
29 | 34 | // Start the Nextcloud docker container |
30 | | -await start() |
31 | | -// Listen for process to exit (tests done) and shut down the docker container |
32 | | -process.on('beforeExit', (code) => { |
33 | | - stopNextcloud() |
34 | | -}) |
| 35 | +const ip = await start() |
| 36 | +await waitOnNextcloud(ip) |
| 37 | +await configureNextcloud(['text', 'viewer']) |
35 | 38 |
|
36 | 39 | // Idle to wait for shutdown |
37 | 40 | while (true) { |
|
0 commit comments