Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[cypress] Use GitHub action service for Nextcloud server #41252

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions .github/workflows/cypress.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
skjnldsv marked this conversation as resolved.
Show resolved Hide resolved

steps:
- name: Restore context
uses: buildjet/cache/restore@e376f15c6ec6dc595375c78633174c7e5f92dc0e # v3
Expand All @@ -103,12 +110,16 @@ jobs:
- name: Run ${{ matrix.containers == 'component' && 'component' || 'E2E' }} cypress tests
uses: cypress-io/github-action@ebe8b24c4428922d0f793a5c4c96853a633180e3 # v6.6.0
with:
# Unavailable without cypress cloud
# 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 || '' }}
skjnldsv marked this conversation as resolved.
Show resolved Hide resolved
# Unavailable without cypress cloud
# 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
Expand Down
4 changes: 3 additions & 1 deletion cypress.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 10 additions & 1 deletion cypress/dockerNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'

/**
Expand All @@ -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<any> {
if (process.env.NEXTCLOUD_HOST) {
console.log('\nRunning on CI skipping pulling images')
return process.env.NEXTCLOUD_HOST
}

try {
try {
Expand Down Expand Up @@ -204,6 +208,11 @@ export const stopNextcloud = async function() {
export const getContainerIP = async function(
container = docker.getContainer(CONTAINER_NAME),
): Promise<string> {

if (process.env.NEXTCLOUD_HOST) {
return process.env.NEXTCLOUD_HOST
}

let ip = ''
let tries = 0
while (ip === '' && tries < 10) {
Expand Down
3 changes: 2 additions & 1 deletion cypress/support/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@ Cypress.Commands.add('resetUserTheming', (user?: User) => {
})

Cypress.Commands.add('runOccCommand', (command: string, options?: Partial<Cypress.ExecOptions>) => {
const container = (Cypress.config() as unknown as Record<string, string>).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)
})
Loading