diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index d8b69ee..5cc0624 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -8,12 +8,11 @@ on: pull_request: jobs: - build: + test: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - uses: ruby/setup-ruby@v1 with: ruby-version: "3.3" @@ -22,8 +21,32 @@ jobs: - name: Lint run: bundle exec rake standard + integration_test: + runs-on: ubuntu-latest + + needs: test + + strategy: + matrix: + include: + - ruby_version: "3.3" + redmine_branch_name: "master" + + steps: + - uses: actions/checkout@v4 + - uses: ruby/setup-ruby@v1 + with: + ruby-version: "3.3" + bundler-cache: true + - name: Set up test run: bundle exec rake rexer:test:build_integration_test_image + env: + RUBY_VERSION: ${{ matrix.ruby_version }} + REDMINE_BRANCH_NAME: ${{ matrix.redmine_branch_name }} - - name: Run tests - run: bundle exec rake test + - name: Run integration tests + run: bundle exec rake test:integration + env: + RUBY_VERSION: ${{ matrix.ruby_version }} + REDMINE_BRANCH_NAME: ${{ matrix.redmine_branch_name }} diff --git a/README.md b/README.md index e01dd65..cf7f952 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,10 @@ It is mainly aimed at helping with the development of Redmine and its plugins, a gem install rexer ``` +## Supported Redmine + +Rexer is tested with Redmine v5.1 and trunk. + ## Usage ### Quick Start @@ -120,20 +124,26 @@ end ## Developing -### Running integration tests +### Running tests First, you need to build the docker image for the integration tests. ``` -rake rexer:test:build_integration_test_image +rake test:prepare_integration ``` -Then, you can run the integration tests. +Then, you can run all tests. ``` rake test ``` +Or, you can only the integration tests as follows. + +``` +rake test:integration +``` + ### Formatting and Linting code This project uses [Standard](https://github.com/standardrb/standard) for code formatting and linting. You can format and check the code by running the following commands. diff --git a/Rakefile b/Rakefile index 5336e15..0c0add6 100644 --- a/Rakefile +++ b/Rakefile @@ -2,20 +2,31 @@ require "bundler/gem_tasks" require "rake/testtask" require "standard/rake" -Rake::TestTask.new(:test) do |t| +Rake::TestTask.new("test:integration") do |t| t.libs << "test" t.libs << "lib" - t.test_files = FileList["test/**/*_test.rb"] + t.test_files = FileList["test/integration/**/*_test.rb"] t.warning = false end task default: %i[test standard] -namespace :rexer do - namespace :test do - desc "Build the integration test image" - task :build_integration_test_image do - system "docker build -f test/integration/Dockerfile -t rexer-test .", exception: true - end +desc "Run all tests" +task test: %i[test:integration] + +namespace :test do + desc "Prepare to run integration tests" + task :prepare_integration do + ruby_version = ENV["RUBY_VERSION"] || "3.3" + redmine_branch_name = ENV["REDMINE_BRANCH_NAME"] || "master" + + image_tag = "rexer-test:#{ruby_version}-#{redmine_branch_name}" + + system(<<~CMD, exception: true) + docker build -f test/integration/Dockerfile \ + --build-arg RUBY_VERSION=#{ruby_version} \ + --build-arg REDMINE_BRANCH_NAME=#{redmine_branch_name} \ + -t #{image_tag} . + CMD end end diff --git a/lib/rexer/extension/theme.rb b/lib/rexer/extension/theme.rb index 2d3ee40..44dd82d 100644 --- a/lib/rexer/extension/theme.rb +++ b/lib/rexer/extension/theme.rb @@ -2,7 +2,14 @@ module Rexer module Extension module Theme def self.dir - Pathname.new("themes") + public_themes = Pathname.pwd.join("public", "themes") + + if public_themes.exist? + # When Redmine version is v5.1 or older, public/themes is used. + public_themes + else + Pathname.new("themes") + end end class Base diff --git a/test/integration/Dockerfile b/test/integration/Dockerfile index 5afd142..a926827 100644 --- a/test/integration/Dockerfile +++ b/test/integration/Dockerfile @@ -2,6 +2,8 @@ ARG RUBY_VERSION=3.3 FROM ruby:$RUBY_VERSION +ARG REDMINE_BRANCH_NAME=master + RUN set -eux; \ apt-get update; \ apt-get install -y --no-install-recommends \ @@ -52,7 +54,7 @@ RUN git init && \ # Redmine # WORKDIR /redmine -RUN git clone --depth 1 https://github.com/redmine/redmine.git . +RUN git clone -b $REDMINE_BRANCH_NAME --depth 1 https://github.com/redmine/redmine.git . COPY test/integration/docker/database.yml config/database.yml # Directory for the bundle cache diff --git a/test/integration/docker/plugin_a/app/models/hello.rb b/test/integration/docker/plugin_a/app/models/hello.rb index d766d5e..b4e9185 100644 --- a/test/integration/docker/plugin_a/app/models/hello.rb +++ b/test/integration/docker/plugin_a/app/models/hello.rb @@ -1,2 +1,2 @@ -class Hello < ApplicationRecord +class Hello < (defined?(ApplicationRecord) ? ApplicationRecord : ActiveRecord::Base) end diff --git a/test/integration/docker/plugin_a/db/migrate/20240813045236_create_hellos.rb b/test/integration/docker/plugin_a/db/migrate/20240813045236_create_hellos.rb index 05e80a8..2e436ed 100644 --- a/test/integration/docker/plugin_a/db/migrate/20240813045236_create_hellos.rb +++ b/test/integration/docker/plugin_a/db/migrate/20240813045236_create_hellos.rb @@ -1,4 +1,4 @@ -class CreateHellos < ActiveRecord::Migration[7.1] +class CreateHellos < ActiveRecord::Migration[6.1] def change create_table :hellos do |t| t.string :world diff --git a/test/integration/integration_helper.rb b/test/integration/integration_helper.rb index 25cd504..a41f3e0 100644 --- a/test/integration/integration_helper.rb +++ b/test/integration/integration_helper.rb @@ -3,6 +3,8 @@ require "rake" ENV["VERBOSE"] = "1" +ENV["RUBY_VERSION"] ||= "3.3" +ENV["REDMINE_BRANCH_NAME"] ||= "master" module IntegrationHelper Result = Data.define(:output_raw, :error_raw, :status_raw) do @@ -15,7 +17,9 @@ def error = error_raw.strip def success? = status_raw.success? end - def image_name = "rexer-test" + def image_name + @image_name ||= "rexer-test:#{ENV["RUBY_VERSION"]}-#{ENV["REDMINE_BRANCH_NAME"]}" + end def container_name = "rexer-test-container" @@ -62,4 +66,13 @@ def docker_exec(*command, raise: false) def docker_stop run_with_capture("docker container stop -t 0 #{container_name} && docker container rm #{container_name}", raise: true) end + + def legacy_theme_dir? + return @legacy_theme_dir if defined?(@legacy_theme_dir) + @legacy_theme_dir = docker_exec("test -d /redmine/public/themes").success? + end + + def theme_dir + legacy_theme_dir? ? "/redmine/public/themes" : "/redmine/themes" + end end diff --git a/test/integration/integration_test.rb b/test/integration/integration_test.rb index 7d12a79..8d1ae9d 100644 --- a/test/integration/integration_test.rb +++ b/test/integration/integration_test.rb @@ -43,8 +43,8 @@ class IntegrationTest < Test::Unit::TestCase assert_equal "plugin_a", result.output.last end - docker_exec("ls themes").then do |result| - assert_equal "theme_a", result.output.last + docker_exec("ls #{theme_dir}").then do |result| + assert_includes result.output.last, "theme_a" end docker_exec("bin/rails r 'puts Hello.table_name'").then do |result| @@ -60,8 +60,9 @@ class IntegrationTest < Test::Unit::TestCase assert_equal ["README"], result.output end - docker_exec("ls themes").then do |result| - assert_equal ["README"], result.output + docker_exec("ls #{theme_dir}").then do |result| + expected_files = legacy_theme_dir? ? %w[README alternate classic] : %w[README] + assert_equal expected_files, result.output end docker_exec("rex state").then do |result| @@ -120,7 +121,7 @@ class IntegrationTest < Test::Unit::TestCase assert_equal "update", result.output_str end - docker_exec("cat /redmine/themes/theme_a/README").then do |result| + docker_exec("cat #{theme_dir}/theme_a/README").then do |result| assert_equal "update", result.output_str end