Add real release version into the running code (#14870)

* Add real release version into the running code

* Fix warnings
This commit is contained in:
Jamie Gaskins 2021-10-04 09:35:20 -04:00 committed by GitHub
parent bbc79821d0
commit 3801789e8f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 1 deletions

View file

@ -13,7 +13,7 @@ module Api
name: Settings::Community.community_name,
registered_users_count: User.registered.estimated_count,
tagline: Settings::Community.tagline,
version: "edge.#{Time.now.utc.strftime('%Y%m%d')}.0",
version: release_version,
visibility: visibility
}, status: :ok
end
@ -25,6 +25,24 @@ module Api
Settings::UserExperience.public ? "public" : "private"
end
def release_version
File.read(Rails.root.join(".release-version"))
# Accommodate the .release-version file not existing in the case where
# this deployment is deployed from a checkout/snapshot of the code.
rescue StandardError
# Get the latest modified file in the app. We don't use git in case it's
# being run from a snapshot of the code outside a git repo (for example:
# https://github.com/forem/forem/archive/refs/heads/main.zip), but
# instead we use the latest modified time ("mtime") from application
# code.
latest_mtime = Dir[Rails.root.join("{app,config,db,lib}/**/*")]
.max_by { |filename| File.mtime(filename) }
.then { |filename| File.mtime(filename) }
"edge.#{latest_mtime.strftime('%Y%m%d')}.0"
end
end
end
end

View file

@ -69,6 +69,9 @@ begin
puts "Merged #{source} into #{channel}"
begin
run "echo '#{tag}' > .release-version"
run "git add .release-version"
run "git commit --message 'Version #{tag}'"
run "git tag #{tag}"
puts "Tagged #{tag}"
rescue StandardError