⚠ This page is served via a proxy. Original site: https://github.com
This service does not collect credentials or authentication data.
Skip to content
Merged
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
5 changes: 5 additions & 0 deletions .github/actions/test_ruby_gem_uploads/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,8 @@
source 'https://rubygems.org'

gem 'rspec'
gem 'knapsack_pro'
gem 'rake'
gem 'rake-compiler'
gem 'logger'
gem 'rspec_trunk_flaky_tests', :path => '../../../rspec-trunk-flaky-tests'
40 changes: 40 additions & 0 deletions .github/actions/test_ruby_gem_uploads/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Running Ruby Tests Locally

If you want to locally run the ruby smoke tests that are run in CI, run:

From `cd rspec-trunk-flaky-tests`:

1. `cd rspec-trunk-flaky-tests`
2. `bundle install`
3. `bundle exec rake build`
4. `cd ../.github/actions/test_ruby_gem_uploads`
5. Verify [Gemfile](./Gemfile) points to the built gem, i.e. `gem 'rspec_trunk_flaky_tests', :path => '../../../rspec-trunk-flaky-tests'`
6. Run `bundle exec rspec spec/variant_quarantine_spec.rb --format documentation`

After `cd .github/actions/test_ruby_gem_uploads`

See more in the [rspec README.md](../../../rspec-trunk-flaky-tests/README.md).

## Knapsack Pro

Repeat steps 1-5 above, and run:

```bash
export KNAPSACK_PRO_CI_NODE_BUILD_ID=$(openssl rand -base64 32)
export KNAPSACK_PRO_TEST_DIR=spec
export KNAPSACK_PRO_TEST_FILE_PATTERN="**/*.rb"
export KNAPSACK_PRO_PROJECT_DIR=.
export KNAPSACK_PRO_REPOSITORY_ADAPTER=git
export KNAPSACK_PRO_LOG_LEVEL=debug
export KNAPSACK_PRO_TEST_SUITE_TOKEN_RSPEC="<api-key>"
export KNAPSACK_PRO_CI_NODE_TOTAL=1
export KNAPSACK_PRO_CI_NODE_INDEX=0
export KNAPSACK_PRO_FIXED_QUEUE_SPLIT=false

bundle exec rake "knapsack_pro:queue:rspec:initialize"
bundle exec rake "knapsack_pro:queue:rspec"
```

### Reference

- [More information about Queue Mode](https://docs.knapsackpro.com/ruby/queue-mode/)
5 changes: 5 additions & 0 deletions .github/actions/test_ruby_gem_uploads/Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
require 'rake/testtask'
require 'rake/extensiontask'
require 'knapsack_pro'
require 'rspec/core/rake_task'
KnapsackPro.load_tasks if defined?(KnapsackPro)
58 changes: 57 additions & 1 deletion .github/actions/test_ruby_gem_uploads/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ inputs:
platform:
description: The platform that the gem was built for
required: true
knapsack-pro-test-suite-token-rspec:
description: Optional Knapsack Pro test suite token for RSpec
required: true

runs:
using: composite
Expand Down Expand Up @@ -63,8 +66,8 @@ runs:
gem unpack "${GEM_FILE}" --target=rspec_trunk_flaky_tests
mv rspec_trunk_flaky_tests/rspec_trunk_flaky_tests*/lib rspec_trunk_flaky_tests/lib
bundle install
sed -i "s|gem 'rspec_trunk_flaky_tests'.*|gem 'rspec_trunk_flaky_tests', '${GEM_VERSION}', :path => './rspec_trunk_flaky_tests'|" Gemfile
bundle lock --remove-platform ruby || true
echo "gem 'rspec_trunk_flaky_tests', '${GEM_VERSION}', :path => './rspec_trunk_flaky_tests'" >> Gemfile
bundle install --gemfile Gemfile --local

- name: Run regular tests
Expand Down Expand Up @@ -117,3 +120,56 @@ runs:
TRUNK_ORG_URL_SLUG: ${{ inputs.trunk-org-slug }}
TRUNK_API_TOKEN: ${{ inputs.trunk-token }}
TRUNK_VARIANT: smoke-test-variant

- name: Run knapsack_pro queue and verify a single local bundle
shell: bash
if: inputs.knapsack-pro-test-suite-token-rspec != ''
working-directory: ${{ github.action_path }}
env:
KNAPSACK_PRO_TEST_DIR: spec
# Required when using queue intialization
KNAPSACK_PRO_TEST_FILE_PATTERN: spec/*.rb
KNAPSACK_PRO_TEST_SUITE_TOKEN_RSPEC: ${{ inputs.knapsack-pro-test-suite-token-rspec }}
KNAPSACK_PRO_CI_NODE_TOTAL: 1
KNAPSACK_PRO_CI_NODE_INDEX: 0
# https://docs.knapsackpro.com/ruby/queue-mode/#dynamic-split-vs-fixed-split
KNAPSACK_PRO_FIXED_QUEUE_SPLIT: false
TRUNK_API_TOKEN: ${{ inputs.trunk-token }}
TRUNK_ORG_URL_SLUG: ${{ inputs.trunk-org-slug }}
TRUNK_PUBLIC_API_ADDRESS: ${{ inputs.trunk-public-api-address }}
TRUNK_LOCAL_UPLOAD_DIR: bundles
run: |
set -euo pipefail
rm -rf "${TRUNK_LOCAL_UPLOAD_DIR}"
mkdir -p "${TRUNK_LOCAL_UPLOAD_DIR}"
set +e
# Initialize is not required, but some custom setups will use it
bundle exec rake "knapsack_pro:queue:rspec:initialize"

FILE_COUNT=$(find "${TRUNK_LOCAL_UPLOAD_DIR}" -maxdepth 1 -type f 2>/dev/null | wc -l)
if [ "${FILE_COUNT}" -ne 0 ]; then
echo "knapsack_pro manual queue initialization should not trigger an upload"
ls -la "${TRUNK_LOCAL_UPLOAD_DIR}"
exit 1
fi

OUTPUT_FILE=$(mktemp)
bundle exec rake "knapsack_pro:queue:rspec" 2>&1 | tee "${OUTPUT_FILE}"
set -e
OUTPUT=$(cat "${OUTPUT_FILE}")
rm -f "${OUTPUT_FILE}"

FILE_COUNT=$(find "${TRUNK_LOCAL_UPLOAD_DIR}" -maxdepth 1 -type f 2>/dev/null | wc -l)
if [ "${FILE_COUNT}" -ne 1 ]; then
echo "knapsack_pro execution run should trigger an upload"
ls -la "${TRUNK_LOCAL_UPLOAD_DIR}"
exit 1
fi

REPORT_COUNT=$(echo "${OUTPUT}" | grep -c "Local Flaky tests report generated" || echo "0")
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I acknowledge this type of assertion is brittle. I don't have a better alternative at the moment without exposing more output information from the impl itself. Imo this is fine for now, and the DevEx story is now sane enough that we can revisit when we do have more time and ideas

if [ "${REPORT_COUNT}" -ne 1 ]; then
echo "Expected 'Local Flaky tests report generated' to appear exactly once, found ${REPORT_COUNT} times"
exit 1
fi

echo "Knapsack run correctly generated exactly one bundle"
5 changes: 5 additions & 0 deletions .github/actions/test_ruby_gem_uploads/spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# frozen_string_literal: true

require 'trunk_spec_helper'
if ENV['KNAPSACK_PRO_TEST_SUITE_TOKEN_RSPEC']
# Enable Knapsack queueing when CI provides a suite token
require 'knapsack_pro'
KnapsackPro::Adapters::RSpecAdapter.bind
end
# This file was generated by the `rspec --init` command. Conventionally, all
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
# The generated `.rspec` file contains `--require spec_helper` which will cause
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/release_ruby_gem.yml
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ jobs:
trunk-token: ${{ secrets.TRUNK_STAGING_ORG_API_TOKEN }}
platform: ${{ matrix.platform.name }}
artifact-pattern: cross-gem-${{ matrix.platform.name }}
knapsack-pro-test-suite-token-rspec: ${{ secrets.KNAPSACK_PRO_TEST_SUITE_TOKEN_RSPEC }}

publish_ruby_gem:
runs-on: ubuntu-latest
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/smoke_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ jobs:
trunk-org-slug: trunk-staging-org
platform: x86_64-linux
artifact-pattern: ""
knapsack-pro-test-suite-token-rspec: ${{ secrets.KNAPSACK_PRO_TEST_SUITE_TOKEN_RSPEC }}

test_ruby_gem_production:
name: Test Ruby gem on production
Expand All @@ -151,6 +152,7 @@ jobs:
trunk-org-slug: trunk
platform: x86_64-linux
artifact-pattern: ""
knapsack-pro-test-suite-token-rspec: ${{ secrets.KNAPSACK_PRO_TEST_SUITE_TOKEN_RSPEC }}

production-slack-workflow-status:
if: always() && github.ref == 'refs/heads/main' && (needs.build_cli.outputs.production-success != 'true' || needs.test_ruby_gem_production.result != 'success')
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/smoke_test_main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ jobs:
trunk-org-slug: trunk-staging-org
platform: x86_64-linux
artifact-pattern: ""
knapsack-pro-test-suite-token-rspec: ${{ secrets.KNAPSACK_PRO_TEST_SUITE_TOKEN_RSPEC }}

test_ruby_gem_production:
name: Test Ruby gem on production
Expand All @@ -252,6 +253,7 @@ jobs:
trunk-org-slug: trunk
platform: x86_64-linux
artifact-pattern: ""
knapsack-pro-test-suite-token-rspec: ${{ secrets.KNAPSACK_PRO_TEST_SUITE_TOKEN_RSPEC }}

production-slack-workflow-status:
if: always() && github.ref == 'refs/heads/main' && (needs.test_cli.result != 'success' || needs.test_ruby_gem_production.result != 'success')
Expand Down
3 changes: 2 additions & 1 deletion rspec-trunk-flaky-tests/lib/trunk_spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ def knapsack_detector_mode?

def knapsack_detector_command?
command_line = "#{$PROGRAM_NAME} #{ARGV.join(' ')}".strip
command_line.include?('knapsack_pro:rspec_test_example_detector')
command_line.include?('knapsack_pro:rspec_test_example_detector') ||
command_line.include?('knapsack_pro:queue:rspec:initialize')
end

def trunk_disabled
Expand Down
Loading