Skip to content
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
54 changes: 54 additions & 0 deletions .github/workflows/gem_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,58 @@ jobs:
- id: set
run: echo "include=$(jq -c . ${{ inputs.gem }}/test-matrix.json)" >> "$GITHUB_OUTPUT"

# Builds one Bundler download cache (gems, compiled extensions, git checkouts,
# index) covering every cell of the gem, so test jobs stop re-downloading the
# same gems. Runs only when the gem's lockfiles change; test jobs don't wait
# for it and fall back to the previous cache until it's saved.
gem-cache:
runs-on: ubuntu-latest
timeout-minutes: 60
env:
CC: gcc-13
CXX: g++-13
BUNDLE_GLOBAL_GEM_CACHE: "true"
steps:
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0

- name: Check for an existing gem cache
id: lookup
uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
with:
path: ~/.bundle/cache
key: bundle-v1-${{ runner.os }}-${{ inputs.gem }}-${{ hashFiles(format('{0}/gemfiles/*.lock', inputs.gem)) }}
lookup-only: true

- name: Install apt packages
if: steps.lookup.outputs.cache-hit != 'true' && inputs.sqlite
run: |
sudo apt-get update
sudo apt-get install --no-install-recommends libsqlite3-dev
- name: Set up Ruby
if: steps.lookup.outputs.cache-hit != 'true'
uses: ./.github/actions/setup-mise

- name: Install every cell's gems
if: steps.lookup.outputs.cache-hit != 'true'
run: |
for cell in $(ruby bin/test --gem "${{ inputs.gem }}" -l); do
ruby bin/test --cell "$cell" --install-only
done
- name: Save gem cache
if: steps.lookup.outputs.cache-hit != 'true'
uses: actions/cache/save@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
with:
path: ~/.bundle/cache
key: ${{ steps.lookup.outputs.cache-primary-key }}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cache job failure fails the tests

Medium Severity

The new gem-cache job is not in test.needs, so spec jobs run in parallel, but it still counts toward the reusable workflow result. A timeout, bundle install flake, or cache save error fails the caller test job and skips codecov, even when every spec cell passed. That contradicts the intended fallback path where tests proceed from the previous cache.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 6a3a2f8. Configure here.


test:
needs: matrix
env:
CC: gcc-13
CXX: g++-13
BUNDLE_GLOBAL_GEM_CACHE: "true"
defaults:
run:
working-directory: ${{ inputs.gem }}
Expand Down Expand Up @@ -96,6 +143,13 @@ jobs:
- name: Set up Ruby
uses: ./.github/actions/setup-mise

- name: Restore gem cache
uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
with:
path: ~/.bundle/cache
key: bundle-v1-${{ runner.os }}-${{ inputs.gem }}-${{ hashFiles(format('{0}/gemfiles/*.lock', inputs.gem)) }}
restore-keys: bundle-v1-${{ runner.os }}-${{ inputs.gem }}-

- name: Run specs
env:
MATRIX_ENTRY: ${{ toJson(matrix) }}
Expand Down
16 changes: 13 additions & 3 deletions bin/test
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
# bin/test --cell <cell> spec/sentry/client_spec.rb # forward args to rspec
# bin/test --cell <cell> -- --tag foo # everything after -- goes to rspec
# bin/test --cell <cell> --rake # run `bundle exec rake` like CI
# bin/test --cell <cell> --install-only # install the cell's gems, run nothing
#
# The Ruby must already be installed (`mise --env ci install`).
#
Expand Down Expand Up @@ -70,6 +71,7 @@ opts = {
entry: nil,
gem: nil,
rake: false,
install_only: false,
list: false
}

Expand All @@ -79,6 +81,7 @@ parser = OptionParser.new do |o|
o.on("--entry JSON", "Cell to run, from a test-matrix.json entry (pairs with --gem/cwd).") { |v| opts[:entry] = v }
o.on("--gem NAME", "Gem to run (auto-picks newest installed Ruby cell); scopes -l.") { |v| opts[:gem] = v }
o.on("--rake", "Run `bundle exec rake` (full CI task) instead of rspec.") { opts[:rake] = true }
o.on("--install-only", "Install the cell's gems and exit without running anything.") { opts[:install_only] = true }
o.on("-l", "--list", "List every cell's wrapper path, one per line; do nothing.") { opts[:list] = true }
o.on("-h", "--help") { puts o; exit 0 }
end
Expand Down Expand Up @@ -131,7 +134,14 @@ env["JRUBY_OPTS"] = "--debug" if cell.ruby.include?("jruby") # for more accurate
# `git` or tab-completion resolves too — both forms name the same file.
rspec_args = rspec_args.map { |a| a.sub(%r{\A(?:\./)?#{Regexp.escape(gem)}/}, "") }

test_cmd = opts[:rake] ? ["rake"] : ["rspec", *rspec_args]
test_cmd =
if opts[:install_only]
[]
elsif opts[:rake]
["rake"]
else
["rspec", *rspec_args]
end

# Ensure the cell's gems are present before running. The wrapper is committed,
# but write it if absent so a freshly added matrix row still works. Args reach
Expand All @@ -142,11 +152,11 @@ RUN = <<~SH
mkdir -p "$(dirname "$BUNDLE_GEMFILE")"
[ -f "$BUNDLE_GEMFILE" ] || echo 'eval_gemfile "../Gemfile"' > "$BUNDLE_GEMFILE"
bundle check >/dev/null 2>&1 || bundle install
exec bundle exec "$@"
[ "$#" -eq 0 ] || exec bundle exec "$@"
SH

puts "#{color('→', CYAN)} #{color(cell.label, BOLD)} #{color("(ruby #{cell.ruby})", DIM)}"
puts " #{color(test_cmd.join(' '), DIM)}"
puts " #{color(test_cmd.empty? ? "bundle install" : test_cmd.join(' '), DIM)}"

# bash -c (not -lc): inherit the env mise just set; a login shell would reset
# Ruby to the host default. $0 is a label; "$@" is the test command.
Expand Down
Loading