Skip to content

A platform for community discussion. Free, open, simple.

FEATURE: Improve display of installed/available version on dashboard (#41165)

David Taylorb6dfa40d1e83
diff --git a/app/assets/stylesheets/admin/dashboard.scss b/app/assets/stylesheets/admin/dashboard.scss
index da9b66564ca..c79467aeb23 100644
--- a/app/assets/stylesheets/admin/dashboard.scss
+++ b/app/assets/stylesheets/admin/dashboard.scss
@@ -646,15 +646,32 @@
white-space: nowrap;
}
+ .commits-ahead {
+ font-size: var(--font-down-2-rem);
+ font-weight: normal;
+ color: var(--primary-medium);
+ cursor: help;
+ }
+
h4 {
font-size: var(--font-down-2);
margin-bottom: 0.5em;
}
- .sha-link {
- display: inline-flex;
- font-size: var(--font-down-2);
- font-weight: normal;
+ .version-links {
+ display: flex;
+ flex-wrap: wrap;
+ gap: var(--space-4);
+ margin-top: var(--space-1);
+
+ a {
+ display: inline-flex;
+ align-items: center;
+ gap: var(--space-1);
+ font-size: var(--font-down-3);
+ font-weight: normal;
+ white-space: nowrap;
+ }
}
}
@@ -685,7 +702,7 @@
display: none;
}
- .fa {
+ .face .fa {
font-size: var(--font-up-4);
}
diff --git a/app/jobs/scheduled/call_discourse_hub.rb b/app/jobs/scheduled/call_discourse_hub.rb
index 5ca9e7baa10..8ba616c0f72 100644
--- a/app/jobs/scheduled/call_discourse_hub.rb
+++ b/app/jobs/scheduled/call_discourse_hub.rb
@@ -13,6 +13,8 @@ module Jobs
json = DiscourseHub.discourse_version_check
DiscourseUpdates.last_installed_version = Discourse::VERSION::STRING
DiscourseUpdates.latest_version = json["latestVersion"]
+ DiscourseUpdates.latest_pretty_version = json["latestPrettyVersion"]
+ DiscourseUpdates.latest_sha = json["latestSha"]
DiscourseUpdates.critical_updates_available = json["criticalUpdates"]
DiscourseUpdates.missing_versions_count = json["missingVersionsCount"]
DiscourseUpdates.updated_at = Time.zone.now
diff --git a/app/models/discourse_version_check.rb b/app/models/discourse_version_check.rb
index 8a3b914bae9..847eb846e9c 100644
--- a/app/models/discourse_version_check.rb
+++ b/app/models/discourse_version_check.rb
@@ -4,6 +4,8 @@ class DiscourseVersionCheck
include ActiveModel::Model
attr_accessor :latest_version,
+ :latest_pretty_version,
+ :latest_sha,
:critical_updates,
:installed_version,
:installed_sha,
diff --git a/app/serializers/discourse_version_check_serializer.rb b/app/serializers/discourse_version_check_serializer.rb
index 42b2c32daf4..7d1307a876e 100644
--- a/app/serializers/discourse_version_check_serializer.rb
+++ b/app/serializers/discourse_version_check_serializer.rb
@@ -2,9 +2,12 @@
class DiscourseVersionCheckSerializer < ApplicationSerializer
attributes :latest_version,
+ :latest_pretty_version,
+ :latest_sha,
:critical_updates,
:installed_version,
:installed_sha,
+ :installed_describe,
:missing_versions_count,
:updated_at
diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml
index c983b411e4e..a5941f445bb 100644
--- a/config/locales/client.en.yml
+++ b/config/locales/client.en.yml
@@ -7016,6 +7016,9 @@ en:
discourse_last_updated: "Discourse updated:"
version: "Version"
up_to_date: "You're up to date!"
+ up_to_date_newer_commits:
+ one: "You're on the most recent release, but %{count} new change is available."
+ other: "You're on the most recent release, but %{count} new changes are available."
critical_available: "A critical update is available."
updates_available: "Updates are available."
please_update: "Please update!"
@@ -7023,7 +7026,13 @@ en:
stale_data: "A check for updates has not been performed lately. Ensure Sidekiq is running."
version_check_pending: "Looks like you updated recently. Fantastic!"
installed_version: "Installed"
- latest_version: "Latest"
+ latest_version: "Available"
+ github: "GitHub"
+ commit_on_github: "View commit %{sha} on GitHub"
+ changelog: "Changelog"
+ commits_ahead:
+ one: "Running %{count} additional change since the start of this release series"
+ other: "Running %{count} additional changes since the start of this release series"
problems_found: "Some advice based on your current site settings"
dismiss_notice: "Ignore"
site_advice:
diff --git a/frontend/discourse/admin/components/version-checks.gjs b/frontend/discourse/admin/components/version-checks.gjs
index f8545bb3e0f..fe26c02bbea 100644
--- a/frontend/discourse/admin/components/version-checks.gjs
+++ b/frontend/discourse/admin/components/version-checks.gjs
@@ -22,18 +22,31 @@ const VersionChecks = <template>
</h4>
<h3>
{{dashIfEmpty @versionCheck.installed_version}}
+ {{#if @versionCheck.installedCommitsAhead}}
+ <span
+ class="commits-ahead"
+ title={{i18n
+ "admin.dashboard.commits_ahead"
+ }}
+ >+{{@versionCheck.installedCommitsAhead}}</span>
+ {{/if}}
</h3>
{{#if @versionCheck.gitLink}}
- <div class="sha-link">
- (
+ <div class="version-links">
<a
+ class="github-link"
href={{@versionCheck.gitLink}}
rel="noopener noreferrer"
target="_blank"
+ title={{i18n
+ "admin.dashboard.commit_on_github"
+ }}
>
- {{@versionCheck.shortSha}}
+ {{i18n "admin.dashboard.github"}}
+ {{dIcon "up-right-from-square"}}
</a>
- )
</div>
{{/if}}
</div>
@@ -98,7 +111,44 @@ const VersionChecks = <template>
</h4>
<h3>
{{dashIfEmpty @versionCheck.latest_version}}
+ {{#if @versionCheck.latestCommitsAhead}}
+ <span
+ class="commits-ahead"
+ title={{i18n
+ "admin.dashboard.commits_ahead"
+ }}
+ >+{{@versionCheck.latestCommitsAhead}}</span>
+ {{/if}}
</h3>
+ {{#if @versionCheck.latestGitLink}}
+ <div class="version-links">
+ {{#if @versionCheck.changelogLink}}
+ <a
+ class="changelog-link"
+ href={{@versionCheck.changelogLink}}
+ rel="noopener noreferrer"
+ target="_blank"
+ >
+ {{i18n "admin.dashboard.changelog"}}
+ {{dIcon "up-right-from-square"}}
+ </a>
+ {{/if}}
+ <a
+ class="github-link"
+ href={{@versionCheck.latestGitLink}}
+ rel="noopener noreferrer"
+ target="_blank"
+ title={{i18n
+ "admin.dashboard.commit_on_github"
+ }}
+ >
+ {{i18n "admin.dashboard.github"}}
+ {{dIcon "up-right-from-square"}}
+ </a>
+ </div>
+ {{/if}}
</div>
<div class="version-status">
<div class="face">
@@ -125,7 +175,14 @@ const VersionChecks = <template>
</div>
<div class="version-notes">
{{#if @versionCheck.upToDate}}
- {{i18n "admin.dashboard.up_to_date"}}
+ {{#if @versionCheck.newerCommitsAvailable}}
+ {{i18n
+ "admin.dashboard.up_to_date_newer_commits"
+ }}
+ {{else}}
+ {{i18n "admin.dashboard.up_to_date"}}
+ {{/if}}
{{else}}
<span class="critical-note">
{{i18n "admin.dashboard.critical_available"}}
diff --git a/frontend/discourse/admin/controllers/admin/dashboard.js b/frontend/discourse/admin/controllers/admin/dashboard.js
index 229039ba159..434919c030d 100644
--- a/frontend/discourse/admin/controllers/admin/dashboard.js
+++ b/frontend/discourse/admin/controllers/admin/dashboard.js
@@ -268,7 +268,7 @@ export default class AdminDashboardController extends Controller {
};
if (versionChecks) {
- properties.versionCheck = VersionCheck.create(model.version_check);
+ properties.versionCheck = new VersionCheck(model.version_check);
}
this.setProperties(properties);
diff --git a/frontend/discourse/admin/models/version-check.js b/frontend/discourse/admin/models/version-check.js
index cb7c655d794..b4e66633ad4 100644
--- a/frontend/discourse/admin/models/version-check.js
+++ b/frontend/discourse/admin/models/version-check.js
@@ -1,41 +1,83 @@
-import EmberObject, { computed } from "@ember/object";
import { ajax } from "discourse/lib/ajax";
-export default class VersionCheck extends EmberObject {
- static find() {
- return ajax("/admin/version_check").then((json) =>
- VersionCheck.create(json)
- );
+export default class VersionCheck {
+ static async find() {
+ return new VersionCheck(await ajax("/admin/version_check"));
+ }
+
+ constructor(json = {}) {
+ Object.assign(this, json);
}
- @computed("updated_at")
get noCheckPerformed() {
return this.updated_at === null;
}
- @computed("missing_versions_count")
get upToDate() {
return (
this.missing_versions_count === 0 || this.missing_versions_count === null
);
}
- @computed("missing_versions_count")
get behindByOneVersion() {
return this.missing_versions_count === 1;
}
- @computed("installed_sha")
get gitLink() {
- if (this.installed_sha) {
- return `https://github.com/discourse/discourse/commits/${this.installed_sha}`;
- }
+ return commitLink(this.installed_sha);
}
- @computed("installed_sha")
get shortSha() {
- if (this.installed_sha) {
- return this.installed_sha.slice(0, 10);
+ return truncateSha(this.installed_sha);
+ }
+
+ get latestGitLink() {
+ return commitLink(this.latest_sha);
+ }
+
+ get latestShortSha() {
+ return truncateSha(this.latest_sha);
+ }
+
+ get changelogLink() {
+ if (this.installed_sha && this.latest_sha) {
+ const start = this.installed_sha.slice(0, 8);
+ const end = this.latest_sha.slice(0, 8);
+ return `https://releases.discourse.org/changelog/custom?start=${start}&end=${end}`;
+ }
+ }
+
+ get installedCommitsAhead() {
+ return commitsAhead(this.installed_describe);
+ }
+
+ get latestCommitsAhead() {
+ return commitsAhead(this.latest_pretty_version);
+ }
+
+ get newerCommitsAvailable() {
+ return this.newChangesCount > 0;
+ }
+
+ get newChangesCount() {
+ if (this.latestCommitsAhead === undefined) {
+ return 0;
}
+ return this.latestCommitsAhead - (this.installedCommitsAhead ?? 0);
}
}
+
+function commitLink(sha) {
+ if (sha) {
+ return `https://github.com/discourse/discourse/commits/${sha}`;
+ }
+}
+
+function truncateSha(sha) {
+ return sha?.slice(0, 10);
+}
+
+function commitsAhead(prettyVersion) {
+ const extra = prettyVersion?.split(" +")[1];
+ return extra ? parseInt(extra, 10) : undefined;
+}
diff --git a/lib/discourse_updates.rb b/lib/discourse_updates.rb
index d68d2243431..79a571d8b99 100644
--- a/lib/discourse_updates.rb
+++ b/lib/discourse_updates.rb
@@ -14,6 +14,8 @@ module DiscourseUpdates
unless updated_at.nil?
attrs.merge!(
latest_version: latest_version,
+ latest_pretty_version: latest_pretty_version,
+ latest_sha: latest_sha,
critical_updates: critical_updates_available?,
missing_versions_count: missing_versions_count,
)
@@ -75,6 +77,22 @@ module DiscourseUpdates
Discourse.redis.set(latest_version_key, arg)
end
+ def latest_pretty_version
+ Discourse.redis.get latest_pretty_version_key
+ end
+
+ def latest_pretty_version=(arg)
+ Discourse.redis.set(latest_pretty_version_key, arg)
+ end
+
+ def latest_sha
+ Discourse.redis.get latest_sha_key
+ end
+
+ def latest_sha=(arg)
+ Discourse.redis.set(latest_sha_key, arg)
+ end
+
def missing_versions_count
Discourse.redis.get(missing_versions_count_key).try(:to_i)
end
@@ -312,6 +330,8 @@ module DiscourseUpdates
Discourse.redis.del(
last_installed_version_key,
latest_version_key,
+ latest_pretty_version_key,
+ latest_sha_key,
critical_updates_available_key,
missing_versions_count_key,
updated_at_key,
@@ -349,6 +369,14 @@ module DiscourseUpdates
"discourse_latest_version"
end
+ def latest_pretty_version_key
+ "discourse_latest_pretty_version"
+ end
+
+ def latest_sha_key
+ "discourse_latest_sha"
+ end
+
def critical_updates_available_key
"critical_updates_available"
end
diff --git a/spec/lib/discourse_updates_spec.rb b/spec/lib/discourse_updates_spec.rb
index 5baf17c2234..4f1daf62e3e 100644
--- a/spec/lib/discourse_updates_spec.rb
+++ b/spec/lib/discourse_updates_spec.rb
@@ -649,4 +649,27 @@ RSpec.describe DiscourseUpdates do
expect(DiscourseUpdates.get_last_viewed_feature_date(user.id)).to eq(time)
end
end
+
+ describe "commits ahead" do
+ before { DiscourseUpdates.last_installed_version = Discourse::VERSION::STRING }
+
+ it "rewrites the git describe suffix into a ' +N' installed_describe" do
+ Discourse.stubs(:full_version).returns("v#{Discourse::VERSION::STRING}-444-gabc1234")
+ expect(version.installed_describe).to eq("v#{Discourse::VERSION::STRING} +444")
+ end
+
+ it "leaves installed_describe without a suffix when the build sits on a tag" do
+ Discourse.stubs(:full_version).returns("v#{Discourse::VERSION::STRING}")
+ expect(version.installed_describe).to eq("v#{Discourse::VERSION::STRING}")
+ end
+
+ it "exposes the latest pretty version and sha from the version check" do
+ stub_data(Discourse::VERSION::STRING, 0, false, 12.hours.ago)
+ DiscourseUpdates.latest_pretty_version = "#{Discourse::VERSION::STRING} +444"
+ DiscourseUpdates.latest_sha = "abc1234def5678"
+
+ expect(version.latest_pretty_version).to eq("#{Discourse::VERSION::STRING} +444")
+ expect(version.latest_sha).to eq("abc1234def5678")
+ end
+ end
end