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

Update for new Ruby and Rails versions #499

Merged
merged 1 commit into from Apr 11, 2022
Merged

Conversation

BrianHawley
Copy link
Contributor

@BrianHawley BrianHawley commented Dec 21, 2021

  • Test Ruby 2.7, 3.0, and 3.1, and Rails 6.1 and 7.0.
  • Exclude incompatible test matrix combinations.
  • Show Ruby deprecation warnings in tests where supported.
  • File.exists? is deprecated; use File.exist?.
  • URI.escape and URI.decode are deprecated.
  • Add frozen string literal comments.
  • Make sure constants are frozen.
  • Make sure that the code is frozen-string safe.
  • Adjust dev dependencies for Ruby 3.0+ compatibility.
  • Fix Ruby warnings in pdfkit_spec.rb
  • Comment out bad syntax in release-drafter action.

Fixes #498

@BrianHawley
Copy link
Contributor Author

BrianHawley commented Dec 21, 2021

@serene are you still the maintainer?

I ran all the tests locally in all version combinations so I could make sure the deprecations were fixed. Once Travis runs, we should be able to see whether the config changes worked.

@BrianHawley
Copy link
Contributor Author

BrianHawley commented Jan 6, 2022

Since Ruby 3.1.0 is out now, I updated the PR to include it in its tests. The tests pass locally with no warnings.

@serene
Copy link
Contributor

serene commented Jan 6, 2022

I will add this to my list to review, but if others can put some eyes on it as well, I'd really appreciate it!

@@ -38,11 +42,11 @@ def to_s
private

def shell_safe_url
url_needs_escaping? ? URI::escape(@source) : @source
url_needs_escaping? ? URI::DEFAULT_PARSER.escape(@source) : @source
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a direct fix of the URI.escape deprecation, and has the same exact behavior, but my main concern is that I don't think this is the right escaping method.

URI.escape escapes a string for use in a URI as a query value. However, in this case, the string is being escaped for use in a shell command parameter, which doesn't really have the same requirements. For one thing, the percent-encoding that URI.escape generates might conflict with the %var environment variable syntax on Windows. There might be some other issues, but I haven't taken the time to check.

The change here has no effect on the existing behavior (except getting rid of the deprecation message), so it's probably the best to do here. However, in the long run, it's probably best to change to a more appropriate escaping method (in a separate PR).

@BrianHawley
Copy link
Contributor Author

BrianHawley commented Jan 7, 2022

I notice that the Travis CI tests didn't run. Should we set up Github Actions tests?

@serene
Copy link
Contributor

serene commented Jan 8, 2022

@BrianHawley if that's something you'd like to take on, that would be really great! Maybe as a separate PR?

@BrianHawley
Copy link
Contributor Author

@serene yes, preferably as a separate PR. For one thing, I haven't done that before, so I'd have to take time to learn how :)

@BrianHawley
Copy link
Contributor Author

I've been using a patched version of pdfkit with these changes for a month (used vendorer to automatically generate the patched version). Are we going to merge this soon and release a new version, so I can switch back to the regular gem?

@@ -6,13 +8,15 @@
add_filter 'spec/'
end

Warning[:deprecated] = true if defined?(Warning.[]=)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice PR @BrianHawley
What is the use of this line about deprecated ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes Ruby deprecation warnings show up while running tests. I used those warnings to determine and fix any future compatibility issues, when I was running the tests locally against all supported versions. It's a good trick I use at work as well. The defined?(Warning.[]=) guard is because it only applies to Ruby 2.7+.

@thomasdarde
Copy link
Contributor

Seems really nice, I did also use this version without any issues !

@github-actions
Copy link

This pull request has been marked as stale and will be automatically closed.

@dedene
Copy link

dedene commented Mar 30, 2022

We are also using this version without any issues. Can't it be merged and released?

@serene
Copy link
Contributor

serene commented Mar 30, 2022

I'm a little concerned that the build didn't run on this branch and merging it could cause issues for others.

@leonyip
Copy link
Contributor

leonyip commented Apr 3, 2022

@serene is it possible that this repo had not migrated to travis-ci.com? https://blog.travis-ci.com/2021-05-07-orgshutdown

@leonyip
Copy link
Contributor

leonyip commented Apr 3, 2022

@serene I just opened #502 for the Github Actions migration. This branch can be tested against that and should be able to merge. Thanks!

@serene
Copy link
Contributor

serene commented Apr 4, 2022

@BrianHawley Can you pull in main to get the Github actions changes?

@BrianHawley
Copy link
Contributor Author

BrianHawley commented Apr 4, 2022

@serene I pushed up a rebased version with the same test matrix changes applied to the Github Actions tests. The workflow needs approval before the tests will run.

@BrianHawley
Copy link
Contributor Author

BrianHawley commented Apr 4, 2022

Cool, looks like the exclusions worked properly.

Looks like there was an internal error in one of the 2.5.9 steps that didn't affect the other 2.5.9 steps, and it's GA code that runs before the other parts of the matrix, so it seems to just be flaky. I don't know the GA capabilities well enough, but is there a way to rerun a step?

I just pushed up a useless commit to trigger the tests again.

@BrianHawley
Copy link
Contributor Author

OK, that's not flaky. Let me check if another exclusion is needed.

@serene
Copy link
Contributor

serene commented Apr 4, 2022

Should we even be supporting 2.5 anymore?

@BrianHawley
Copy link
Contributor Author

BrianHawley commented Apr 4, 2022

I don't have a problem with leaving 2.5 support there. I mean, I don't use it, but others might need to. I'd rather keep it there long enough to figure out what the problem was. That failure was uninformative.

@leonyip
Copy link
Contributor

leonyip commented Apr 4, 2022

@BrianHawley I sent a PR to your repo with the exclusions. It ran fine on my build.

@BrianHawley
Copy link
Contributor Author

@leonyip I already made those exclusions, but I appreciate the PR. Still, it's not working in one case (which your PR also includes) with an uninformative error message, so I'm trying to figure out what's actually failing.

@leonyip
Copy link
Contributor

leonyip commented Apr 4, 2022

Might have something to do with the bundler cache, can you omit the bundler-cache: true

@BrianHawley
Copy link
Contributor Author

BrianHawley commented Apr 4, 2022

@serene I updated the default ruby version to the latest 2.6.x, and turned off the bundler cache. The workflow needs approval again.

I think that the method of selecting the Rails version isn't working well with the cache, probably because the Gemfile doesn't change even though its meaning does when that env var changes. A lot of other projects use the appraisal gem to resolve this kind of issue. We might consider switching to it here as well. (Not in this PR; possible future reference).

Update: Nope, turning off the bundler cache broke everything. What worked was updating rubygems and bundler.

@BrianHawley
Copy link
Contributor Author

BrianHawley commented Apr 4, 2022

@serene new workflow attempt needs approving.

@BrianHawley
Copy link
Contributor Author

BrianHawley commented Apr 4, 2022

I would like to squash this before merging. Last workflow approval, @serene :)

- Update default ruby version to latest 2.6 release.
- Test Ruby 2.7, 3.0, and 3.1, and Rails 6.1 and 7.0.
  Use versions as strings to make sure 3.0 tests 3.0.
- Use latest rubygems and bundler to fix the bundler cache.
- Exclude incompatible test matrix combinations.
- Show Ruby deprecation warnings in tests where supported.
- File.exists? is deprecated; use File.exist?.
- URI.escape and URI.decode are deprecated.
- Add frozen string literal comments.
- Make sure constants are frozen.
- Make sure that the code is frozen-string safe.
- Adjust dev dependencies for Ruby 3.0+ compatibility.
- Fix Ruby warnings in pdfkit_spec.rb
- Comment out bad syntax in release-drafter action.

Fixes pdfkit#498
@BrianHawley
Copy link
Contributor Author

BrianHawley commented Apr 4, 2022

@serene I had to change the Ruby version numbers to strings to make sure 3.0 tests 3.0.x, instead of 3.x (which becomes 3.1, which we already test). Could you approve the workflow again? Once this one passes, it should be good to merge.

@serene serene merged commit 965c1bb into pdfkit:master Apr 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

File.exists? is deprecated
5 participants