Skip to content

Commit

Permalink
refactor(versioning): improve how current version and branch is deter…
Browse files Browse the repository at this point in the history
…mined and set

Refactor `Postal.version`` and `Postal.branch` and remove `Postal::VERSION`.
  • Loading branch information
adamcooke committed Mar 21, 2024
1 parent a3fab36 commit 07c6b31
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 28 deletions.
8 changes: 4 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ COPY ./docker/wait-for.sh /docker-entrypoint.sh
COPY --chown=postal . .

# Export the version
ARG VERSION=null
ARG BRANCH=null
RUN echo $VERSION > VERSION \
&& echo $BRANCH > BRANCH
ARG VERSION
ARG BRANCH
RUN if [ "$VERSION" != "" ]; then echo $VERSION > VERSION; fi \
&& if [ "$BRANCH" != "" ]; then echo $BRANCH > BRANCH; fi

# Set paths for when running in a container
ENV POSTAL_CONFIG_FILE_PATH=/config/postal.yml
Expand Down
27 changes: 21 additions & 6 deletions lib/postal/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
require "klogger"

require_relative "error"
require_relative "version"
require_relative "config_schema"
require_relative "legacy_config_source"
require_relative "signer"
Expand Down Expand Up @@ -131,7 +130,7 @@ def graylog_logging_destination
notifier.notify!(short_message: short_message, **{
facility: Config.gelf.facility,
_environment: Config.rails.environment,
_version: Postal::VERSION.to_s,
_version: Postal.version.to_s,
_group_ids: group_ids.join(" ")
}.merge(payload.transform_keys { |k| "_#{k}".to_sym }.transform_values(&:to_s)))
end
Expand Down Expand Up @@ -159,10 +158,26 @@ def change_database_connection_pool_size(new_size)
def branch
return @branch if instance_variable_defined?("@branch")

@branch = begin
path = Rails.root.join("BRANCH")
File.read(path).strip if File.exist?(path)
end
@branch ||= read_version_file("BRANCH")
end

# Return the branch name which created this release
#
# @return [String, nil]
def version
return @version if instance_variable_defined?("@version")

@version ||= read_version_file("VERSION") || "0.0.0"
end

private

def read_version_file(file)
path = Rails.root.join(file)
return unless File.exist?(path)

value = File.read(path).strip
value.empty? ? nil : value
end

end
Expand Down
18 changes: 0 additions & 18 deletions lib/postal/version.rb

This file was deleted.

0 comments on commit 07c6b31

Please sign in to comment.