Skip to content

Commit d5e8cc5

Browse files
committed
fix(cypress): Use github action service for Nextcloud container
Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
1 parent fd73d3a commit d5e8cc5

4 files changed

Lines changed: 25 additions & 7 deletions

File tree

.github/workflows/cypress.yml

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,13 @@ jobs:
8484

8585
name: runner ${{ matrix.containers }}
8686

87+
services:
88+
nextcloud:
89+
image: ghcr.io/nextcloud/continuous-integration-shallow-server
90+
options: --name nextcloud
91+
ports:
92+
- 80:80
93+
8794
steps:
8895
- name: Restore context
8996
uses: buildjet/cache/restore@e376f15c6ec6dc595375c78633174c7e5f92dc0e # v3
@@ -104,11 +111,10 @@ jobs:
104111
uses: cypress-io/github-action@ebe8b24c4428922d0f793a5c4c96853a633180e3 # v6.6.0
105112
with:
106113
component: ${{ matrix.containers == 'component' }}
107-
group: ${{ matrix.use-cypress-cloud && matrix.containers == 'component' && 'Run component' || matrix.use-cypress-cloud && 'Run E2E' || '' }}
108-
# cypress env
109-
ci-build-id: ${{ matrix.use-cypress-cloud && format('{0}-{1}', github.sha, github.run_number) || '' }}
110-
tag: ${{ matrix.use-cypress-cloud && github.event_name || '' }}
111114
env:
115+
# Use github service for server
116+
NEXTCLOUD_HOST: localhost
117+
NEXTCLOUD_CONTAINER: nextcloud
112118
# Needs to be prefixed with CYPRESS_
113119
CYPRESS_BRANCH: ${{ env.BRANCH }}
114120
# https://github.com/cypress-io/github-action/issues/124

cypress.config.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,9 @@ export default defineConfig({
8585
config.baseUrl = `http://${ip}/index.php`
8686
await waitOnNextcloud(ip)
8787
await configureNextcloud()
88-
await applyChangesToNextcloud()
88+
await applyChangesToNextcloud();
89+
90+
(config as any).NEXTCLOUD_CONTAINER = process.env.NEXTCLOUD_CONTAINER ?? 'nextcloud-cypress-tests-server'
8991

9092
// IMPORTANT: return the config otherwise cypress-split will not work
9193
return config

cypress/dockerNode.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import { execSync } from 'child_process'
3030

3131
export const docker = new Docker()
3232

33-
const CONTAINER_NAME = 'nextcloud-cypress-tests-server'
33+
const CONTAINER_NAME = process.env.NEXTCLOUD_CONTAINER ?? 'nextcloud-cypress-tests-server'
3434
const SERVER_IMAGE = 'ghcr.io/nextcloud/continuous-integration-shallow-server'
3535

3636
/**
@@ -39,6 +39,10 @@ const SERVER_IMAGE = 'ghcr.io/nextcloud/continuous-integration-shallow-server'
3939
* @param {string} branch the branch of your current work
4040
*/
4141
export const startNextcloud = async function(branch: string = getCurrentGitBranch()): Promise<any> {
42+
if (process.env.NEXTCLOUD_HOST) {
43+
console.log('\nRunning on CI skipping pulling images')
44+
return process.env.NEXTCLOUD_HOST
45+
}
4246

4347
try {
4448
try {
@@ -204,6 +208,11 @@ export const stopNextcloud = async function() {
204208
export const getContainerIP = async function(
205209
container = docker.getContainer(CONTAINER_NAME),
206210
): Promise<string> {
211+
212+
if (process.env.NEXTCLOUD_HOST) {
213+
return process.env.NEXTCLOUD_HOST
214+
}
215+
207216
let ip = ''
208217
let tries = 0
209218
while (ip === '' && tries < 10) {

cypress/support/commands.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,7 @@ Cypress.Commands.add('resetUserTheming', (user?: User) => {
287287
})
288288

289289
Cypress.Commands.add('runOccCommand', (command: string, options?: Partial<Cypress.ExecOptions>) => {
290+
const container = (Cypress.config() as unknown as Record<string, string>).NEXTCLOUD_CONTAINER
290291
const env = Object.entries(options?.env ?? {}).map(([name, value]) => `-e '${name}=${value}'`).join(' ')
291-
return cy.exec(`docker exec --user www-data ${env} nextcloud-cypress-tests-server php ./occ ${command}`, options)
292+
return cy.exec(`docker exec --user www-data ${env} ${container} php ./occ ${command}`, options)
292293
})

0 commit comments

Comments
 (0)