Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/no commit hash on the deployed project #611

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .controlplane/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,7 @@ ENTRYPOINT ["./.controlplane/entrypoint.sh"]
# Default args to pass to the entry point that can be overridden
# For Kubernetes and ControlPlane, these are the "workload args"
CMD ["./bin/rails", "server"]

# Current commit hash environment variable
ARG GIT_COMMIT_SHA
ENV GIT_COMMIT_SHA=${GIT_COMMIT_SHA}
4 changes: 3 additions & 1 deletion app/models/git_commit_sha.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ class GitCommitSha
attr_writer :current_sha

def self.current_sha
@current_sha ||= retrieve_sha_from_file.presence || retrieve_sha_from_git
@current_sha ||= ENV["GIT_COMMIT_SHA"].presence ||
retrieve_sha_from_file.presence ||
retrieve_sha_from_git
end

def self.reset_current_sha
Expand Down
23 changes: 19 additions & 4 deletions spec/system/pages_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,16 @@
GitCommitSha.reset_current_sha
end

context "when .source_version file does not exist" do
let(:sha) { "94d92356828a56db25fccff9d50f41c525eead5x" }
context "when GIT_COMMIT_SHA env var exists" do
let(:sha) { "94d92356828a56db25fccff9d50f41c525eead5z" }
let(:expected_text) { "94d9235" }

before do
# stub this method since we need to control what the sha actually is
allow(GitCommitSha).to receive(:retrieve_sha_from_git) { sha }
ENV["GIT_COMMIT_SHA"] = sha
end

after do
ENV.delete("GIT_COMMIT_SHA")
end

it_behaves_like "Git Commit SHA"
Expand All @@ -39,4 +42,16 @@

it_behaves_like "Git Commit SHA"
end

context "when falling back to git command" do
let(:sha) { "94d92356828a56db25fccff9d50f41c525eead5x" }
let(:expected_text) { "94d9235" }

before do
# stub this method since we need to control what the sha actually is
allow(GitCommitSha).to receive(:retrieve_sha_from_git) { sha }
end

it_behaves_like "Git Commit SHA"
end
end
Loading