Skip to content

Commit

Permalink
Merge pull request #3141 from nextcloud/backport/3138/stable30
Browse files Browse the repository at this point in the history
  • Loading branch information
skjnldsv authored Aug 27, 2024
2 parents 365f5f1 + 30edceb commit 3f83708
Show file tree
Hide file tree
Showing 10 changed files with 3,576 additions and 2,388 deletions.
64 changes: 37 additions & 27 deletions .github/workflows/cypress.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,8 @@ env:
# Adjust APP_NAME if your repository name is different
APP_NAME: ${{ github.event.repository.name }}

# This represents the server branch to checkout.
# Usually it's the base branch of the PR, but for pushes it's the branch itself.
# e.g. 'main', 'stable27' or 'feature/my-feature
# n.b. server will use head_ref, as we want to test the PR branch.
BRANCH: ${{ github.base_ref || github.ref_name }}
# Server requires head_ref instead of base_ref, as we want to test the PR branch
BRANCH: ${{ github.head_ref || github.ref_name }}

jobs:
init:
Expand All @@ -32,15 +29,23 @@ jobs:
npmVersion: ${{ steps.versions.outputs.npmVersion }}

env:
# We'll install cypress in the cypress job
CYPRESS_INSTALL_BINARY: 0
PUPPETEER_SKIP_DOWNLOAD: true

steps:
- name: Disabled on forks
if: ${{ github.event.pull_request.head.repo.full_name != github.repository }}
run: |
echo 'Can not run cypress on forks'
exit 1
- name: Checkout app
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7

- name: Check composer.json
id: check_composer
uses: andstor/file-existence-action@076e0072799f4942c8bc574a82233e1e4d13e9d6 # v2
uses: andstor/file-existence-action@076e0072799f4942c8bc574a82233e1e4d13e9d6 # v3.0.0
with:
files: "composer.json"

Expand All @@ -56,20 +61,20 @@ jobs:
fallbackNpm: "^10"

- name: Set up node ${{ steps.versions.outputs.nodeVersion }}
uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4.0.2
uses: actions/setup-node@1e60f620b9541d16bece96c5465dc8ee9832be0b # v4.0.3
with:
node-version: ${{ steps.versions.outputs.nodeVersion }}

- name: Set up npm ${{ steps.versions.outputs.npmVersion }}
run: npm i -g npm@"${{ steps.versions.outputs.npmVersion }}"
run: npm i -g 'npm@${{ steps.versions.outputs.npmVersion }}'

- name: Install node dependencies & build app
run: |
npm ci
TESTING=true npm run build --if-present
- name: Save context
uses: buildjet/cache/save@3e70d19e31d6a8030aeddf6ed8dbe601f94d09f4 #v4.0.2
uses: buildjet/cache/save@e376f15c6ec6dc595375c78633174c7e5f92dc0e # v3
with:
key: cypress-context-${{ github.run_id }}
path: ./
Expand All @@ -82,38 +87,43 @@ jobs:
fail-fast: false
matrix:
# Run multiple copies of the current job in parallel
# Please increase the number or runners as your tests suite grows
containers: [1, 2, 3]
# Please increase the number or runners as your tests suite grows (0 based index for e2e tests)
containers: ['0', '1', '2']
# Hack as strategy.job-total includes the component and GitHub does not allow math expressions
# Always align this number with the total of e2e runners (max. index + 1)
total-containers: [3]

name: runner ${{ matrix.containers }}

steps:
- name: Restore context
uses: buildjet/cache/restore@3e70d19e31d6a8030aeddf6ed8dbe601f94d09f4 #v4.0.2
uses: buildjet/cache/restore@e376f15c6ec6dc595375c78633174c7e5f92dc0e # v3
with:
fail-on-cache-miss: true
key: cypress-context-${{ github.run_id }}
path: ./

- name: Set up node ${{ needs.init.outputs.nodeVersion }}
uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4.0.2
uses: actions/setup-node@1e60f620b9541d16bece96c5465dc8ee9832be0b # v4.0.3
with:
node-version: ${{ needs.init.outputs.nodeVersion }}

- name: Set up npm ${{ needs.init.outputs.npmVersion }}
run: npm i -g npm@"${{ needs.init.outputs.npmVersion }}"
run: npm i -g 'npm@${{ needs.init.outputs.npmVersion }}'

- name: Install cypress
run: ./node_modules/cypress/bin/cypress install

- name: Run ${{ matrix.containers == 'component' && 'component' || 'E2E' }} cypress tests
uses: cypress-io/github-action@8d3918616d8ac34caa2b49afc8b408b6a872a6f5 # v6.7.1
uses: cypress-io/github-action@df7484c5ba85def7eef30db301afa688187bc378 # v6.7.2
with:
record: ${{ secrets.CYPRESS_RECORD_KEY && true }}
parallel: ${{ secrets.CYPRESS_RECORD_KEY && true }}
# cypress run type
# We already installed the dependencies in the init job
install: false
component: ${{ matrix.containers == 'component' }}
group: ${{ secrets.CYPRESS_RECORD_KEY && env.CYPRESS_GROUP }}
group: ${{ matrix.use-cypress-cloud && matrix.containers == 'component' && 'Run component' || matrix.use-cypress-cloud && 'Run E2E' || '' }}
# cypress env
ci-build-id: ${{ secrets.CYPRESS_RECORD_KEY && env.CYPRESS_BUILD_ID }}
tag: ${{ secrets.CYPRESS_RECORD_KEY && github.event_name }}
ci-build-id: ${{ matrix.use-cypress-cloud && format('{0}-{1}', github.sha, github.run_number) || '' }}
tag: ${{ matrix.use-cypress-cloud && github.event_name || '' }}
env:
# Needs to be prefixed with CYPRESS_
CYPRESS_BRANCH: ${{ env.BRANCH }}
Expand All @@ -123,11 +133,11 @@ jobs:
TESTING: true
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }}
CYPRESS_BUILD_ID: ${{ github.sha }}-${{ github.run_number }}
CYPRESS_GROUP: Run ${{ matrix.containers == 'component' && 'component' || 'E2E' }}
SPLIT: ${{ matrix.total-containers }}
SPLIT_INDEX: ${{ matrix.containers == 'component' && 0 || matrix.containers }}

- name: Upload snapshots
uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1
uses: actions/upload-artifact@0b2256b8c012f0828dc542b3febcab082c67f72b # v4.3.4
if: always()
with:
name: snapshots_${{ matrix.containers }}
Expand All @@ -138,14 +148,14 @@ jobs:
run: docker logs nextcloud-cypress-tests-${{ env.APP_NAME }} > nextcloud.log

- name: Upload NC logs
uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1
uses: actions/upload-artifact@0b2256b8c012f0828dc542b3febcab082c67f72b # v4.3.4
if: failure() && matrix.containers != 'component'
with:
name: nc_logs_${{ matrix.containers }}
path: nextcloud.log

summary:
runs-on: ubuntu-latest
runs-on: ubuntu-latest-low
needs: [init, cypress]

if: always()
Expand Down
63 changes: 13 additions & 50 deletions cypress.config.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
/**
* SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
import { configureNextcloud, startNextcloud, stopNextcloud, waitOnNextcloud } from './cypress/dockerNode'
import { configureNextcloud, startNextcloud, stopNextcloud, waitOnNextcloud } from '@nextcloud/cypress/docker'
import { defineConfig } from 'cypress'

import getCompareSnapshotsPlugin from 'cypress-visual-regression/dist/plugin'
import cypressSplit from 'cypress-split'

export default defineConfig({
projectId: 'xcmgay',
Expand All @@ -14,10 +9,9 @@ export default defineConfig({
viewportWidth: 1280,
viewportHeight: 720,

requestTimeout: 20000,

// Tries again 2 more times on failure
retries: {
runMode: 0,
runMode: 2,
// do not retry in `cypress open`
openMode: 0,
},
Expand All @@ -32,40 +26,14 @@ export default defineConfig({
// https://github.com/cypress-io/cypress/issues/871
scrollBehavior: 'center',

// Visual regression testing
env: {
failSilently: false,
type: 'actual',
},
screenshotsFolder: 'cypress/snapshots/actual',
trashAssetsBeforeRuns: true,

e2e: {
// Disable isolation
// Disable session isolation
testIsolation: false,

// We've imported your old cypress plugins here.
// You may want to clean this up later by importing these.
async setupNodeEvents(on, config) {
getCompareSnapshotsPlugin(on, config)

// Disable spell checking to prevent rendering differences
on('before:browser:launch', (browser, launchOptions) => {
if (browser.family === 'chromium' && browser.name !== 'electron') {
launchOptions.preferences.default['browser.enable_spellchecking'] = false
return launchOptions
}

if (browser.family === 'firefox') {
launchOptions.preferences['layout.spellcheckDefault'] = 0
return launchOptions
}

if (browser.name === 'electron') {
launchOptions.preferences.spellcheck = false
return launchOptions
}
})
cypressSplit(on, config)

// Remove container after run
on('after:run', () => {
Expand All @@ -76,17 +44,12 @@ export default defineConfig({

// Before the browser launches
// starting Nextcloud testing container
return startNextcloud(process.env.BRANCH)
.then((ip) => {
// Setting container's IP as base Url
config.baseUrl = `http://${ip}/index.php`
return ip
})
.then(waitOnNextcloud)
.then(() => configureNextcloud(process.env.BRANCH))
.then(() => {
return config
})
const ip = await startNextcloud(process.env.BRANCH)
// Setting container's IP as base Url
config.baseUrl = `http://${ip}/index.php`
await waitOnNextcloud(ip)
await configureNextcloud(['groupfolders']) // pass empty array as WE are already the viewer
return config
},
},
})
})
Loading

0 comments on commit 3f83708

Please sign in to comment.