Added latest version info to footer when logged in as admin
Describe the solution you'd like This is a nice to have feature. where when you are logged in as admin it would be amazing to have a notification even if it is where the version is in the footer of hey there is a updated version to your instance available. This could be something as simple as this
Version: 0.99.1 (c4f9cf89) !update available
Or we could expand it with
Version: 0.99.1 (c4f9cf89) !Version 0.102.2 is available for download
This maybe best if it is run as a job that runs like once a day or maybe every hour or 2 hours so it isnt hitting githubs servers checking on every page refresh and updates a table in the database and pull from there.
Additional context here would be the endpoint todo that can do this, with 0 being the newest release/tag
https://api.github.com/repos/manyfold3d/manyfold/tags
There is also the https://docs.github.com/en/rest/releases/releases?apiVersion=2022-11-28 but it needs a Bearer token to use where as the tag endpoint doesnt.
this could also use ghcr.io for the container endpoint so it is on each type. but It appears to be needing a API key for this endpoint to work.
Here's a quick hack I did to check feasibility:
diff --git a/app/views/application/_footer.html.erb b/app/views/application/_footer.html.erb
index 3ab39f78..a4f5cd48 100644
--- a/app/views/application/_footer.html.erb
+++ b/app/views/application/_footer.html.erb
@@ -13,6 +13,10 @@
"#{Rails.application.config.upstream_repo}/tree/#{Rails.application.config.git_sha}",
target: "_blank", rel: "noopener" %>
</li>
+ <% if current_user.is_administrator? %>
+ <li class="mb-2">Latest version: <%= "#{Rails.application.config.latest_version}" %>
+ </li>
+ <% end %>
</ul>
</div>
<div class="col-4 col-lg-2 mb-3">
diff --git a/config/initializers/app_version.rb b/config/initializers/app_version.rb
index 6a284a20..59225cd0 100644
--- a/config/initializers/app_version.rb
+++ b/config/initializers/app_version.rb
@@ -11,8 +11,13 @@ if Rails.env.development?
git_sha.strip!
app_version = `git describe --tags --abbrev=0 #{git_sha}`
app_version.strip!
+ upstream_tags = `git --no-pager ls-remote --tags --sort=-version:refname #{Rails.application.config.upstream_repo}`
+ latest_hash, latest_version, _ = upstream_tags.split(/[\n,\t]/)
+ latest_version = latest_version.gsub("refs/tags/", "")
Rails.application.config.git_sha = git_sha
Rails.application.config.app_version = app_version
+ Rails.application.config.latest_hash = latest_hash
+ Rails.application.config.latest_version = latest_version
end
end
We can easily get the upstream tags and sort descending. Then we can store this and add it to the initializer.
We can't use the API without an auth token but we can get the tags anonymously through a git ls remote. As long as semver is strictly adhered to.
The next parts to this are the cronjob to update the version number as the application is running.
I think that will only work on a git checkout, which I don't think you can do inside the docker container. Good news though, there's an atom feed for releases! https://github.com/manyfold3d/manyfold/releases.atom
We could add a scheduled sidekiq job (like CacheCleanJob or UsageReportJob) which pulls the atom feed regularly and sets the latest release in a SiteSettings.latest_version field. Then that could be displayed however appropriate in the UI.