Skip to content

Commit

Permalink
Add/migrate wp desktop teamcity (#47368)
Browse files Browse the repository at this point in the history
* Add more logs to app startup

* Create Desktop subproject in TeamCity

* Disable chrome sandbox

* Use custom log file for electron startup

* Add junit-reporter for mocha

* Add notifications, pull request support and test reports to desktop build

* Fix typo in kotlin

* Add multiple reports to mocha

* Store screenshots artifact

* Use correct path for junit test results

* Adds logs for video recorder

* Set CI env var

* Clean up unused env vars

* Clean up debug leftovers
  • Loading branch information
scinos authored Nov 16, 2020
1 parent bb648a1 commit 7ac5bd1
Show file tree
Hide file tree
Showing 7 changed files with 253 additions and 25 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ cached-requests.json
/desktop/id_rsa
/desktop/e2e/logs
/desktop/e2e/screenshots
/desktop/e2e/result.xml

# Typescript
*.tsbuildinfo
159 changes: 157 additions & 2 deletions .teamcity/settings.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import jetbrains.buildServer.configs.kotlin.v2019_2.buildFeatures.pullRequests
import jetbrains.buildServer.configs.kotlin.v2019_2.buildSteps.ScriptBuildStep
import jetbrains.buildServer.configs.kotlin.v2019_2.buildSteps.script
import jetbrains.buildServer.configs.kotlin.v2019_2.projectFeatures.dockerRegistry
import jetbrains.buildServer.configs.kotlin.v2019_2.buildSteps.DockerCommandStep
import jetbrains.buildServer.configs.kotlin.v2019_2.buildSteps.dockerCommand
import jetbrains.buildServer.configs.kotlin.v2019_2.projectFeatures.githubConnection
import jetbrains.buildServer.configs.kotlin.v2019_2.triggers.schedule
Expand Down Expand Up @@ -650,16 +649,172 @@ object WpCalypso : GitVcsRoot({
object WpDesktop : Project({
name = "Desktop"
buildType(WpDesktop_DesktopE2ETests)

params {
text("docker_image_dekstop", "registry.a8c.com/calypso/ci-desktop:latest", label = "Docker image", description = "Docker image to use for the run", allowEmpty = true)
password("CALYPSO_SECRETS_ENCRYPTION_KEY", "credentialsJSON:ff451a7d-df79-4635-b6e8-cbd6ec18ddd8", description = "password for encrypting/decrypting certificates and general secrets for the wp-desktop and simplenote-electron repo", display = ParameterDisplay.HIDDEN)
password("E2EGUTENBERGUSER", "credentialsJSON:27ca9d7b-c6b5-4e84-94d5-ea43879d8184", display = ParameterDisplay.HIDDEN)
password("E2EPASSWORD", "credentialsJSON:2c4425c4-07d2-414c-9f18-b64da307bdf2", display = ParameterDisplay.HIDDEN)
}
})

object WpDesktop_DesktopE2ETests : BuildType({
name = "Desktop e2e tests"
description = "Run wp-desktop e2e tests in Linux"

artifactRules = """
desktop/release => release
desktop/e2e/logs => logs
desktop/e2e/screenshots => screenshots
""".trimIndent()

vcs {
root(WpCalypso)
cleanCheckout = true
}

steps { }
steps {
script {
name = "Prepare environment"
scriptContent = """
set -e
export CHROMEDRIVER_SKIP_DOWNLOAD=true
export PUPPETEER_SKIP_DOWNLOAD=true
# Update node
. "${'$'}NVM_DIR/nvm.sh" --no-use
nvm install
# Restore mtime to maximize cache hits
/usr/lib/git-core/git-restore-mtime --force --commit-time --skip-missing
# Decript certs
openssl aes-256-cbc -md md5 -d -in desktop/resource/calypso/secrets.json.enc -out config/secrets.json -k "%CALYPSO_SECRETS_ENCRYPTION_KEY%"
# Install modules
yarn install
yarn run build-desktop:install-app-deps
""".trimIndent()
dockerImagePlatform = ScriptBuildStep.ImagePlatform.Linux
dockerPull = true
dockerImage = "%docker_image_dekstop%"
dockerRunParameters = "-u %env.UID%"
}

script {
name = "Build Calypso source"
scriptContent = """
set -e
# Update node
. "${'$'}NVM_DIR/nvm.sh" --no-use
nvm install
# Build desktop
yarn run build-desktop:source
""".trimIndent()
dockerImagePlatform = ScriptBuildStep.ImagePlatform.Linux
dockerPull = true
dockerImage = "%docker_image_dekstop%"
dockerRunParameters = "-u %env.UID%"
}

script {
name = "Build app (linux)"
scriptContent = """
set -e
export ELECTRON_BUILDER_ARGS='-c.linux.target=dir'
export USE_HARD_LINKS=false
# Update node
. "${'$'}NVM_DIR/nvm.sh" --no-use
nvm install
# Build app
yarn run build-desktop:app
""".trimIndent()
dockerImagePlatform = ScriptBuildStep.ImagePlatform.Linux
dockerPull = true
dockerImage = "%docker_image_dekstop%"
dockerRunParameters = "-u %env.UID%"
}

script {
name = "Run tests (linux)"
scriptContent = """
set -e
export E2EGUTENBERGUSER="%E2EGUTENBERGUSER%"
export E2EPASSWORD="%E2EPASSWORD%"
export DISPLAY=:99
export CI=true
# Update node
. "${'$'}NVM_DIR/nvm.sh" --no-use
nvm install
# Start framebuffer
Xvfb ${'$'}{DISPLAY} -screen 0 1280x1024x24 &
# Run tests
yarn run test-desktop:e2e
""".trimIndent()
dockerImagePlatform = ScriptBuildStep.ImagePlatform.Linux
dockerPull = true
dockerImage = "%docker_image_dekstop%"
dockerRunParameters = "-u %env.UID%"
}
}

failureConditions {
executionTimeoutMin = 15
}

features {
feature {
type = "xml-report-plugin"
param("xmlReportParsing.reportType", "junit")
param("xmlReportParsing.reportDirs", "desktop/e2e/result.xml")
}
perfmon {
}
pullRequests {
vcsRootExtId = "${WpCalypso.id}"
provider = github {
authType = token {
token = "credentialsJSON:57e22787-e451-48ed-9fea-b9bf30775b36"
}
filterAuthorRole = PullRequests.GitHubRoleFilter.EVERYBODY
}
}
commitStatusPublisher {
vcsRootExtId = "${WpCalypso.id}"
publisher = github {
githubUrl = "https://api.github.com"
authType = personalToken {
token = "credentialsJSON:57e22787-e451-48ed-9fea-b9bf30775b36"
}
}
}

notifications {
notifierSettings = slackNotifier {
connection = "PROJECT_EXT_11"
sendTo = "#wp-desktop-calypso-e2e"
messageFormat = verboseMessageFormat {
addBranch = true
maximumNumberOfChanges = 10
}
}
buildFailedToStart = true
buildFailed = true
buildFinishedSuccessfully = true
firstSuccessAfterFailure = true
buildProbablyHanging = true
}
}

})

6 changes: 6 additions & 0 deletions desktop/e2e/mocha-reporter.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"reporterEnabled": "spec, mocha-junit-reporter",
"mochaJunitReporterReporterOptions": {
"mochaFile": "./e2e/result.xml"
}
}
24 changes: 17 additions & 7 deletions desktop/e2e/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ const APP_ARGS = [
'--disable-http-cache',
'--start-maximized',
'--remote-debugging-port=9222',
'--disable-setuid-sandbox',
'--no-sandbox',
];

let BUILT_APP_DIR;
Expand Down Expand Up @@ -63,18 +65,21 @@ function initLogs( timestamp ) {

const appLogPath = path.join( dir, `app-${ timestamp }.log` );
const driverLogPath = path.join( dir, `chromedriver-${ timestamp }.log` );
const electronLogPath = path.join( dir, `electron-${ timestamp }.log` );

const appLogFd = openSync( appLogPath, 'a' );
const driverLogFd = openSync( driverLogPath, 'a' );
const electronLogFd = openSync( electronLogPath, 'a' );

if ( ! appLogFd || ! driverLogFd ) {
if ( ! appLogFd || ! driverLogFd || ! electronLogFd ) {
throw 'failed to initialize logs';
}

const appLog = { path: appLogPath, fd: appLogFd };
const driverLog = { path: driverLogPath, fd: driverLogFd };
const electronLog = { path: electronLogPath, fd: electronLogFd };

return { appLog, driverLog };
return { appLog, driverLog, electronLog };
}

const delay = promisify( setTimeout );
Expand Down Expand Up @@ -111,12 +116,12 @@ async function run() {

// Replace `:` with `-` to format timestamp as YYYY-MM-DDTHH-MM-SS.mmmZ
const timestamp = new Date().toJSON().replace( /:/g, '-' );
const { appLog, driverLog } = initLogs( timestamp );
const { appLog, driverLog, electronLog } = initLogs( timestamp );

await videoRecorder.startVideo();

const parentEnv = process.env;
app = spawnDetached( CWD, SPAWN_CMD, APP_ARGS, null, {
app = spawnDetached( CWD, SPAWN_CMD, APP_ARGS, electronLog.fd, {
WP_DEBUG_LOG: appLog.path,
DEBUG: true,
...parentEnv,
Expand All @@ -132,9 +137,14 @@ async function run() {
);

const tests = path.join( E2E_DIR, 'tests', 'e2e.js' );
execSync( `npx mocha ${ tests } --timeout 20000 --exit`, {
stdio: 'inherit',
} );
const reporterOptions = path.join( E2E_DIR, 'mocha-reporter.json' );
execSync(
`npx mocha ${ tests } --timeout 20000 --exit --reporter mocha-multi-reporters --reporter-options configFile=${ reporterOptions }`,
{
cwd: PROJECT_DIR,
stdio: 'inherit',
}
);
} catch ( err ) {
console.error( err ); // eslint-disable-line no-console
process.exitCode = 1;
Expand Down
36 changes: 21 additions & 15 deletions desktop/e2e/tests/lib/video-recorder.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,21 +42,27 @@ exports.startVideo = function () {
const fileName = `e2e-test-run-${ dateTime }.mpg`;
file = path.join( E2E_DIR, 'screenshots', 'videos', fileName );
this.createDir( path.dirname( file ) );
ffVideo = child_process.spawn( ffmpeg.path, [
'-f',
'avfoundation',
'-video_size',
'1440x1000',
'-r',
30,
'-i',
'0:none',
'-pix_fmt',
'yuv420p',
'-loglevel',
'error',
file,
] );
ffVideo = child_process.spawn(
ffmpeg.path,
[
'-f',
'avfoundation',
'-video_size',
'1440x1000',
'-r',
30,
'-i',
'0:none',
'-pix_fmt',
'yuv420p',
'-loglevel',
'error',
file,
],
{
stdio: 'inherit',
}
);
};

exports.stopVideo = function () {
Expand Down
2 changes: 2 additions & 0 deletions desktop/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
"ffmpeg-static": "2.4.0",
"lodash": "^4.17.15",
"mocha": "^8.1.3",
"mocha-junit-reporter": "^2.0.0",
"mocha-multi-reporters": "^1.5.1",
"mocha-steps": "1.3.0",
"ncp": "^2.0.0",
"selenium-webdriver": "4.0.0-alpha.1"
Expand Down
Loading

0 comments on commit 7ac5bd1

Please sign in to comment.