Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.
Ruby b2b-commercee-commerceecommerceecommerce-apiecommerce-frameworkecommerce-platformheadlessheadless-commerceheadless-ecommercemarketplacemulti-tenantmulti-vendormulti-vendor-ecommerceopen-sourcespree-commerce
Migrate CI from CircleCI to GitHub Actions (#13544)
Damian Legawieccece40834ca3
diff --git a/.circleci/config.yml b/.circleci/config.ymldeleted file mode 100644index 66b1a26e39..0000000000--- a/.circleci/config.yml+++ /dev/null@@ -1,260 +0,0 @@-version: 2.1--defaults: &defaults- environment: &environment- CIRCLE_TEST_REPORTS: /tmp/test-results- CIRCLE_ARTIFACTS: /tmp/test-artifacts- BUNDLE_JOBS: 4- BUNDLE_RETRY: 3- BUNDLE_PATH: ~/spree/vendor/bundle- DB_HOST: localhost- DB: postgres # default value, this will speed up bundle install for all postgres builds- DB_USERNAME: postgres- working_directory: ~/spree- docker:- - image: &ruby_image cimg/ruby:4.0-browsers--commands:- check_code_changes:- steps:- - run:- name: Check for code changes beyond docs/config- command: |- if [ "$CIRCLE_BRANCH" = "main" ]; then- CHANGED_FILES=$(git diff --name-only HEAD~1 2>/dev/null || echo "")- else- git fetch origin main --depth=1 2>/dev/null || true- CHANGED_FILES=$(git diff --name-only origin/main...HEAD 2>/dev/null || echo "")- fi-- if [ -z "$CHANGED_FILES" ]; then- echo "No changed files detected, proceeding with CI."- exit 0- fi-- ONLY_EXCLUDED=true- for file in $CHANGED_FILES; do- case "$file" in- .github/*|docs/*|sdk/*|bin/*)- ;;- *)- ONLY_EXCLUDED=false- break- ;;- esac- done-- if [ "$ONLY_EXCLUDED" = true ]; then- echo "Only changes in excluded directories (.github, docs, sdk, bin). Skipping CI."- circleci-agent step halt- else- echo "Code changes detected, proceeding with CI."- fi- bundle_install:- parameters:- update:- type: boolean- default: false- clean:- type: boolean- default: false- steps:- - restore_cache:- keys:- - spree-bundle-v13-ruby-{{ .Branch }}- - spree-bundle-v13-ruby- - install_libvips- - when:- condition: << parameters.update >>- steps:- - run:- name: Update global dependencies- command: bundle update- - unless:- condition: << parameters.update >>- steps:- - run:- name: Install global dependencies- command: bundle install- - when:- condition: << parameters.clean >>- steps:- - run:- name: Clean old gems- command: bundle clean- - run:- name: Install per-project gem dependencies- command: bin/build-ci.rb install- install_libvips:- steps:- - run:- name: Fix APT mirrors- command: |- sudo apt-get update- - run:- name: Install libvips- command: |- sudo apt-get install -y libvips-dev- store_all_artifacts:- steps:- - store_artifacts:- path: /tmp/test-artifacts- destination: test-artifacts- - store_artifacts:- path: /tmp/failed_tests- destination: failed_tests- - store_artifacts:- path: /tmp/test-results- destination: raw-test-output- - store_test_results:- path: /tmp/test-results-jobs:- build:- <<: *defaults- steps:- - checkout- - check_code_changes- - bundle_install:- update: true- clean: true- - save_cache:- key: spree-bundle-v13-ruby-{{ .Branch }}- paths:- - ~/spree/vendor/bundle- test: &test- <<: *defaults- docker:- - image: *ruby_image- - image: cimg/postgres:16.2- environment:- POSTGRES_USER: postgres- steps: &default_steps- - checkout- - check_code_changes- - attach_workspace:- at: /tmp- - bundle_install- - run:- name: Run tests- command: bin/build-ci.rb test- - store_all_artifacts-- test_mysql: &test_mysql- <<: *test- docker:- - image: *ruby_image- - image: cimg/mysql:8.0- command: [--default-authentication-plugin=mysql_native_password]- environment:- MYSQL_ROOT_PASSWORD: password- environment: &mysql_environment- <<: *environment- DB: mysql- DB_USERNAME: root- DB_PASSWORD: password- DB_HOST: 127.0.0.1- RAILS_VERSION: 7.2.0-- # postgres tests- test_core_postgres:- <<: *test- parallelism: 6- environment:- <<: *environment- PROJECTS: core- test_api_postgres:- <<: *test- parallelism: 2- environment:- <<: *environment- PROJECTS: api- test_admin_postgres:- <<: *test- parallelism: 2- environment:- <<: *environment- PROJECTS: admin- test_other_postgres:- <<: *test- environment:- <<: *environment- PROJECTS: emails,sample-- # mysql tests- test_core_mysql:- <<: *test_mysql- parallelism: 6- environment:- <<: *mysql_environment- PROJECTS: core- test_api_mysql:- <<: *test_mysql- parallelism: 2- environment:- <<: *mysql_environment- PROJECTS: api- test_admin_mysql:- <<: *test_mysql- parallelism: 2- environment:- <<: *mysql_environment- PROJECTS: admin- test_other_mysql:- <<: *test_mysql- environment:- <<: *mysql_environment- PROJECTS: emails,sample-- # brakeman- brakeman:- <<: *defaults- steps:- - checkout- - check_code_changes- - bundle_install- - run: bin/brakeman.sh- - run:- name: Move brakeman reports to artifacts directory- command: |- mkdir -p /tmp/test-artifacts/- mv brakeman-*.* /tmp/test-artifacts/- - store_artifacts:- path: /tmp/test-artifacts- destination: brakeman-reports--workflows:- main:- jobs:- - build- # postgres tests- - test_core_postgres:- requires:- - build- - test_api_postgres:- requires:- - build- - test_admin_postgres:- requires:- - build- - test_other_postgres:- requires:- - build-- # mysql tests- - test_core_mysql:- requires:- - build- - test_api_mysql:- requires:- - build- - test_admin_mysql:- requires:- - build- - test_other_mysql:- requires:- - build-- # brakeman- - brakeman:- requires:- - builddiff --git a/.github/workflows/tests.yml b/.github/workflows/tests.ymlnew file mode 100644index 0000000000..8e2dff3e62--- /dev/null+++ b/.github/workflows/tests.yml@@ -0,0 +1,388 @@+name: Tests++on:+ push:+ branches: [main]+ paths-ignore:+ - 'docs/**'+ - 'sdk/**'+ - '**/*.md'+ pull_request:+ paths-ignore:+ - 'docs/**'+ - 'sdk/**'+ - '**/*.md'++concurrency:+ group: ${{ github.workflow }}-${{ github.ref }}+ cancel-in-progress: true++permissions:+ contents: read++jobs:+ build-postgres:+ name: "Build (PostgreSQL)"+ runs-on: ubuntu-latest+ env:+ DB: postgres+ RAILS_VERSION: "~> 8.1.0"+ BUNDLE_JOBS: 4+ BUNDLE_RETRY: 3+ steps:+ - uses: actions/checkout@v4++ - uses: ruby/setup-ruby@v1+ with:+ ruby-version: '4.0'++ - name: Cache Ruby gems+ uses: actions/cache@v4+ with:+ path: vendor/bundle+ key: gems-${{ runner.os }}-ruby4.0-postgres-${{ hashFiles('Gemfile', '*.gemspec', 'common_spree_dependencies.rb', '*/*.gemspec') }}+ restore-keys: |+ gems-${{ runner.os }}-ruby4.0-postgres-++ - name: Install root dependencies+ run: |+ bundle config set --local path vendor/bundle+ bundle install++ - name: Install all project dependencies+ run: |+ for project in core api admin emails sample; do+ echo "--- Installing gems for $project ---"+ cd $project+ bundle config set --local path ${{ github.workspace }}/vendor/bundle+ bundle install+ cd ${{ github.workspace }}+ done++ build-mysql:+ name: "Build (MySQL)"+ runs-on: ubuntu-latest+ env:+ DB: mysql+ RAILS_VERSION: "7.2.0"+ BUNDLE_JOBS: 4+ BUNDLE_RETRY: 3+ steps:+ - uses: actions/checkout@v4++ - uses: ruby/setup-ruby@v1+ with:+ ruby-version: '4.0'++ - name: Cache Ruby gems+ uses: actions/cache@v4+ with:+ path: vendor/bundle+ key: gems-${{ runner.os }}-ruby4.0-mysql-${{ hashFiles('Gemfile', '*.gemspec', 'common_spree_dependencies.rb', '*/*.gemspec') }}+ restore-keys: |+ gems-${{ runner.os }}-ruby4.0-mysql-++ - name: Install root dependencies+ run: |+ bundle config set --local path vendor/bundle+ bundle install++ - name: Install all project dependencies+ run: |+ for project in core api admin emails sample; do+ echo "--- Installing gems for $project ---"+ cd $project+ bundle config set --local path ${{ github.workspace }}/vendor/bundle+ bundle install+ cd ${{ github.workspace }}+ done++ test-postgres:+ name: "PostgreSQL - ${{ matrix.project }} (${{ matrix.shard }}/${{ matrix.total_shards }})"+ needs: build-postgres+ runs-on: ubuntu-latest+ strategy:+ fail-fast: false+ matrix:+ include:+ # core: 6 shards+ - { project: core, shard: 1, total_shards: 6 }+ - { project: core, shard: 2, total_shards: 6 }+ - { project: core, shard: 3, total_shards: 6 }+ - { project: core, shard: 4, total_shards: 6 }+ - { project: core, shard: 5, total_shards: 6 }+ - { project: core, shard: 6, total_shards: 6 }+ # api: 2 shards+ - { project: api, shard: 1, total_shards: 2 }+ - { project: api, shard: 2, total_shards: 2 }+ # admin: 2 shards+ - { project: admin, shard: 1, total_shards: 2 }+ - { project: admin, shard: 2, total_shards: 2 }+ # emails & sample: 1 shard each+ - { project: emails, shard: 1, total_shards: 1 }+ - { project: sample, shard: 1, total_shards: 1 }+ services:+ postgres:+ image: postgres:16+ env:+ POSTGRES_USER: postgres+ POSTGRES_PASSWORD: postgres+ ports:+ - 5432:5432+ options: >-+ --health-cmd pg_isready+ --health-interval 10s+ --health-timeout 5s+ --health-retries 5+ env:+ DB: postgres+ DB_HOST: localhost+ DB_USERNAME: postgres+ DB_PASSWORD: postgres+ RAILS_VERSION: "~> 8.1.0"+ CI_ARTIFACTS: /tmp/test-artifacts+ BUNDLE_JOBS: 4+ BUNDLE_RETRY: 3+ steps:+ - uses: actions/checkout@v4++ - uses: ruby/setup-ruby@v1+ with:+ ruby-version: '4.0'++ - name: Restore gem cache+ uses: actions/cache@v4+ with:+ path: vendor/bundle+ key: gems-${{ runner.os }}-ruby4.0-postgres-${{ hashFiles('Gemfile', '*.gemspec', 'common_spree_dependencies.rb', '*/*.gemspec') }}+ restore-keys: |+ gems-${{ runner.os }}-ruby4.0-postgres-++ - name: Install libvips+ run: sudo apt-get update && sudo apt-get install -y libvips-dev++ - name: Install dependencies+ run: |+ bundle config set --local path vendor/bundle+ bundle install+ cd ${{ matrix.project }}+ bundle config set --local path ${{ github.workspace }}/vendor/bundle+ bundle install++ - name: Setup test app+ working-directory: ${{ matrix.project }}+ run: |+ if [[ "${{ matrix.project }}" == "core" || "${{ matrix.project }}" == "api" ]]; then+ bundle exec --gemfile=${{ github.workspace }}/Gemfile rake test_app+ else+ bundle exec rake test_app+ fi++ - name: Select shard specs+ id: specs+ working-directory: ${{ matrix.project }}+ run: |+ all_specs=($(find spec -name '*_spec.rb' | sort))+ total=${#all_specs[@]}+ shard_specs=()+ shard_index=$(( ${{ matrix.shard }} - 1 ))+ for ((i=0; i<total; i++)); do+ if (( i % ${{ matrix.total_shards }} == shard_index )); then+ shard_specs+=("${all_specs[$i]}")+ fi+ done+ echo "Found ${#shard_specs[@]} specs for shard ${{ matrix.shard }}/${{ matrix.total_shards }} (out of $total total)"+ echo "files=${shard_specs[*]}" >> "$GITHUB_OUTPUT"++ - name: Run tests+ working-directory: ${{ matrix.project }}+ run: |+ mkdir -p ${{ github.workspace }}/tmp/test-results/rspec+ bundle exec rspec \+ --order random \+ --format progress \+ --profile 10 \+ -r rspec_junit_formatter \+ --format RspecJunitFormatter \+ -o ${{ github.workspace }}/tmp/test-results/rspec/${{ matrix.project }}-${{ matrix.shard }}.xml \+ ${{ steps.specs.outputs.files }}++ - name: Upload test results+ if: always()+ uses: actions/upload-artifact@v4+ with:+ name: test-results-postgres-${{ matrix.project }}-${{ matrix.shard }}+ path: tmp/test-results/+ if-no-files-found: ignore++ - name: Upload failed test screenshots+ if: failure()+ uses: actions/upload-artifact@v4+ with:+ name: failed-screenshots-postgres-${{ matrix.project }}-${{ matrix.shard }}+ path: /tmp/test-artifacts/+ if-no-files-found: ignore++ test-mysql:+ name: "MySQL - ${{ matrix.project }} (${{ matrix.shard }}/${{ matrix.total_shards }})"+ needs: build-mysql+ runs-on: ubuntu-latest+ strategy:+ fail-fast: false+ matrix:+ include:+ # core: 6 shards+ - { project: core, shard: 1, total_shards: 6 }+ - { project: core, shard: 2, total_shards: 6 }+ - { project: core, shard: 3, total_shards: 6 }+ - { project: core, shard: 4, total_shards: 6 }+ - { project: core, shard: 5, total_shards: 6 }+ - { project: core, shard: 6, total_shards: 6 }+ # api: 2 shards+ - { project: api, shard: 1, total_shards: 2 }+ - { project: api, shard: 2, total_shards: 2 }+ # admin: 2 shards+ - { project: admin, shard: 1, total_shards: 2 }+ - { project: admin, shard: 2, total_shards: 2 }+ # emails & sample: 1 shard each+ - { project: emails, shard: 1, total_shards: 1 }+ - { project: sample, shard: 1, total_shards: 1 }+ services:+ mysql:+ image: mysql:8.0+ env:+ MYSQL_ROOT_PASSWORD: password+ ports:+ - 3306:3306+ options: >-+ --health-cmd="mysqladmin ping"+ --health-interval 10s+ --health-timeout 5s+ --health-retries 5+ env:+ DB: mysql+ DB_HOST: 127.0.0.1+ DB_USERNAME: root+ DB_PASSWORD: password+ RAILS_VERSION: "7.2.0"+ CI_ARTIFACTS: /tmp/test-artifacts+ BUNDLE_JOBS: 4+ BUNDLE_RETRY: 3+ steps:+ - uses: actions/checkout@v4++ - uses: ruby/setup-ruby@v1+ with:+ ruby-version: '4.0'++ - name: Restore gem cache+ uses: actions/cache@v4+ with:+ path: vendor/bundle+ key: gems-${{ runner.os }}-ruby4.0-mysql-${{ hashFiles('Gemfile', '*.gemspec', 'common_spree_dependencies.rb', '*/*.gemspec') }}+ restore-keys: |+ gems-${{ runner.os }}-ruby4.0-mysql-++ - name: Install libvips+ run: sudo apt-get update && sudo apt-get install -y libvips-dev++ - name: Install dependencies+ run: |+ bundle config set --local path vendor/bundle+ bundle install+ cd ${{ matrix.project }}+ bundle config set --local path ${{ github.workspace }}/vendor/bundle+ bundle install++ - name: Setup test app+ working-directory: ${{ matrix.project }}+ run: |+ if [[ "${{ matrix.project }}" == "core" || "${{ matrix.project }}" == "api" ]]; then+ bundle exec --gemfile=${{ github.workspace }}/Gemfile rake test_app+ else+ bundle exec rake test_app+ fi++ - name: Select shard specs+ id: specs+ working-directory: ${{ matrix.project }}+ run: |+ all_specs=($(find spec -name '*_spec.rb' | sort))+ total=${#all_specs[@]}+ shard_specs=()+ shard_index=$(( ${{ matrix.shard }} - 1 ))+ for ((i=0; i<total; i++)); do+ if (( i % ${{ matrix.total_shards }} == shard_index )); then+ shard_specs+=("${all_specs[$i]}")+ fi+ done+ echo "Found ${#shard_specs[@]} specs for shard ${{ matrix.shard }}/${{ matrix.total_shards }} (out of $total total)"+ echo "files=${shard_specs[*]}" >> "$GITHUB_OUTPUT"++ - name: Run tests+ working-directory: ${{ matrix.project }}+ run: |+ mkdir -p ${{ github.workspace }}/tmp/test-results/rspec+ bundle exec rspec \+ --order random \+ --format progress \+ --profile 10 \+ -r rspec_junit_formatter \+ --format RspecJunitFormatter \+ -o ${{ github.workspace }}/tmp/test-results/rspec/${{ matrix.project }}-${{ matrix.shard }}.xml \+ ${{ steps.specs.outputs.files }}++ - name: Upload test results+ if: always()+ uses: actions/upload-artifact@v4+ with:+ name: test-results-mysql-${{ matrix.project }}-${{ matrix.shard }}+ path: tmp/test-results/+ if-no-files-found: ignore++ - name: Upload failed test screenshots+ if: failure()+ uses: actions/upload-artifact@v4+ with:+ name: failed-screenshots-mysql-${{ matrix.project }}-${{ matrix.shard }}+ path: /tmp/test-artifacts/+ if-no-files-found: ignore++ brakeman:+ name: Brakeman+ needs: build-postgres+ runs-on: ubuntu-latest+ env:+ DB: postgres+ BUNDLE_JOBS: 4+ BUNDLE_RETRY: 3+ steps:+ - uses: actions/checkout@v4++ - uses: ruby/setup-ruby@v1+ with:+ ruby-version: '4.0'++ - name: Restore gem cache+ uses: actions/cache@v4+ with:+ path: vendor/bundle+ key: gems-${{ runner.os }}-ruby4.0-postgres-${{ hashFiles('Gemfile', '*.gemspec', 'common_spree_dependencies.rb', '*/*.gemspec') }}+ restore-keys: |+ gems-${{ runner.os }}-ruby4.0-postgres-++ - name: Install dependencies+ run: |+ bundle config set --local path vendor/bundle+ bundle install++ - name: Run Brakeman+ run: bin/brakeman.sh++ - name: Upload Brakeman reports+ if: always()+ uses: actions/upload-artifact@v4+ with:+ name: brakeman-reports+ path: brakeman-*.*+ if-no-files-found: ignorediff --git a/admin/config/brakeman.ignore b/admin/config/brakeman.ignorenew file mode 100644index 0000000000..8cd8b9f524--- /dev/null+++ b/admin/config/brakeman.ignore@@ -0,0 +1,28 @@+{+ "ignored_warnings": [+ {+ "warning_type": "SQL Injection",+ "warning_code": 0,+ "fingerprint": "88419e0a9641c91da76b4b9030cf728cfea25fc84f9715a660f85ae805284d0d",+ "check_name": "SQL",+ "message": "Possible SQL injection",+ "file": "lib/spree/admin/testing_support/capybara_utils.rb",+ "line": 6,+ "link": "https://brakemanscanner.org/docs/warning_types/sql_injection/",+ "code": "first(\".ti-#{type}\")",+ "render_path": null,+ "location": {+ "type": "method",+ "class": "Spree::Admin::TestingSupport::CapybaraUtils",+ "method": "click_icon"+ },+ "user_input": "type",+ "confidence": "Medium",+ "cwe_id": [+ 89+ ],+ "note": "False positive: this is a Capybara CSS selector, not SQL"+ }+ ],+ "brakeman_version": "7.1.0"+}diff --git a/cli/lib/spree_cli/extension.rb b/cli/lib/spree_cli/extension.rbindex 2636a88f58..cc33a8534f 100644--- a/cli/lib/spree_cli/extension.rb+++ b/cli/lib/spree_cli/extension.rb@@ -45,7 +45,7 @@ module SpreeClitemplate 'config/importmap.rb', "#{file_name}/config/importmap.rb"template 'rspec', "#{file_name}/.rspec"- template '.circleci/config.yml', "#{file_name}/.circleci/config.yml"+ template '.github/workflows/tests.yml', "#{file_name}/.github/workflows/tests.yml"template '.github/.dependabot.yml', "#{file_name}/.github/.dependabot.yml"template '.rubocop.yml', "#{file_name}/.rubocop.yml"template '.gem_release.yml', "#{file_name}/.gem_release.yml"diff --git a/cli/lib/spree_cli/templates/extension/.circleci/config.yml b/cli/lib/spree_cli/templates/extension/.circleci/config.ymldeleted file mode 100644index 1f78910215..0000000000--- a/cli/lib/spree_cli/templates/extension/.circleci/config.yml+++ /dev/null@@ -1,143 +0,0 @@-version: 2.1--defaults: &defaults- environment: &environment- CIRCLE_TEST_REPORTS: /tmp/test-results- CIRCLE_ARTIFACTS: /tmp/test-artifacts- BUNDLE_JOBS: 4- BUNDLE_RETRY: 3- BUNDLE_PATH: ~/spree/vendor/bundle- working_directory: ~/spree- docker:- - image: &ruby_image cimg/ruby:3.4-browsers--run_tests: &run_tests- <<: *defaults- steps:- - checkout- - restore_cache:- keys:- - spree-bundle-{{ .Branch }}- - run:- name: Add keyserver- command: sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 4EB27DB2A3B88B8B- - run:- name: Install libvips- command: sudo apt-get update && sudo apt-get install libvips- - run:- name: Set bundle path- command: bundle config --local path vendor/bundle- - run:- name: Ensure bundle Install- command: |- bundle check || bundle install- - run:- name: Create test app- command: |- bundle exec rake test_app- - run:- name: Run Rspec- command: |- TESTFILES=$(circleci tests glob "spec/**/*_spec.rb" | circleci tests split --split-by=timings)- bundle exec rspec --format documentation \- --format RspecJunitFormatter \- -o ~/rspec/rspec.xml \- -- ${TESTFILES}- - store_test_results:- path: ~/rspec- - store_artifacts:- path: tmp/capybara--jobs:- bundle:- <<: *defaults- steps:- - checkout- - restore_cache:- keys:- - spree-bundle-{{ .Branch }}- - run:- name: Add keyserver- command: sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 4EB27DB2A3B88B8B- - run:- name: Install libvips- command: sudo apt-get update && sudo apt-get install libvips- - run:- name: Set bundle path- command: bundle config --local path vendor/bundle- - run:- name: Bundle Install- command: |- bundle check || bundle install- - save_cache:- paths:- - vendor/bundle- key: spree-bundle-{{ .Branch }}-- tests_postgres: &tests_postgres- <<: *run_tests- environment: &postgres_environment- <<: *environment- DB: postgres- DB_HOST: localhost- DB_USERNAME: postgres- docker:- - image: *ruby_image- - image: &postgres_image cimg/postgres:18.0- environment:- POSTGRES_USER: postgres-- tests_mysql: &tests_mysql- <<: *run_tests- environment: &mysql_environment- <<: *environment- DB: mysql- DB_HOST: 127.0.0.1- DB_USERNAME: root- COVERAGE: true- COVERAGE_DIR: /tmp/workspace/simplecov- docker:- - image: *ruby_image- - image: &mysql_image cimg/mysql:8.0-- brakeman:- <<: *defaults- steps:- - checkout- - restore_cache:- keys:- - spree-bundle-{{ .Branch }}- - run:- name: Set bundle path- command: bundle config --local path vendor/bundle- - run:- name: Ensure bundle Install- command: |- bundle check || bundle install- - run:- name: Brakeman- command: bundle exec brakeman --exit-on-warn --exit-on-error -o brakeman.json -o brakeman.html- - run:- name: Move brakeman reports to artifacts directory- command: |- mkdir -p /tmp/test-artifacts/- mv brakeman.json /tmp/test-artifacts/- mv brakeman.html /tmp/test-artifacts/- - store_artifacts:- path: /tmp/test-artifacts- destination: brakeman-reports--workflows:- version: 2- main:- jobs:- - bundle- - tests_postgres:- requires:- - bundle- - tests_mysql:- requires:- - bundle- - brakeman:- requires:- - bundle\ No newline at end of filediff --git a/cli/lib/spree_cli/templates/extension/.github/workflows/tests.yml b/cli/lib/spree_cli/templates/extension/.github/workflows/tests.ymlnew file mode 100644index 0000000000..bc6430d237--- /dev/null+++ b/cli/lib/spree_cli/templates/extension/.github/workflows/tests.yml@@ -0,0 +1,107 @@+name: Tests++on:+ push:+ branches: [main]+ pull_request:++concurrency:+ group: ${{ github.workflow }}-${{ github.ref }}+ cancel-in-progress: true++permissions:+ contents: read++jobs:+ test-postgres:+ name: "PostgreSQL"+ runs-on: ubuntu-latest+ services:+ postgres:+ image: postgres:16+ env:+ POSTGRES_USER: postgres+ POSTGRES_PASSWORD: postgres+ ports:+ - 5432:5432+ options: >-+ --health-cmd pg_isready+ --health-interval 10s+ --health-timeout 5s+ --health-retries 5+ env:+ DB: postgres+ DB_HOST: localhost+ DB_USERNAME: postgres+ DB_PASSWORD: postgres+ BUNDLE_JOBS: 4+ BUNDLE_RETRY: 3+ steps:+ - uses: actions/checkout@v4++ - uses: ruby/setup-ruby@v1+ with:+ ruby-version: '4.0'+ bundler-cache: true++ - name: Install libvips+ run: sudo apt-get update && sudo apt-get install -y libvips-dev++ - name: Create test app+ run: bundle exec rake test_app++ - name: Run tests+ run: bundle exec rspec --format documentation++ test-mysql:+ name: "MySQL"+ runs-on: ubuntu-latest+ services:+ mysql:+ image: mysql:8.0+ env:+ MYSQL_ROOT_PASSWORD: password+ ports:+ - 3306:3306+ options: >-+ --health-cmd="mysqladmin ping"+ --health-interval 10s+ --health-timeout 5s+ --health-retries 5+ env:+ DB: mysql+ DB_HOST: 127.0.0.1+ DB_USERNAME: root+ DB_PASSWORD: password+ BUNDLE_JOBS: 4+ BUNDLE_RETRY: 3+ steps:+ - uses: actions/checkout@v4++ - uses: ruby/setup-ruby@v1+ with:+ ruby-version: '4.0'+ bundler-cache: true++ - name: Install libvips+ run: sudo apt-get update && sudo apt-get install -y libvips-dev++ - name: Create test app+ run: bundle exec rake test_app++ - name: Run tests+ run: bundle exec rspec --format documentation++ brakeman:+ name: Brakeman+ runs-on: ubuntu-latest+ steps:+ - uses: actions/checkout@v4++ - uses: ruby/setup-ruby@v1+ with:+ ruby-version: '4.0'+ bundler-cache: true++ - name: Run Brakeman+ run: bundle exec brakeman --exit-on-warn --exit-on-errordiff --git a/core/config/brakeman.ignore b/core/config/brakeman.ignorenew file mode 100644index 0000000000..50d47bf59c--- /dev/null+++ b/core/config/brakeman.ignore@@ -0,0 +1,120 @@+{+ "ignored_warnings": [+ {+ "warning_type": "SQL Injection",+ "warning_code": 0,+ "fingerprint": "05bad36b6a70ef61186c5f7152922a518714d5ac67766cebae0c35d0503e8d1a",+ "check_name": "SQL",+ "message": "Possible SQL injection",+ "file": "lib/spree/testing_support/capybara_ext.rb",+ "line": 16,+ "link": "https://brakemanscanner.org/docs/warning_types/sql_injection/",+ "code": "first(\".icon-#{type}\")",+ "render_path": null,+ "location": {+ "type": "method",+ "class": "CapybaraExt",+ "method": "click_icon"+ },+ "user_input": "type",+ "confidence": "Medium",+ "cwe_id": [+ 89+ ],+ "note": "False positive: this is a Capybara CSS selector, not a SQL query"+ },+ {+ "warning_type": "SQL Injection",+ "warning_code": 0,+ "fingerprint": "0e3bd8868fcc07adb95a529b67bc5729a239a89bda61e44fb8a117930ac22281",+ "check_name": "SQL",+ "message": "Possible SQL injection",+ "file": "app/finders/spree/products/find.rb",+ "line": 349,+ "link": "https://brakemanscanner.org/docs/warning_types/sql_injection/",+ "code": "scope.joins(:variants_including_master => :prices).select(\"#{Spree::Product.table_name}.* , min(#{Spree::Price.table_name}.amount)\").where(Spree::Price.table_name => ({ :currency => currency })).where.not(Spree::Price.table_name => ({ :amount => nil })).order(\"min(#{Spree::Price.table_name}.amount) #{sort_order}\")",+ "render_path": null,+ "location": {+ "type": "method",+ "class": "Spree::Products::Find",+ "method": "order_by_price"+ },+ "user_input": "sort_order",+ "confidence": "Weak",+ "cwe_id": [+ 89+ ],+ "note": "Safe: sort_order is hardcoded as :desc or :asc at the call site, never from user input"+ },+ {+ "warning_type": "SQL Injection",+ "warning_code": 0,+ "fingerprint": "1365b154e2a8020d32c58a32394892212c8c575676ab0e6c51a379b1485ca38c",+ "check_name": "SQL",+ "message": "Possible SQL injection",+ "file": "app/sorters/spree/products/sort.rb",+ "line": 44,+ "link": "https://brakemanscanner.org/docs/warning_types/sql_injection/",+ "code": "scope.joins(:master).select(\"#{(\"\" or \"#{Spree::Product.table_name}.*, \")}#{Spree::Variant.table_name}.sku\").order(\"#{Spree::Variant.table_name}.sku #{sort_by?(\"sku\")[1]}\")",+ "render_path": null,+ "location": {+ "type": "method",+ "class": "Spree::Products::Sort",+ "method": "by_sku"+ },+ "user_input": "sort_by?(\"sku\")[1]",+ "confidence": "Weak",+ "cwe_id": [+ 89+ ],+ "note": "Safe: sort direction comes from BaseSorter#order_direction which only returns :desc or :asc"+ },+ {+ "warning_type": "SQL Injection",+ "warning_code": 0,+ "fingerprint": "3f8922e178006ab8f050ffd2636a2aa96241b5d754b4e019e9a1285feae4e57c",+ "check_name": "SQL",+ "message": "Possible SQL injection",+ "file": "app/sorters/spree/classifications/sort.rb",+ "line": 59,+ "link": "https://brakemanscanner.org/docs/warning_types/sql_injection/",+ "code": "scope.joins(:product => ({ :variants_including_master => :prices })).select(\"#{Spree::Classification.table_name}.*, min(#{Spree::Price.table_name}.amount)\").distinct.where(:spree_prices => ({ :currency => currency })).order(\"min(#{Spree::Price.table_name}.amount) #{sort_by?(\"price\")[1]}\")",+ "render_path": null,+ "location": {+ "type": "method",+ "class": "Spree::Classifications::Sort",+ "method": "by_price"+ },+ "user_input": "sort_by?(\"price\")[1]",+ "confidence": "Weak",+ "cwe_id": [+ 89+ ],+ "note": "Safe: sort direction comes from BaseSorter#order_direction which only returns :desc or :asc"+ },+ {+ "warning_type": "SQL Injection",+ "warning_code": 0,+ "fingerprint": "9d14b5b042473e45257286b5342318871ebe0c907ddbb3808151b5efb3281b36",+ "check_name": "SQL",+ "message": "Possible SQL injection",+ "file": "app/sorters/spree/products/sort.rb",+ "line": 30,+ "link": "https://brakemanscanner.org/docs/warning_types/sql_injection/",+ "code": "scope.joins(:variants_including_master => :prices).select(\"#{Spree::Product.table_name}.*, #{Spree::Price.table_name}.amount\").distinct.where(:\"#{Spree::Price.table_name}.currency\" => currency).order(\"#{Spree::Price.table_name}.amount #{sort_by?(\"price\")[1]}\")",+ "render_path": null,+ "location": {+ "type": "method",+ "class": "Spree::Products::Sort",+ "method": "by_price"+ },+ "user_input": "sort_by?(\"price\")[1]",+ "confidence": "Weak",+ "cwe_id": [+ 89+ ],+ "note": "Safe: sort direction comes from BaseSorter#order_direction which only returns :desc or :asc"+ }+ ],+ "brakeman_version": "8.0.2"+}diff --git a/core/lib/spree/testing_support/capybara_config.rb b/core/lib/spree/testing_support/capybara_config.rbindex 5aae71ffbf..c0bb2cc4de 100644--- a/core/lib/spree/testing_support/capybara_config.rb+++ b/core/lib/spree/testing_support/capybara_config.rb@@ -1,7 +1,7 @@require 'capybara-screenshot/rspec'Capybara.configure do |config|- config.save_path = ENV['CIRCLE_ARTIFACTS'] if ENV['CIRCLE_ARTIFACTS']+ config.save_path = ENV['CI_ARTIFACTS'] if ENV['CI_ARTIFACTS']config.server = :pumaconfig.default_driver = :rack_testconfig.javascript_driver = :selenium_chrome_headless@@ -27,7 +27,7 @@ Capybara.register_driver :selenium_chrome_headless do |app|options.add_argument '--window-size=1920,1080'options.add_argument '--disable-search-engine-choice-screen'- # Required for running in Docker containers (CircleCI)+ # Required for running in CI containersoptions.add_argument '--no-sandbox'options.add_argument '--disable-dev-shm-usage'diff --git a/core/spec/models/spree/concerns/user_methods_spec.rb b/core/spec/models/spree/concerns/user_methods_spec.rbindex b2e1c99609..c0fedf92ef 100644--- a/core/spec/models/spree/concerns/user_methods_spec.rb+++ b/core/spec/models/spree/concerns/user_methods_spec.rb@@ -131,22 +131,22 @@ describe Spree::UserMethods doendit 'returns users based on the first name' do- expect(Spree.user_class.multi_search('joh')).to eq([user_1, user_5])+ expect(Spree.user_class.multi_search('joh')).to match_array([user_1, user_5])expect(Spree.user_class.multi_search('jan')).to eq([user_2])expect(Spree.user_class.multi_search('greg')).to eq([])endit 'returns users based on the last name' do- expect(Spree.user_class.multi_search('do')).to eq([user_1, user_5])+ expect(Spree.user_class.multi_search('do')).to match_array([user_1, user_5])expect(Spree.user_class.multi_search('moe')).to eq([user_3])expect(Spree.user_class.multi_search('smith')).to eq([])endit 'returns users based on the full name' do- expect(Spree.user_class.multi_search('joh do')).to eq([user_1, user_5])+ expect(Spree.user_class.multi_search('joh do')).to match_array([user_1, user_5])expect(Spree.user_class.multi_search('ane gon')).to eq([user_2])expect(Spree.user_class.multi_search('mary moe')).to eq([user_3])- expect(Spree.user_class.multi_search('jane moe')).to eq([user_2, user_3])+ expect(Spree.user_class.multi_search('jane moe')).to match_array([user_2, user_3])expect(Spree.user_class.multi_search('greg smith')).to eq([])endenddiff --git a/core/spec/models/spree/property_spec.rb b/core/spec/models/spree/property_spec.rbindex 129248f01d..630f68a98f 100644--- a/core/spec/models/spree/property_spec.rb+++ b/core/spec/models/spree/property_spec.rb@@ -99,7 +99,7 @@ describe Spree::Property, type: :model doexpect(property.uniq_values).to eq([['some-value', 'Some Value'], ['another-10-value', 'Another 10% Value']])product_property_1 = create(:product_property, property: property, value: 'Some 20% Value')- expect(property.uniq_values).to eq(+ expect(property.uniq_values).to match_array([['some-value', 'Some Value'],['another-10-value', 'Another 10% Value'],@@ -113,14 +113,14 @@ describe Spree::Property, type: :model doscope = [product_property_1, product_property_2]other_scope = [product_property_2, product_property_3]- expect(property.uniq_values(product_properties_scope: scope)).to eq(+ expect(property.uniq_values(product_properties_scope: scope)).to match_array([['some-20-value', 'Some 20% Value'],['another-20-value', 'Another 20% Value']])- expect(property.uniq_values(product_properties_scope: other_scope)).to eq(+ expect(property.uniq_values(product_properties_scope: other_scope)).to match_array([['another-20-value', 'Another 20% Value'],['another-30-value', 'Another 30% Value']diff --git a/core/spec/models/spree/taxon_spec.rb b/core/spec/models/spree/taxon_spec.rbindex 91154171b2..8f6d97cdd9 100644--- a/core/spec/models/spree/taxon_spec.rb+++ b/core/spec/models/spree/taxon_spec.rb@@ -319,15 +319,18 @@ describe Spree::Taxon, type: :model docontext 'when root taxon attribute other than name is updated' doit 'does not update the taxonomy' doroot_taxon = described_class.find_by(name: 'Soft Goods')- taxonomy_updated_at = taxonomy.updated_at.to_s- expect {- root_taxon.update!(permalink: 'something-else')- root_taxon.reload- taxonomy.reload- }.not_to change { taxonomy.updated_at.to_s }.from(taxonomy_updated_at)+ Timecop.freeze do+ taxonomy_updated_at = taxonomy.updated_at.to_s- expect(root_taxon.permalink).to eql 'something-else'+ expect {+ root_taxon.update!(permalink: 'something-else')+ root_taxon.reload+ taxonomy.reload+ }.not_to change { taxonomy.updated_at.to_s }.from(taxonomy_updated_at)++ expect(root_taxon.permalink).to eql 'something-else'+ endendendenddiff --git a/core/spec/services/spree/stock_locations/stock_items/create_spec.rb b/core/spec/services/spree/stock_locations/stock_items/create_spec.rbindex 9abe59760c..d8272a8e0c 100644--- a/core/spec/services/spree/stock_locations/stock_items/create_spec.rb+++ b/core/spec/services/spree/stock_locations/stock_items/create_spec.rb@@ -30,7 +30,7 @@ module Spreestock_location.stock_items.unscope(:where).delete_allend- let(:created_stock_item) { stock_location.stock_items.order(:id).last }+ let(:created_stock_item) { stock_location.stock_items.find_by(variant_id: unrelated_variant.id) }let(:created_stock_item_attrs) docreated_stock_item.attributes.values_at('stock_location_id', 'variant_id', 'backorderable', 'created_at', 'updated_at'