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

Consolidate Gemfiles; improve and simplify CI workflow #1002

Merged
merged 8 commits into from
Oct 20, 2023

Conversation

mattbrictson
Copy link
Contributor

@mattbrictson mattbrictson commented Oct 20, 2023

The goal of this PR is to improve the long-term maintainability of vcr by greatly simplifying the CI infrastructure and improving its troubleshooting output.

Improving troubleshooting output

Before, cucumber and rspec commands had their stderr output redirected to a temporary file. The contents of this file were never explicitly printed or archived. If the command failed (as recently happened in #995), maintainers would be flying blind in terms of understanding the failure.

With the changes of this PR, the redirection of stderr still exists, but if a command fails, the stderr output is explicitly printed to the console prior to the CI job exiting. This allows maintainers to see what went wrong in failure scenarios.

Fixes #1000.

Simplifying Gemfiles and CI infrastructure

Before, the CI workflow was organized as a 1:1 conversion of a previous Travis CI setup, which was structured as one big CI script and multiple Gemfiles.

Over the years, the vcr project dropped the appraisal gem in favor of manually managing Gemfile variants. The project also at times tested JRuby and Rubinius, before removing them from CI. These changes and experiments have left a lot of cruft in the testing infrastructure.

This PR performs several cleanup operations:

  1. Removes extra complexity of supporting JRuby and Rubinius. These runtimes were not being tested, so the complexity did not serve a purpose.
  2. Removes separate Gemfiles. The Gemfile.faraday-1.0.0 file, for example, had an overlapping version specification with the one in vcr.gemspec, effectively making it redundant. In the past, CI was configured to run against different major versions of some key dependencies, but that is no longer the case. Now the multiple Gemfiles do not have any benefit. This PR merges them all into a single Gemfile.
  3. Splits the rspec, cucumber, and yard CI steps into parallel jobs. This is something that is easy to do in GitHub Actions that was probably prohibitively difficult in TravisCI. The parallel jobs increase performance and have other benefits.
  4. Moves the stderr output redirection and warning detection logic out of the CI workflow and into a dedicated bash script.

My hope is that with fewer Gemfiles to maintain, and a more familiar GitHub Actions workflow, this PR will make vcr more approachable to maintainers and contributors going forward.

It has been several years since this project was tested under jruby or
rbx in CI. This commit removes non-MRI complexity from the Gemfiles that
is not needed, since non-MRI platforms are not being tested.
The base Gemfile already restricted faraday to versions `< 2`, so the
extra `Gemfile.faraday-1.0.0` was redundant. This commit removes that
separate Gemfile and merges its dependencies into the main Gemfile.
@@ -1,69 +1,56 @@
name: vcr ci
name: CI
Copy link
Contributor Author

Choose a reason for hiding this comment

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

🗒️ I shortened this name for more concise output.

Screenshot 2023-10-19 at 5 49 31 PM


on:
push:
branches: [ master ]
branches: [master]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

🗒️ I ran this file through Prettier to apply standard YAML formatting and indentation.

pull_request:
types: [opened, synchronize, reopened]

jobs:
test:
cucumber:
Copy link
Contributor Author

Choose a reason for hiding this comment

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

🗒️ I separated rspec, cucumber, yard steps into their own jobs for the following reasons:

  1. CI can complete faster, since jobs run in parallel.
  2. Developers see more precise status about which parts of CI are passing/failing.
  3. The yard step can be optimized to run with less setup, because it doesn't need the apt-get steps.


- name: faraday-1.0.0
run: |
bundle install
Copy link
Contributor Author

Choose a reason for hiding this comment

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

🗒️ The old CI setup had multiple invocations of bundle install with different Gemfiles. There were not any important differences between the Gemfiles, so I removed these redundant installations and consolidated dependencies to a single Gemfile.


- name: check warnings
run: |
vcr_warnings="$(grep -F "$PWD" "${ALL_WARNINGS}" | grep "warning: " | grep -v "${PWD}/vendor/bundle" | sort | uniq -c | tee /dev/stderr | wc -l)"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

🗒️ I moved the warning detection code into a new dedicated bash script, script/fail_if_warnings.

gemspec

gem 'jruby-openssl', :platforms => :jruby
Copy link
Contributor Author

Choose a reason for hiding this comment

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

🗒️ CI has not tested against JRuby in quite a long time. There was extra complexity for non-MRI runtimes in the Gemfiles that was not providing any benefit, because CI was never being run on anything besides MRI. I decided to remove this complexity and write the Gemfile assuming MRI.

gem "em-http-request"
gem "curb", "~> 1.0.1"
end
gem "aruba", "~> 0.14.14"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

🗒️ I moved all development dependencies out of vcr.gemspec and into the main Gemfile. The standard project structure recommended by bundle init these days advocates for organizing dev dependencies in this way.

warnings=/tmp/vcr_warnings.out
touch "${warnings}"

RUBYOPT=-w bundle exec "$@" 2> "${warnings}" || { cat "${warnings}" > /dev/stderr; exit 1; }
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 pipes stderr from the Ruby process to a warnings file. If the Ruby process fails for whatever reason, the warnings file is printed to the console and the script exits. This fixes a problem with the old CI script where stderr was being swallowed if the Ruby process crashed. Now we can easily troubleshoot when this happens.

Comment on lines +14 to +15
warnings_count="$(grep -F "$PWD" "${warnings}" | grep "warning: " | grep -v "${PWD}/vendor/bundle" | sort | uniq -c | tee /dev/stderr | wc -l)"
if [[ "${warnings_count}" -gt 0 ]]; then echo "FAILED: test suite doesn't tolerate warnings"; exit 1; fi
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 code is unmodified from its previous version. I simply moved it out of the Actions workflow into this script and renamed some variables for clarity.

@@ -20,25 +20,4 @@ Gem::Specification.new do |spec|
spec.require_paths = ["lib"]

spec.required_ruby_version = ">= 2.7"

spec.add_development_dependency "bundler", "~> 2.0"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

🗒️ These dependencies are now declared in the Gemfile.

Comment on lines +46 to +53
doc-coverage:
name: "Doc coverage"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: ruby/setup-ruby@v1
with:
ruby-version: "ruby"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

🗒️ I assumed that running the yard coverage check against a matrix of multiple versions of Ruby was overkill. I changed it to run on the latest version of Ruby only.

If you get an error while running `bundle install`, it may be one of the "extras" gems which are not required for development. Try installing it without these gems.

```console
bundle install --without extras
Copy link
Contributor Author

Choose a reason for hiding this comment

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

🗒️ There is no extras group in the Gemfile, so this documentation was misleading. I removed it to prevent confusion.

Copy link
Member

@olleolleolle olleolleolle left a comment

Choose a reason for hiding this comment

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

Thank you, @mattbrictson! I agree with all the changes, and thanks also for all the context-preserving notes in the Description and comments of this PR.

@olleolleolle olleolleolle merged commit bf8e1b0 into vcr:master Oct 20, 2023
@mattbrictson mattbrictson deleted the chores/simplify-gems-and-ci branch October 20, 2023 13:49
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.

CI: Failures are prohibitively difficult to troubleshoot
2 participants