From 1f6ed9c9374241aa65120e645fb36ec96f870ba7 Mon Sep 17 00:00:00 2001 From: Ferdinand Thiessen Date: Thu, 2 Nov 2023 21:11:40 +0100 Subject: [PATCH 1/2] fix(cypress): Use github action service for Nextcloud container Signed-off-by: Ferdinand Thiessen --- .github/workflows/cypress.yml | 17 +++++++++++++---- cypress.config.ts | 4 +++- cypress/dockerNode.ts | 11 ++++++++++- cypress/support/commands.ts | 3 ++- 4 files changed, 28 insertions(+), 7 deletions(-) diff --git a/.github/workflows/cypress.yml b/.github/workflows/cypress.yml index 3facf40004bed..16fefe3d1f48a 100644 --- a/.github/workflows/cypress.yml +++ b/.github/workflows/cypress.yml @@ -84,6 +84,13 @@ jobs: name: runner ${{ matrix.containers }} + services: + nextcloud: + image: ghcr.io/nextcloud/continuous-integration-shallow-server + options: --name nextcloud + ports: + - 80:80 + steps: - name: Restore context uses: buildjet/cache/restore@e376f15c6ec6dc595375c78633174c7e5f92dc0e # v3 @@ -103,12 +110,14 @@ jobs: - name: Run ${{ matrix.containers == 'component' && 'component' || 'E2E' }} cypress tests uses: cypress-io/github-action@ebe8b24c4428922d0f793a5c4c96853a633180e3 # v6.6.0 with: + ci-build-id: ${{ github.sha }}-${{ github.run_number }} component: ${{ matrix.containers == 'component' }} - group: ${{ matrix.use-cypress-cloud && matrix.containers == 'component' && 'Run component' || matrix.use-cypress-cloud && 'Run E2E' || '' }} - # cypress env - ci-build-id: ${{ matrix.use-cypress-cloud && format('{0}-{1}', github.sha, github.run_number) || '' }} - tag: ${{ matrix.use-cypress-cloud && github.event_name || '' }} + group: Run ${{ matrix.containers == 'component' && 'component' || 'E2E' }} + tag: ${{ github.event_name }} env: + # Use github service for server + NEXTCLOUD_HOST: localhost + NEXTCLOUD_CONTAINER: nextcloud # Needs to be prefixed with CYPRESS_ CYPRESS_BRANCH: ${{ env.BRANCH }} # https://github.com/cypress-io/github-action/issues/124 diff --git a/cypress.config.ts b/cypress.config.ts index 8aa4bd48b245e..f3d2e2ff8d429 100644 --- a/cypress.config.ts +++ b/cypress.config.ts @@ -85,7 +85,9 @@ export default defineConfig({ config.baseUrl = `http://${ip}/index.php` await waitOnNextcloud(ip) await configureNextcloud() - await applyChangesToNextcloud() + await applyChangesToNextcloud(); + + (config as any).NEXTCLOUD_CONTAINER = process.env.NEXTCLOUD_CONTAINER ?? 'nextcloud-cypress-tests-server' // IMPORTANT: return the config otherwise cypress-split will not work return config diff --git a/cypress/dockerNode.ts b/cypress/dockerNode.ts index 38bc86d9c5f39..80acab9866305 100644 --- a/cypress/dockerNode.ts +++ b/cypress/dockerNode.ts @@ -30,7 +30,7 @@ import { execSync } from 'child_process' export const docker = new Docker() -const CONTAINER_NAME = 'nextcloud-cypress-tests-server' +const CONTAINER_NAME = process.env.NEXTCLOUD_CONTAINER ?? 'nextcloud-cypress-tests-server' const SERVER_IMAGE = 'ghcr.io/nextcloud/continuous-integration-shallow-server' /** @@ -39,6 +39,10 @@ const SERVER_IMAGE = 'ghcr.io/nextcloud/continuous-integration-shallow-server' * @param {string} branch the branch of your current work */ export const startNextcloud = async function(branch: string = getCurrentGitBranch()): Promise { + if (process.env.NEXTCLOUD_HOST) { + console.log('\nRunning on CI skipping pulling images') + return process.env.NEXTCLOUD_HOST + } try { try { @@ -204,6 +208,11 @@ export const stopNextcloud = async function() { export const getContainerIP = async function( container = docker.getContainer(CONTAINER_NAME), ): Promise { + + if (process.env.NEXTCLOUD_HOST) { + return process.env.NEXTCLOUD_HOST + } + let ip = '' let tries = 0 while (ip === '' && tries < 10) { diff --git a/cypress/support/commands.ts b/cypress/support/commands.ts index 477a366a421a2..40719e0ff644e 100644 --- a/cypress/support/commands.ts +++ b/cypress/support/commands.ts @@ -287,6 +287,7 @@ Cypress.Commands.add('resetUserTheming', (user?: User) => { }) Cypress.Commands.add('runOccCommand', (command: string, options?: Partial) => { + const container = (Cypress.config() as unknown as Record).NEXTCLOUD_CONTAINER const env = Object.entries(options?.env ?? {}).map(([name, value]) => `-e '${name}=${value}'`).join(' ') - return cy.exec(`docker exec --user www-data ${env} nextcloud-cypress-tests-server php ./occ ${command}`, options) + return cy.exec(`docker exec --user www-data ${env} ${container} php ./occ ${command}`, options) }) From 41f6c9fe1286eecdfc2e7002274b3501cdbe7848 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Molakvo=C3=A6?= Date: Sun, 21 Jan 2024 09:38:56 +0100 Subject: [PATCH 2/2] fix(cypress): disable `ci-build-id`, `group` and `tag` until we have a cypress cloud service again MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: John Molakvoæ --- .github/workflows/cypress.yml | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/.github/workflows/cypress.yml b/.github/workflows/cypress.yml index 16fefe3d1f48a..9444ec612e4fb 100644 --- a/.github/workflows/cypress.yml +++ b/.github/workflows/cypress.yml @@ -110,10 +110,12 @@ jobs: - name: Run ${{ matrix.containers == 'component' && 'component' || 'E2E' }} cypress tests uses: cypress-io/github-action@ebe8b24c4428922d0f793a5c4c96853a633180e3 # v6.6.0 with: - ci-build-id: ${{ github.sha }}-${{ github.run_number }} + # Unavailable without cypress cloud + # ci-build-id: ${{ github.sha }}-${{ github.run_number }} component: ${{ matrix.containers == 'component' }} - group: Run ${{ matrix.containers == 'component' && 'component' || 'E2E' }} - tag: ${{ github.event_name }} + # Unavailable without cypress cloud + # group: Run ${{ matrix.containers == 'component' && 'component' || 'E2E' }} + # tag: ${{ github.event_name }} env: # Use github service for server NEXTCLOUD_HOST: localhost