From 72ea00d0cc69e49017ecb363f2dc1a39aa2dea14 Mon Sep 17 00:00:00 2001 From: David Taylor <david@taylorhq.com> Date: Wed, 17 Aug 2022 22:39:52 +0100 Subject: [PATCH] DEV: Add progress output in CI during ember-cli build (#17977) By default, in CI environments, Ember CLI does not output anything between "building..." and "cleaning up". Depending on configuration and hardware, Discourse asset builds can take upwards of 60s, and so this lack of output can make the build feel 'stuck'. This commit introduces an addon which checks for CI mode, and then outputs status information periodically. The logic is very similar to Ember CLI's non-CI progress output implementation (https://github.com/ember-cli/ember-cli/blob/04a38fda2c/lib/models/builder.js#L183-L185). --- app/assets/javascripts/discourse/package.json | 1 + .../ember-cli-progress-ci/index.js | 54 +++++++++++++++++++ .../ember-cli-progress-ci/package.json | 10 ++++ app/assets/javascripts/package.json | 1 + 4 files changed, 66 insertions(+) create mode 100644 app/assets/javascripts/ember-cli-progress-ci/index.js create mode 100644 app/assets/javascripts/ember-cli-progress-ci/package.json diff --git a/app/assets/javascripts/discourse/package.json b/app/assets/javascripts/discourse/package.json index 2679a8e4232..e618e95b9b2 100644 --- a/app/assets/javascripts/discourse/package.json +++ b/app/assets/javascripts/discourse/package.json @@ -51,6 +51,7 @@ "ember-cli-deprecation-workflow": "^2.1.0", "ember-cli-htmlbars": "^6.1.0", "ember-cli-inject-live-reload": "^2.1.0", + "ember-cli-progress-ci": "1.0.0", "ember-cli-sri": "^2.1.1", "ember-cli-terser": "^4.0.2", "ember-exam": "^7.0.1", diff --git a/app/assets/javascripts/ember-cli-progress-ci/index.js b/app/assets/javascripts/ember-cli-progress-ci/index.js new file mode 100644 index 00000000000..1c30a7e5c85 --- /dev/null +++ b/app/assets/javascripts/ember-cli-progress-ci/index.js @@ -0,0 +1,54 @@ +"use strict"; + +const progress = require("ember-cli/lib/utilities/heimdall-progress"); + +const CHECK_INTERVAL = 100; +const LOG_DUPLICATE_AFTER_DURATION = 5000; + +const REPEAT_DUPLICATE_LOG_ITERATIONS = + LOG_DUPLICATE_AFTER_DURATION / CHECK_INTERVAL; + +// If running in CI mode, this addon will poll the current build node and log it. +// If the node runs for more than LOG_DUPLICATE_AFTER_DURATION, it will be logged again. +module.exports = { + name: require("./package").name, + + preBuild() { + if (this.project.ui.ci) { + this._startOutput(); + } + }, + + outputReady() { + this._stopOutput(); + }, + + buildError() { + this._stopOutput(); + }, + + _startOutput() { + this._discourseProgressLoggerInterval = setInterval( + this._handleProgress.bind(this), + CHECK_INTERVAL + ); + }, + + _handleProgress() { + const text = progress(); + if ( + text === this._lastText && + this._sameOutputCount < REPEAT_DUPLICATE_LOG_ITERATIONS + ) { + this._sameOutputCount++; + } else { + this.project.ui.writeInfoLine("..." + (text ? `[${text}]` : ".")); + this._sameOutputCount = 0; + } + this._lastText = text; + }, + + _stopOutput() { + clearInterval(this._discourseProgressLoggerInterval); + }, +}; diff --git a/app/assets/javascripts/ember-cli-progress-ci/package.json b/app/assets/javascripts/ember-cli-progress-ci/package.json new file mode 100644 index 00000000000..34ae814729c --- /dev/null +++ b/app/assets/javascripts/ember-cli-progress-ci/package.json @@ -0,0 +1,10 @@ +{ + "name": "ember-cli-progress-ci", + "version": "1.0.0", + "description": "Provides output during the ember-cli build process for CI environments", + "author": "Discourse", + "license": "GPL-2.0-only", + "keywords": [ + "ember-addon" + ] +} diff --git a/app/assets/javascripts/package.json b/app/assets/javascripts/package.json index 52efea876e3..43154f4212c 100644 --- a/app/assets/javascripts/package.json +++ b/app/assets/javascripts/package.json @@ -7,6 +7,7 @@ "discourse-ensure-deprecation-order", "discourse-hbr", "discourse-widget-hbs", + "ember-cli-progress-ci", "pretty-text", "select-kit", "truth-helpers",