Skip to content

Commit

Permalink
Use Dir.pwd instead of ENV['PWD'] in Capistrano integration (#848)
Browse files Browse the repository at this point in the history
* Use Dir.pwd instead of ENV['PWD']

I'm using a pretty different setup for my Deploy with Capistrano, which
includes deploying from a dev container in rootless podman, using the
Ruby on Whales guide, with some changes.

I don't know exactly why it happens, but when deploying ENV["PWD"]
returns nil. I tinkered a little and it seems that Dir.pwd is more
reliable.

* Use Dir.chdir to mock directory in Capistrano spec

Instead of mocking the `Dir.pwd` method, switch the current directory to
what the test expects it to be. This doesn't interfere with our internal
test system.

Co-authored-by: Tomás Coêlho <tomascoelho6@gmail.com>
Co-authored-by: Tom de Bruijn <tom@tomdebruijn.com>
  • Loading branch information
3 people authored May 30, 2022
1 parent 4f99623 commit 7032dc4
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
6 changes: 6 additions & 0 deletions .changesets/use-dir-pwd-for-capistrano-3-current-directory.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
bump: "patch"
type: "fix"
---

Use `Dir.pwd` to determine the current directory in the Capistrano 3 integration. It previously relied on `ENV["pwd"]` which returned `nil` in some scenarios.
2 changes: 1 addition & 1 deletion lib/appsignal/integrations/capistrano/appsignal.cap
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace :appsignal do
revision = fetch(:appsignal_revision, fetch(:current_revision))

appsignal_config = Appsignal::Config.new(
ENV["PWD"],
Dir.pwd,
appsignal_env,
{},
Logger.new(StringIO.new)
Expand Down
6 changes: 5 additions & 1 deletion spec/lib/appsignal/capistrano3_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,11 @@ def run
describe "appsignal:deploy task" do
before do
ENV["USER"] = "batman"
ENV["PWD"] = project_fixture_path
end
around do |example|
Dir.chdir project_fixture_path do
example.run
end
end

context "config" do
Expand Down

0 comments on commit 7032dc4

Please sign in to comment.