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

Check if HOME can change or not instead of ENV["CI"] #732

Merged
merged 2 commits into from
Aug 10, 2022

Conversation

znz
Copy link
Member

@znz znz commented Aug 2, 2022

Tests of snapshot tarball are failed, because the CIs run without write permissions to HOME.
So I want to check the desired feature instead of ENV["CI"].

https://github.com/ruby/actions/runs/7617816773?check_suite_focus=true#step:17:2135

  Failure: test_frame_filtering_works_with_unexpanded_path_and_expanded_skip_path(DEBUGGER__::BasicBacktraceTest):
    Test::Unit::AssertionFailedError: 
    --------------------
    | Debugger Session |
    --------------------
    
    > [1, 2] in /tmp/debug-20220801-16442-89w16l.rb
    > =>   1| load "~/foo.rb"
    >      2| Foo.new.bar
    > =>#0	<main> at /tmp/debug-20220801-16442-89w16l.rb:1
    > file = File.open('/home/runner/foo.rb', 'w+') { |f| f.write('class Foo; def bar; debugger; end; end') }
    > �[?2004h(rdbg) file = File.open('/home/runner/foo.rb', 'w+') { |f| f.write('class Foo; def bar; debugger; end; end') }
    > �[?2004l
  eval error: Permission denied @ rb_sysopen - /home/runner/foo.rb
    >   (rdbg)//tmp/debug-20220801-16442-89w16l.rb:1:in `initialize'
    >   (rdbg)//tmp/debug-20220801-16442-89w16l.rb:1:in `open'
    >   (rdbg)//tmp/debug-20220801-16442-89w16l.rb:1:in `<main>'
    > nil
    > c
    > �[?2004h(rdbg) c
    > �[?2004l
  /tmp/debug-20220801-16442-89w16l.rb:1:in `load': cannot load such file -- ~/foo.rb (LoadError)
    > 	from /tmp/debug-20220801-16442-89w16l.rb:1:in `<main>'

@st0012
Copy link
Member

st0012 commented Aug 2, 2022

@znz Sorry that @ko1 reminded me this may be happening but I forgot to follow up.

But I'm confused by GH Action's behavior because its document says ENV["CI"] should always be true, which applies to this repo. And we can also see it set in the build's Run env | sort step. However it's not picked up by the tests 🤔

@znz
Copy link
Member Author

znz commented Aug 2, 2022

This fails because chmod -w $HOME at https://github.com/ruby/actions/blob/9d0cf8fffecac5f9c8b8600e452021b87458d974/.github/workflows/snapshot-master.yml#L143 to check that tests does not affect normal environments.
So I want to write nothing under $HOME on CI too.

@st0012
Copy link
Member

st0012 commented Aug 2, 2022

Thanks for explanation 🙏

However, this change also allows modifying $HOME when it's run locally, which was the patch originally trying to prevent.

❯ cat ~/.rdbgrc
foo

❯ be ruby test/console/rdbg_option_test.rb -n /rc_file/
Calling `DidYouMean::SPELL_CHECKERS.merge!(error_name => spell_checker)' has been deprecated. Please call `DidYouMean.correct_error(error_name, spell_checker)' instead.
Calling `DidYouMean::SPELL_CHECKERS.merge!(error_name => spell_checker)' has been deprecated. Please call `DidYouMean.correct_error(error_name, spell_checker)' instead.
Loaded suite test/console/rdbg_option_test
Started
..
Finished in 0.49796 seconds.
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
2 tests, 12 assertions, 0 failures, 0 errors, 0 pendings, 0 omissions, 0 notifications
100% passed
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
4.02 tests/s, 24.10 assertions/s

❯ cat ~/.rdbgrc
cat: /Users/st0012/.rdbgrc: No such file or directory

I think we can summarize our needs as:

  • If it's a local environment, we don't want to modify $HOME
  • If it's a CI environment, it's fine to write files in $HOME
    • However, in ruby/actions's CI we also don't want $HOME to be writable

So maybe the conditions should be this instead?

USE_TMP_HOME = !ENV["CI"] || HOME_CANNOT_CHANGE

# startup
@pty_home_dir =
  if USE_TMP_HOME
    Dir.mktmpdir
  else
    Dir.home
  end

# shutdown
if USE_TMP_HOME
  FileUtils.remove_entry @pty_home_dir
end

ruby#732 (comment)

* If it's a local environment, we don't want to modify $HOME
* If it's a CI environment, it's fine to write files in $HOME
  * However, in ruby/actions's CI we also don't want $HOME to be writable
@znz
Copy link
Member Author

znz commented Aug 2, 2022

Thank you for your summarize.
I update the conditions.

@st0012
Copy link
Member

st0012 commented Aug 2, 2022

I can confirm it's not affecting local ~/.rdbgrc anymore. Sorry again for the trouble and thanks for the fix 😄

@ko1 ko1 merged commit 13dcca4 into ruby:master Aug 10, 2022
ono-max pushed a commit to ono-max/debug that referenced this pull request Sep 20, 2022
ruby#732 (comment)

* If it's a local environment, we don't want to modify $HOME
* If it's a CI environment, it's fine to write files in $HOME
  * However, in ruby/actions's CI we also don't want $HOME to be writable
ono-max pushed a commit to ono-max/debug that referenced this pull request Oct 29, 2022
ruby#732 (comment)

* If it's a local environment, we don't want to modify $HOME
* If it's a CI environment, it's fine to write files in $HOME
  * However, in ruby/actions's CI we also don't want $HOME to be writable
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants