From 693910f59d35bcef5c9e3c3ea6b0f92582cf51a8 Mon Sep 17 00:00:00 2001 From: Andrey Date: Fri, 31 May 2024 15:24:05 +0200 Subject: [PATCH 01/14] upgrade some GHA, add datadog-static-analysis workflow --- .../add-milestone-to-pull-requests.yml | 2 +- .github/workflows/build-gem.yml | 6 +++--- .github/workflows/check.yml | 4 ++-- .github/workflows/datadog-static-analysis.yml | 21 +++++++++++++++++++ .github/workflows/yard.yml | 2 +- 5 files changed, 28 insertions(+), 7 deletions(-) create mode 100644 .github/workflows/datadog-static-analysis.yml diff --git a/.github/workflows/add-milestone-to-pull-requests.yml b/.github/workflows/add-milestone-to-pull-requests.yml index fed57269..2ff00b17 100644 --- a/.github/workflows/add-milestone-to-pull-requests.yml +++ b/.github/workflows/add-milestone-to-pull-requests.yml @@ -10,7 +10,7 @@ jobs: steps: - name: Checkout code # Checks out the branch that the pull request is merged into - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: ref: ${{ github.event.pull_request.base.ref }} diff --git a/.github/workflows/build-gem.yml b/.github/workflows/build-gem.yml index 626c987a..44839d90 100644 --- a/.github/workflows/build-gem.yml +++ b/.github/workflows/build-gem.yml @@ -28,9 +28,9 @@ jobs: steps: - name: Checkout uses: actions/checkout@v4 - - uses: ruby/setup-ruby@31a7f6d628878b80bc63375a93ae079ec50a1601 # v1.143.0 + - uses: ruby/setup-ruby@v1 with: - ruby-version: '3.2' + ruby-version: '3.3' bundler-cache: true # runs 'bundle install' and caches installed gems automatically - name: Patch version if: ${{ matrix.type != 'final' }} @@ -122,7 +122,7 @@ jobs: find pkg - uses: ruby/setup-ruby@31a7f6d628878b80bc63375a93ae079ec50a1601 # v1.143.0 with: - ruby-version: '3.2' + ruby-version: '3.3' - name: Install gem run: | gem install pkg/*.gem diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index ea256174..b2949916 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -11,9 +11,9 @@ jobs: runs-on: ubuntu-22.04 steps: - uses: actions/checkout@v4 - - uses: ruby/setup-ruby@31a7f6d628878b80bc63375a93ae079ec50a1601 # v1.143.0 + - uses: ruby/setup-ruby@v1 with: - ruby-version: '3.2' + ruby-version: '3.3' bundler-cache: true # runs 'bundle install' and caches installed gems automatically - name: Check for stale signature files run: bundle exec rake rbs:stale diff --git a/.github/workflows/datadog-static-analysis.yml b/.github/workflows/datadog-static-analysis.yml new file mode 100644 index 00000000..be35a97f --- /dev/null +++ b/.github/workflows/datadog-static-analysis.yml @@ -0,0 +1,21 @@ +on: [push] + +name: Datadog Static Analysis + +jobs: + static-analysis: + runs-on: ubuntu-latest + name: Datadog Static Analyzer + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Check code meets quality and security standards + id: datadog-static-analysis + uses: DataDog/datadog-static-analyzer-github-action@v1 + with: + dd_api_key: ${{ secrets.DD_API_KEY }} + dd_app_key: ${{ secrets.DD_APP_KEY }} + dd_service: datadog-ci-rb + dd_env: ci + dd_site: datadoghq.com + cpu_count: 2 diff --git a/.github/workflows/yard.yml b/.github/workflows/yard.yml index 30f63046..800d5fd8 100644 --- a/.github/workflows/yard.yml +++ b/.github/workflows/yard.yml @@ -30,7 +30,7 @@ jobs: uses: actions/checkout@v4 - uses: ruby/setup-ruby@v1 with: - ruby-version: '3.2' + ruby-version: '3.3' bundler-cache: true - name: Generate YARD documentation run: bundle exec rake docs From 71be50e79cb8fc9b8f135fa31afdfc11f2011094 Mon Sep 17 00:00:00 2001 From: Andrey Date: Fri, 31 May 2024 15:32:51 +0200 Subject: [PATCH 02/14] update outdated setup-ruby action --- .github/workflows/build-gem.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build-gem.yml b/.github/workflows/build-gem.yml index 44839d90..af52a690 100644 --- a/.github/workflows/build-gem.yml +++ b/.github/workflows/build-gem.yml @@ -120,7 +120,7 @@ jobs: - name: List gem run: | find pkg - - uses: ruby/setup-ruby@31a7f6d628878b80bc63375a93ae079ec50a1601 # v1.143.0 + - uses: ruby/setup-ruby@v1 with: ruby-version: '3.3' - name: Install gem From 6b8b314509413b5d343b1c09bd19951af74b5a21 Mon Sep 17 00:00:00 2001 From: Andrey Date: Fri, 31 May 2024 15:43:20 +0200 Subject: [PATCH 03/14] try to ignore some rules --- static-analysis.datadog.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/static-analysis.datadog.yml b/static-analysis.datadog.yml index 67a2b9d4..4aa6b588 100644 --- a/static-analysis.datadog.yml +++ b/static-analysis.datadog.yml @@ -1,6 +1,8 @@ rulesets: - ruby-code-style - ruby-security - - ruby-best-practices - - rails-best-practices + - ruby-best-practices: + rules: + symbols-as-keys: + ignore: '**' ignorePaths: [] From bfd345d7d5b1f1661584a7b246d18035cb4ca689 Mon Sep 17 00:00:00 2001 From: Andrey Date: Fri, 31 May 2024 15:45:10 +0200 Subject: [PATCH 04/14] try ignoring the rule in a different way --- static-analysis.datadog.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/static-analysis.datadog.yml b/static-analysis.datadog.yml index 4aa6b588..87160355 100644 --- a/static-analysis.datadog.yml +++ b/static-analysis.datadog.yml @@ -4,5 +4,6 @@ rulesets: - ruby-best-practices: rules: symbols-as-keys: - ignore: '**' + ignore: + - '**' ignorePaths: [] From 50a46d4f8b6a68dd07843127928ff50597a440c9 Mon Sep 17 00:00:00 2001 From: Andrey Date: Fri, 31 May 2024 17:19:36 +0200 Subject: [PATCH 05/14] ignore hash fetch rule for specs --- static-analysis.datadog.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/static-analysis.datadog.yml b/static-analysis.datadog.yml index 87160355..d8f521f4 100644 --- a/static-analysis.datadog.yml +++ b/static-analysis.datadog.yml @@ -6,4 +6,8 @@ rulesets: symbols-as-keys: ignore: - '**' + hash-fetch: + ignore: + - 'spec/**/*' + ignorePaths: [] From e83688a0da1bcf23cd462ece556d9d6608ac777c Mon Sep 17 00:00:00 2001 From: Andrey Date: Mon, 3 Jun 2024 10:29:20 +0200 Subject: [PATCH 06/14] fixing violations --- Appraisals | 16 ++++------------ .../ci/test_visibility/serializers/span.rb | 4 ++-- static-analysis.datadog.yml | 5 ++--- 3 files changed, 8 insertions(+), 17 deletions(-) diff --git a/Appraisals b/Appraisals index 87ae4f44..b23fbbac 100644 --- a/Appraisals +++ b/Appraisals @@ -3,27 +3,19 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) module DisableBundleCheck def check_command - ["bundle", "exec", "false"] + %w[bundle exec false] end end -if ["true", "y", "yes", "1"].include?(ENV["APPRAISAL_SKIP_BUNDLE_CHECK"]) +if %w[true y yes 1].include?(ENV["APPRAISAL_SKIP_BUNDLE_CHECK"]) ::Appraisal::Appraisal.prepend(DisableBundleCheck) end alias original_appraise appraise REMOVED_GEMS = { - check: [ - "rbs", - "steep" - ], - development: [ - "ruby-lsp", - "ruby-lsp-rspec", - "debug", - "irb" - ] + check: %w[rbs steep], + development: %w[ruby-lsp ruby-lsp-rspec debug irb] } def appraise(group, &block) diff --git a/lib/datadog/ci/test_visibility/serializers/span.rb b/lib/datadog/ci/test_visibility/serializers/span.rb index 07caefe2..d3b2b66f 100644 --- a/lib/datadog/ci/test_visibility/serializers/span.rb +++ b/lib/datadog/ci/test_visibility/serializers/span.rb @@ -7,11 +7,11 @@ module CI module TestVisibility module Serializers class Span < Base - CONTENT_FIELDS = (["trace_id", "span_id", "parent_id"] + Base::CONTENT_FIELDS).freeze + CONTENT_FIELDS = (%w[trace_id span_id parent_id] + Base::CONTENT_FIELDS).freeze CONTENT_MAP_SIZE = calculate_content_map_size(CONTENT_FIELDS) - REQUIRED_FIELDS = (["trace_id", "span_id"] + Base::REQUIRED_FIELDS).freeze + REQUIRED_FIELDS = (%w[trace_id span_id] + Base::REQUIRED_FIELDS).freeze def content_fields CONTENT_FIELDS diff --git a/static-analysis.datadog.yml b/static-analysis.datadog.yml index d8f521f4..a7108546 100644 --- a/static-analysis.datadog.yml +++ b/static-analysis.datadog.yml @@ -1,3 +1,4 @@ +schema-version: v1 rulesets: - ruby-code-style - ruby-security @@ -8,6 +9,4 @@ rulesets: - '**' hash-fetch: ignore: - - 'spec/**/*' - -ignorePaths: [] + - spec/**/* From 1514898f13b1f50b6014c00904384b56e24ceb03 Mon Sep 17 00:00:00 2001 From: Andrey Date: Mon, 3 Jun 2024 10:46:39 +0200 Subject: [PATCH 07/14] ignore percent-we rule for specs because many lists of test name contain spaces --- .github/workflows/publish.yml | 2 +- spec/datadog/ci/test_visibility/context/global_spec.rb | 2 +- spec/support/span_helpers.rb | 2 +- static-analysis.datadog.yml | 5 +++++ 4 files changed, 8 insertions(+), 3 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 9f4522c4..f5a9fc67 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -21,5 +21,5 @@ jobs: uses: ruby/setup-ruby@v1 with: bundler-cache: true - ruby-version: '3.2.4' + ruby-version: '3.3' - uses: rubygems/release-gem@v1 diff --git a/spec/datadog/ci/test_visibility/context/global_spec.rb b/spec/datadog/ci/test_visibility/context/global_spec.rb index 72cc669f..4fcb0fc5 100644 --- a/spec/datadog/ci/test_visibility/context/global_spec.rb +++ b/spec/datadog/ci/test_visibility/context/global_spec.rb @@ -207,7 +207,7 @@ context "when multiple test suites are running" do before do - ["suite1", "suite2"].each do |test_suite_name| + %w[suite1 suite2].each do |test_suite_name| subject.fetch_or_activate_test_suite(test_suite_name) do Datadog::CI::TestSuite.new(double(Datadog::Tracing::SpanOperation)) end diff --git a/spec/support/span_helpers.rb b/spec/support/span_helpers.rb index d3d81190..58515b48 100644 --- a/spec/support/span_helpers.rb +++ b/spec/support/span_helpers.rb @@ -118,7 +118,7 @@ def description_of(actual) # rubocop:disable Lint/NestedMethodDefinition end end - ["skip", "pass", "fail"].each do |status| + %w[skip pass fail].each do |status| RSpec::Matchers.define "have_#{status}_status" do match do |span| @actual = span.get_tag(Datadog::CI::Ext::Test::TAG_STATUS) diff --git a/static-analysis.datadog.yml b/static-analysis.datadog.yml index a7108546..e07f4abf 100644 --- a/static-analysis.datadog.yml +++ b/static-analysis.datadog.yml @@ -10,3 +10,8 @@ rulesets: hash-fetch: ignore: - spec/**/* + rules: + percent-w: + ignore: + - spec/**/* + From 189dc3942fc60f0b57074f9d187af24afa05cee6 Mon Sep 17 00:00:00 2001 From: Andrey Date: Mon, 3 Jun 2024 10:49:24 +0200 Subject: [PATCH 08/14] fix static analysis config --- static-analysis.datadog.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/static-analysis.datadog.yml b/static-analysis.datadog.yml index e07f4abf..4500f996 100644 --- a/static-analysis.datadog.yml +++ b/static-analysis.datadog.yml @@ -10,8 +10,6 @@ rulesets: hash-fetch: ignore: - spec/**/* - rules: percent-w: ignore: - - spec/**/* - + - spec/**/* From b3eee9d21dd312aa8ca71649e646f5f0277f8642 Mon Sep 17 00:00:00 2001 From: Andrey Date: Mon, 3 Jun 2024 11:07:27 +0200 Subject: [PATCH 09/14] try to use software composition analysis --- .github/workflows/datadog-sca.yml | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 .github/workflows/datadog-sca.yml diff --git a/.github/workflows/datadog-sca.yml b/.github/workflows/datadog-sca.yml new file mode 100644 index 00000000..7e7b1d23 --- /dev/null +++ b/.github/workflows/datadog-sca.yml @@ -0,0 +1,25 @@ +on: [push] + +name: Datadog Software Composition Analysis + +jobs: + software-composition-analysis: + runs-on: ubuntu-latest + name: Datadog SBOM Generation and Upload + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Set up Ruby + uses: ruby/setup-ruby@v1 + with: + bundler-cache: true + ruby-version: '3.3' + - name: Check imported libraries are secure and compliant + id: datadog-software-composition-analysis + uses: DataDog/datadog-sca-github-action@main + with: + dd_api_key: ${{ secrets.DD_API_KEY }} + dd_app_key: ${{ secrets.DD_APP_KEY }} + dd_service: my-app + dd_env: ci + dd_site: datadoghq.com From b63752e191a16a1e36c946aa2bacf8ee4b48c51a Mon Sep 17 00:00:00 2001 From: Andrey Date: Mon, 3 Jun 2024 11:18:54 +0200 Subject: [PATCH 10/14] more fixes and ignores --- spec/support/contexts/msgpack_serializer.rb | 6 +----- static-analysis.datadog.yml | 3 +++ yard/extensions.rb | 2 +- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/spec/support/contexts/msgpack_serializer.rb b/spec/support/contexts/msgpack_serializer.rb index eec6fc9d..df38dc75 100644 --- a/spec/support/contexts/msgpack_serializer.rb +++ b/spec/support/contexts/msgpack_serializer.rb @@ -5,11 +5,7 @@ subject {} let(:msgpack_jsons) do - if subject.is_a?(Array) - subject.map { |s| MessagePack.unpack(MessagePack.pack(s)) } - else - [MessagePack.unpack(MessagePack.pack(subject))] - end + Array(subject).map { |s| MessagePack.unpack(MessagePack.pack(s)) } end let(:msgpack_json) { msgpack_jsons.first } diff --git a/static-analysis.datadog.yml b/static-analysis.datadog.yml index 4500f996..e417a3ae 100644 --- a/static-analysis.datadog.yml +++ b/static-analysis.datadog.yml @@ -13,3 +13,6 @@ rulesets: percent-w: ignore: - spec/**/* + no-optional-hash-params: + ignore: + - '**' diff --git a/yard/extensions.rb b/yard/extensions.rb index 00585bce..69e4ac75 100644 --- a/yard/extensions.rb +++ b/yard/extensions.rb @@ -65,7 +65,7 @@ class DatadogConfigurationSettingsHandler < YARD::Handlers::Ruby::Base process do next if statement.is_a?(YARD::Parser::Ruby::ReferenceNode) - name = call_params[0] + name = call_params.first # Check if we are already nested inside the DSL namespace if namespace.has_tag?(:dsl) From 26999693781c9e23ea5380843e7840b44f916884 Mon Sep 17 00:00:00 2001 From: Andrey Date: Mon, 3 Jun 2024 11:33:28 +0200 Subject: [PATCH 11/14] more fixes and ignores --- lib/datadog/ci/contrib/cucumber/formatter.rb | 2 +- lib/datadog/ci/contrib/rspec/example.rb | 11 +++++++---- lib/datadog/ci/test_visibility/serializers/base.rb | 8 +------- .../ci/test_visibility/serializers/test_module.rb | 4 ++-- .../ci/test_visibility/serializers/test_session.rb | 4 ++-- .../ci/test_visibility/serializers/test_suite.rb | 4 ++-- lib/datadog/ci/test_visibility/serializers/test_v1.rb | 4 ++-- lib/datadog/ci/test_visibility/serializers/test_v2.rb | 6 +++--- static-analysis.datadog.yml | 2 +- 9 files changed, 21 insertions(+), 24 deletions(-) diff --git a/lib/datadog/ci/contrib/cucumber/formatter.rb b/lib/datadog/ci/contrib/cucumber/formatter.rb index 14134e3b..e105ddac 100644 --- a/lib/datadog/ci/contrib/cucumber/formatter.rb +++ b/lib/datadog/ci/contrib/cucumber/formatter.rb @@ -187,7 +187,7 @@ def extract_parameters_hash(test_case) def ok?(result, strict) # in minor update in Cucumber 9.2.0, the arity of the `ok?` method changed parameters = result.method(:ok?).parameters - if parameters == [[:opt, :be_strict]] + if parameters == [%i[opt be_strict]] result.ok?(strict) else result.ok?(strict: strict) diff --git a/lib/datadog/ci/contrib/rspec/example.rb b/lib/datadog/ci/contrib/rspec/example.rb index f6703fe0..5b42cb41 100644 --- a/lib/datadog/ci/contrib/rspec/example.rb +++ b/lib/datadog/ci/contrib/rspec/example.rb @@ -23,7 +23,7 @@ def run(*args) test_name = full_description.strip if metadata[:description].empty? # for unnamed it blocks this appends something like "example at ./spec/some_spec.rb:10" - test_name += " #{description}" + test_name << " #{description}" end test_suite_description = fetch_top_level_example_group[:description] @@ -33,7 +33,7 @@ def run(*args) test_name = test_name.sub(test_suite_description, "").strip if ci_queue? - suite_name += " (ci-queue running example [#{test_name}])" + suite_name << " (ci-queue running example [#{test_name}])" test_suite_span = CI.start_test_suite(suite_name) end @@ -83,9 +83,12 @@ def run(*args) private def fetch_top_level_example_group - return metadata[:example_group] unless metadata[:example_group][:parent_example_group] + example_group = metadata[:example_group] + parent_example_group = example_group[:parent_example_group] - res = metadata[:example_group][:parent_example_group] + return example_group unless parent_example_group + + res = parent_example_group while (parent = res[:parent_example_group]) res = parent end diff --git a/lib/datadog/ci/test_visibility/serializers/base.rb b/lib/datadog/ci/test_visibility/serializers/base.rb index 24fe9777..0872e648 100644 --- a/lib/datadog/ci/test_visibility/serializers/base.rb +++ b/lib/datadog/ci/test_visibility/serializers/base.rb @@ -20,13 +20,7 @@ class Base "type" => "span_type" ].freeze - REQUIRED_FIELDS = [ - "error", - "name", - "resource", - "start", - "duration" - ].freeze + REQUIRED_FIELDS = %w[error name resource start duration].freeze attr_reader :trace, :span, :meta, :options diff --git a/lib/datadog/ci/test_visibility/serializers/test_module.rb b/lib/datadog/ci/test_visibility/serializers/test_module.rb index 385367a1..a37cb42f 100644 --- a/lib/datadog/ci/test_visibility/serializers/test_module.rb +++ b/lib/datadog/ci/test_visibility/serializers/test_module.rb @@ -8,11 +8,11 @@ module CI module TestVisibility module Serializers class TestModule < Base - CONTENT_FIELDS = (["test_session_id", "test_module_id"] + Base::CONTENT_FIELDS).freeze + CONTENT_FIELDS = (%w[test_session_id test_module_id] + Base::CONTENT_FIELDS).freeze CONTENT_MAP_SIZE = calculate_content_map_size(CONTENT_FIELDS) - REQUIRED_FIELDS = (["test_session_id", "test_module_id"] + Base::REQUIRED_FIELDS).freeze + REQUIRED_FIELDS = (%w[test_session_id test_module_id] + Base::REQUIRED_FIELDS).freeze def content_fields CONTENT_FIELDS diff --git a/lib/datadog/ci/test_visibility/serializers/test_session.rb b/lib/datadog/ci/test_visibility/serializers/test_session.rb index bbf0dd13..5ea4e0fe 100644 --- a/lib/datadog/ci/test_visibility/serializers/test_session.rb +++ b/lib/datadog/ci/test_visibility/serializers/test_session.rb @@ -8,11 +8,11 @@ module CI module TestVisibility module Serializers class TestSession < Base - CONTENT_FIELDS = (["test_session_id"] + Base::CONTENT_FIELDS).freeze + CONTENT_FIELDS = (%w[test_session_id] + Base::CONTENT_FIELDS).freeze CONTENT_MAP_SIZE = calculate_content_map_size(CONTENT_FIELDS) - REQUIRED_FIELDS = (["test_session_id"] + Base::REQUIRED_FIELDS).freeze + REQUIRED_FIELDS = (%w[test_session_id] + Base::REQUIRED_FIELDS).freeze def content_fields CONTENT_FIELDS diff --git a/lib/datadog/ci/test_visibility/serializers/test_suite.rb b/lib/datadog/ci/test_visibility/serializers/test_suite.rb index 8fcec2f1..5336e3d5 100644 --- a/lib/datadog/ci/test_visibility/serializers/test_suite.rb +++ b/lib/datadog/ci/test_visibility/serializers/test_suite.rb @@ -8,11 +8,11 @@ module CI module TestVisibility module Serializers class TestSuite < Base - CONTENT_FIELDS = (["test_session_id", "test_module_id", "test_suite_id"] + Base::CONTENT_FIELDS).freeze + CONTENT_FIELDS = (%w[test_session_id test_module_id test_suite_id] + Base::CONTENT_FIELDS).freeze CONTENT_MAP_SIZE = calculate_content_map_size(CONTENT_FIELDS) - REQUIRED_FIELDS = (["test_session_id", "test_module_id", "test_suite_id"] + Base::REQUIRED_FIELDS).freeze + REQUIRED_FIELDS = (%w[test_session_id test_module_id test_suite_id] + Base::REQUIRED_FIELDS).freeze def content_fields CONTENT_FIELDS diff --git a/lib/datadog/ci/test_visibility/serializers/test_v1.rb b/lib/datadog/ci/test_visibility/serializers/test_v1.rb index 0ab2b294..668afbed 100644 --- a/lib/datadog/ci/test_visibility/serializers/test_v1.rb +++ b/lib/datadog/ci/test_visibility/serializers/test_v1.rb @@ -8,11 +8,11 @@ module CI module TestVisibility module Serializers class TestV1 < Base - CONTENT_FIELDS = (["trace_id", "span_id"] + Base::CONTENT_FIELDS).freeze + CONTENT_FIELDS = (%w[trace_id span_id] + Base::CONTENT_FIELDS).freeze CONTENT_MAP_SIZE = calculate_content_map_size(CONTENT_FIELDS) - REQUIRED_FIELDS = (["trace_id", "span_id"] + Base::REQUIRED_FIELDS).freeze + REQUIRED_FIELDS = (%w[trace_id span_id] + Base::REQUIRED_FIELDS).freeze def content_fields CONTENT_FIELDS diff --git a/lib/datadog/ci/test_visibility/serializers/test_v2.rb b/lib/datadog/ci/test_visibility/serializers/test_v2.rb index ec026964..f1f674b1 100644 --- a/lib/datadog/ci/test_visibility/serializers/test_v2.rb +++ b/lib/datadog/ci/test_visibility/serializers/test_v2.rb @@ -8,15 +8,15 @@ module CI module TestVisibility module Serializers class TestV2 < TestV1 - CONTENT_FIELDS = (["test_session_id", "test_module_id", "test_suite_id"] + TestV1::CONTENT_FIELDS).freeze + CONTENT_FIELDS = (%w[test_session_id test_module_id test_suite_id] + TestV1::CONTENT_FIELDS).freeze - CONTENT_FIELDS_WITH_ITR_CORRELATION_ID = (CONTENT_FIELDS + ["itr_correlation_id"]).freeze + CONTENT_FIELDS_WITH_ITR_CORRELATION_ID = (CONTENT_FIELDS + %w[itr_correlation_id]).freeze CONTENT_MAP_SIZE = calculate_content_map_size(CONTENT_FIELDS) CONTENT_MAP_SIZE_WITH_ITR_CORRELATION_ID = calculate_content_map_size(CONTENT_FIELDS_WITH_ITR_CORRELATION_ID) - REQUIRED_FIELDS = (["test_session_id", "test_module_id", "test_suite_id"] + TestV1::REQUIRED_FIELDS).freeze + REQUIRED_FIELDS = (%w[test_session_id test_module_id test_suite_id] + TestV1::REQUIRED_FIELDS).freeze def content_fields return CONTENT_FIELDS if itr_correlation_id.nil? diff --git a/static-analysis.datadog.yml b/static-analysis.datadog.yml index e417a3ae..9a7ffd51 100644 --- a/static-analysis.datadog.yml +++ b/static-analysis.datadog.yml @@ -9,7 +9,7 @@ rulesets: - '**' hash-fetch: ignore: - - spec/**/* + - '**' percent-w: ignore: - spec/**/* From 74468493be3606177a6045ee609152550021657f Mon Sep 17 00:00:00 2001 From: Andrey Date: Mon, 3 Jun 2024 11:39:02 +0200 Subject: [PATCH 12/14] avoid modifying frozen string for ci_queue --- lib/datadog/ci/contrib/rspec/example.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/datadog/ci/contrib/rspec/example.rb b/lib/datadog/ci/contrib/rspec/example.rb index 5b42cb41..01285280 100644 --- a/lib/datadog/ci/contrib/rspec/example.rb +++ b/lib/datadog/ci/contrib/rspec/example.rb @@ -33,7 +33,7 @@ def run(*args) test_name = test_name.sub(test_suite_description, "").strip if ci_queue? - suite_name << " (ci-queue running example [#{test_name}])" + suite_name = "#{suite_name} (ci-queue running example [#{test_name}])" test_suite_span = CI.start_test_suite(suite_name) end From 69b7fdb60a7feb74477a534249edda420bc4537f Mon Sep 17 00:00:00 2001 From: Andrey Date: Mon, 3 Jun 2024 11:47:52 +0200 Subject: [PATCH 13/14] more fixes and ignores --- lib/datadog/ci/codeowners/matcher.rb | 2 +- lib/datadog/ci/codeowners/parser.rb | 10 +++++----- lib/datadog/ci/ext/environment.rb | 5 +---- lib/datadog/ci/ext/environment/providers/gitlab.rb | 4 ++-- lib/datadog/ci/ext/settings.rb | 14 +++++++------- lib/datadog/ci/itr/coverage/event.rb | 2 +- lib/datadog/ci/transport/http.rb | 1 + sig/datadog/ci/codeowners/parser.rbs | 2 +- yard/extensions.rb | 1 + yard/templates/default/docstring/setup.rb | 1 + 10 files changed, 21 insertions(+), 21 deletions(-) diff --git a/lib/datadog/ci/codeowners/matcher.rb b/lib/datadog/ci/codeowners/matcher.rb index 5b77b7bf..e515a365 100644 --- a/lib/datadog/ci/codeowners/matcher.rb +++ b/lib/datadog/ci/codeowners/matcher.rb @@ -87,7 +87,7 @@ def expand_pattern(pattern) return pattern if pattern == "*" # if pattern ends with a slash then it matches everything deeply nested in this directory - pattern += "**" if pattern.end_with?(::File::SEPARATOR) + pattern << "**" if pattern.end_with?(::File::SEPARATOR) # if pattern doesn't start with a slash then it matches anywhere in the repository if !pattern.start_with?(::File::SEPARATOR, "**#{::File::SEPARATOR}", "*#{::File::SEPARATOR}") diff --git a/lib/datadog/ci/codeowners/parser.rb b/lib/datadog/ci/codeowners/parser.rb index 60be8786..8a711fac 100644 --- a/lib/datadog/ci/codeowners/parser.rb +++ b/lib/datadog/ci/codeowners/parser.rb @@ -8,11 +8,11 @@ module Codeowners # Responsible for parsing a CODEOWNERS file class Parser DEFAULT_LOCATION = "CODEOWNERS" - POSSIBLE_CODEOWNERS_LOCATIONS = [ - "CODEOWNERS", - ".github/CODEOWNERS", - ".gitlab/CODEOWNERS", - "docs/CODEOWNERS" + POSSIBLE_CODEOWNERS_LOCATIONS = %w[ + CODEOWNERS + .github/CODEOWNERS + .gitlab/CODEOWNERS + docs/CODEOWNERS ].freeze def initialize(root_file_path) diff --git a/lib/datadog/ci/ext/environment.rb b/lib/datadog/ci/ext/environment.rb index e2fa1b8e..d301cf92 100644 --- a/lib/datadog/ci/ext/environment.rb +++ b/lib/datadog/ci/ext/environment.rb @@ -23,10 +23,7 @@ module Environment TAG_NODE_NAME = "ci.node.name" TAG_CI_ENV_VARS = "_dd.ci.env_vars" - POSSIBLE_BUNDLE_LOCATIONS = [ - "vendor/bundle", - ".bundle" - ].freeze + POSSIBLE_BUNDLE_LOCATIONS = %w[vendor/bundle .bundle].freeze module_function diff --git a/lib/datadog/ci/ext/environment/providers/gitlab.rb b/lib/datadog/ci/ext/environment/providers/gitlab.rb index 6668ee69..e0581083 100644 --- a/lib/datadog/ci/ext/environment/providers/gitlab.rb +++ b/lib/datadog/ci/ext/environment/providers/gitlab.rb @@ -75,12 +75,12 @@ def git_tag end def git_commit_author_name - name, _ = extract_name_email + name, _email = extract_name_email name end def git_commit_author_email - _, email = extract_name_email + _name, email = extract_name_email email end diff --git a/lib/datadog/ci/ext/settings.rb b/lib/datadog/ci/ext/settings.rb index a1921f6e..917fdb33 100644 --- a/lib/datadog/ci/ext/settings.rb +++ b/lib/datadog/ci/ext/settings.rb @@ -15,13 +15,13 @@ module Settings ENV_ITR_CODE_COVERAGE_EXCLUDED_BUNDLE_PATH = "DD_CIVISIBILITY_ITR_CODE_COVERAGE_EXCLUDED_BUNDLE_PATH" # Source: https://docs.datadoghq.com/getting_started/site/ - DD_SITE_ALLOWLIST = [ - "datadoghq.com", - "us3.datadoghq.com", - "us5.datadoghq.com", - "datadoghq.eu", - "ddog-gov.com", - "ap1.datadoghq.com" + DD_SITE_ALLOWLIST = %w[ + datadoghq.com + us3.datadoghq.com + us5.datadoghq.com + datadoghq.eu + ddog-gov.com + ap1.datadoghq.com ].freeze end end diff --git a/lib/datadog/ci/itr/coverage/event.rb b/lib/datadog/ci/itr/coverage/event.rb index 6e3d2a95..1e4815ea 100644 --- a/lib/datadog/ci/itr/coverage/event.rb +++ b/lib/datadog/ci/itr/coverage/event.rb @@ -21,7 +21,7 @@ def initialize(test_id:, test_suite_id:, test_session_id:, coverage:) def valid? valid = true - [:test_id, :test_suite_id, :test_session_id, :coverage].each do |key| + %i[test_id test_suite_id test_session_id coverage].each do |key| next unless send(key).nil? Datadog.logger.warn("citestcov event is invalid: [#{key}] is nil. Event: #{self}") diff --git a/lib/datadog/ci/transport/http.rb b/lib/datadog/ci/transport/http.rb index 2a1e6f43..6069c9d4 100644 --- a/lib/datadog/ci/transport/http.rb +++ b/lib/datadog/ci/transport/http.rb @@ -124,6 +124,7 @@ def trace_count def gzipped?(payload) return false if payload.nil? || payload.empty? + # no-dd-sa first_bytes = payload[0, 2] return false if first_bytes.nil? || first_bytes.empty? diff --git a/sig/datadog/ci/codeowners/parser.rbs b/sig/datadog/ci/codeowners/parser.rbs index 15f064eb..7a80bc19 100644 --- a/sig/datadog/ci/codeowners/parser.rbs +++ b/sig/datadog/ci/codeowners/parser.rbs @@ -6,7 +6,7 @@ module Datadog DEFAULT_LOCATION: "CODEOWNERS" - POSSIBLE_CODEOWNERS_LOCATIONS: ::Array["CODEOWNERS" | ".github/CODEOWNERS" | ".gitlab/CODEOWNERS" | "docs/CODEOWNERS"] + POSSIBLE_CODEOWNERS_LOCATIONS: Array[String] def initialize: (String? root_file_path) -> void diff --git a/yard/extensions.rb b/yard/extensions.rb index 69e4ac75..e3232bb8 100644 --- a/yard/extensions.rb +++ b/yard/extensions.rb @@ -131,6 +131,7 @@ class DatadogConfigurationOptionHandler < YARD::Handlers::Ruby::Base end end +# no-dd-sa def camelize(str) str.split("_").collect(&:capitalize).join end diff --git a/yard/templates/default/docstring/setup.rb b/yard/templates/default/docstring/setup.rb index 4e0b22ff..612564aa 100644 --- a/yard/templates/default/docstring/setup.rb +++ b/yard/templates/default/docstring/setup.rb @@ -5,6 +5,7 @@ # sections :index, [:private, :deprecated, :abstract, :todo, :note, :returns_void, :text], T('tags') # end +# no-dd-sa def deprecated return unless object.has_tag?(:deprecated) From e05bb7e761e536712c9897f508ae21e7280e806c Mon Sep 17 00:00:00 2001 From: Andrey Date: Mon, 3 Jun 2024 12:01:45 +0200 Subject: [PATCH 14/14] use SecureRandom --- .../ci/contrib/ci_queue_minitest/instrumentation_spec.rb | 3 ++- spec/datadog/ci/contrib/ci_queue_rspec/instrumentation_spec.rb | 3 ++- spec/datadog/ci/contrib/cucumber/instrumentation_spec.rb | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/spec/datadog/ci/contrib/ci_queue_minitest/instrumentation_spec.rb b/spec/datadog/ci/contrib/ci_queue_minitest/instrumentation_spec.rb index 013aa2ca..0e4d67a8 100644 --- a/spec/datadog/ci/contrib/ci_queue_minitest/instrumentation_spec.rb +++ b/spec/datadog/ci/contrib/ci_queue_minitest/instrumentation_spec.rb @@ -1,5 +1,6 @@ require "minitest/queue/runner" require "fileutils" +require "securerandom" RSpec.describe "Minitest instrumentation with Shopify's ci-queue runner" do include_context "CI mode activated" do @@ -7,7 +8,7 @@ let(:integration_options) { {service_name: "ltest"} } end - let(:run_id) { rand(1..2**64 - 1) } + let(:run_id) { SecureRandom.random_number(2**64 - 1) } before do Minitest::Runnable.reset diff --git a/spec/datadog/ci/contrib/ci_queue_rspec/instrumentation_spec.rb b/spec/datadog/ci/contrib/ci_queue_rspec/instrumentation_spec.rb index 9e02bbf6..1da3a821 100644 --- a/spec/datadog/ci/contrib/ci_queue_rspec/instrumentation_spec.rb +++ b/spec/datadog/ci/contrib/ci_queue_rspec/instrumentation_spec.rb @@ -1,12 +1,13 @@ require "rspec/queue" require "fileutils" +require "securerandom" RSpec.describe "RSpec instrumentation with Shopify's ci-queue runner" do include_context "CI mode activated" do let(:integration_name) { :rspec } end - let(:run_id) { rand(1..2**64 - 1) } + let(:run_id) { SecureRandom.random_number(2**64 - 1) } let(:options) do RSpec::Core::ConfigurationOptions.new([ "-Ispec/datadog/ci/contrib/ci_queue_rspec/suite_under_test", diff --git a/spec/datadog/ci/contrib/cucumber/instrumentation_spec.rb b/spec/datadog/ci/contrib/cucumber/instrumentation_spec.rb index 3b23acdc..8ff61f98 100644 --- a/spec/datadog/ci/contrib/cucumber/instrumentation_spec.rb +++ b/spec/datadog/ci/contrib/cucumber/instrumentation_spec.rb @@ -1,6 +1,7 @@ require "stringio" require "fileutils" require "cucumber" +require "securerandom" RSpec.describe "Cucumber formatter" do let(:cucumber_features_root) { File.join(__dir__, "features") } @@ -22,7 +23,7 @@ let(:cucumber_8_or_above) { Gem::Version.new("8.0.0") <= Datadog::CI::Contrib::Cucumber::Integration.version } let(:cucumber_4_or_above) { Gem::Version.new("4.0.0") <= Datadog::CI::Contrib::Cucumber::Integration.version } - let(:run_id) { rand(1..2**64 - 1) } + let(:run_id) { SecureRandom.random_number(2**64 - 1) } let(:steps_file_definition_path) { "spec/datadog/ci/contrib/cucumber/features/step_definitions/steps.rb" } let(:steps_file_for_run_path) do "spec/datadog/ci/contrib/cucumber/features/step_definitions/steps_#{run_id}.rb"