From c5659eafbe8b5aa26fef9329d5a981aeb42c95d4 Mon Sep 17 00:00:00 2001
From: Katsuya Hidaka <hidakatsuya@gmail.com>
Date: Sun, 12 Jan 2025 11:52:44 +0900
Subject: [6.0-stable] Enable GitHub Actions for testing and linting on
 6.0-stable branch

---
 .github/workflows/linters.yml     |  55 +++++++++++++++
 .github/workflows/rubyonrails.yml |  17 -----
 .github/workflows/tests.yml       | 112 ++++++++++++++++++++++++++++++
 .stylelintrc                      |   5 +-
 Gemfile                           |   1 +
 5 files changed, 172 insertions(+), 18 deletions(-)
 create mode 100644 .github/workflows/linters.yml
 delete mode 100644 .github/workflows/rubyonrails.yml
 create mode 100644 .github/workflows/tests.yml

diff --git a/.github/workflows/linters.yml b/.github/workflows/linters.yml
new file mode 100644
index 000000000..54ffd08df
--- /dev/null
+++ b/.github/workflows/linters.yml
@@ -0,0 +1,55 @@
+name: Lint
+
+on:
+  push:
+
+jobs:
+  lint:
+    runs-on: ubuntu-latest
+
+    steps:
+      - name: Checkout code
+        uses: actions/checkout@v4
+
+      - name: Set up Ruby
+        uses: ruby/setup-ruby@v1
+        with:
+          ruby-version: 3.2
+          bundler-cache: true
+
+      - name: Lint code for consistent style
+        run: bundle exec rubocop --parallel
+
+  stylelint:
+    runs-on: ubuntu-latest
+
+    steps:
+      - name: Checkout code
+        uses: actions/checkout@v4
+
+      - name: Set up Node.js
+        uses: actions/setup-node@v2
+        with:
+          node-version: '20'
+
+      - name: Install dependencies
+        run: yarn install
+
+      - name: Lint CSS and SCSS files
+        run: npx stylelint "app/assets/stylesheets/**/*.css"
+
+  bundle-audit:
+    runs-on: ubuntu-latest
+
+    steps:
+      - name: Checkout code
+        uses: actions/checkout@v4
+
+      - name: Set up Ruby
+        uses: ruby/setup-ruby@v1
+        with:
+          ruby-version: '3.2'
+          bundler-cache: true
+
+      - name: Run bundle-audit
+        run: bundle exec bundle audit check --update
diff --git a/.github/workflows/rubyonrails.yml b/.github/workflows/rubyonrails.yml
deleted file mode 100644
index d147851b2..000000000
--- a/.github/workflows/rubyonrails.yml
+++ /dev/null
@@ -1,17 +0,0 @@
-name: "Ruby on Rails CI"
-on:
-  push:
-
-jobs:
-  lint:
-    runs-on: ubuntu-latest
-    steps:
-      - name: Checkout code
-        uses: actions/checkout@v4
-      - name: Install Ruby and gems
-        uses: ruby/setup-ruby@v1
-        with:
-          ruby-version: 3.2
-          bundler-cache: true
-      - name: Lint Ruby files
-        run: bundle exec rubocop --parallel
diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml
new file mode 100644
index 000000000..12b507b0e
--- /dev/null
+++ b/.github/workflows/tests.yml
@@ -0,0 +1,112 @@
+name: Tests
+
+on:
+  push:
+
+jobs:
+  tests:
+    name: test ${{matrix.db}} ruby-${{ matrix.ruby }}
+    runs-on: ubuntu-latest
+
+    strategy:
+      matrix:
+        ruby: ['3.1', '3.2', '3.3']
+        db: ['postgresql', 'mysql2', 'sqlite3']
+      fail-fast: false
+
+    services:
+      postgres:
+        image: postgres:13
+        env:
+          POSTGRES_DB: redmine_test
+          POSTGRES_USER: root
+          POSTGRES_PASSWORD: root
+        ports:
+          - 5432:5432
+        options: >-
+          --health-cmd pg_isready
+          --health-interval 10s
+          --health-timeout 5s
+          --health-retries 5
+
+      mysql:
+        image: mysql:8.0
+        env:
+          MYSQL_DATABASE: redmine_test
+          MYSQL_ROOT_PASSWORD: 'root'
+        ports:
+          - 3306:3306
+        options: >-
+          --health-cmd="mysqladmin ping"
+          --health-interval=10s
+          --health-timeout=5s
+          --health-retries=3
+
+    steps:
+      - name: Checkout code
+        uses: actions/checkout@v4
+
+      - name: Install dependencies and configure environment
+        run: |
+          sudo apt-get update
+          sudo apt-get install --yes --quiet ghostscript gsfonts locales bzr cvs
+          sudo locale-gen en_US # for bazaar non ascii test
+
+      - name: Allow imagemagick to read PDF files
+        run: |
+          echo '<policymap>' > policy.xml
+          echo '<policy domain="coder" rights="read | write" pattern="PDF" />' >> policy.xml
+          echo '</policymap>' >> policy.xml
+          sudo rm /etc/ImageMagick-6/policy.xml
+          sudo mv policy.xml /etc/ImageMagick-6/policy.xml
+
+      - if: ${{ matrix.db == 'sqlite3' }}
+        name: Prepare test database for sqlite3
+        run: |
+          cat > config/database.yml <<EOF
+          test:
+            adapter: sqlite3
+            database: db/test.sqlite3
+          EOF
+
+      - if: ${{ matrix.db == 'mysql2' || matrix.db == 'postgresql' }}
+        name: Prepare test database for mysql2 and postgresql
+        run: |
+          cat > config/database.yml <<EOF
+          test:
+            adapter: ${{ matrix.db }}
+            database: redmine_test
+            username: root
+            password: root
+            host: 127.0.0.1
+          EOF
+
+      - name: Install Ruby and gems
+        uses: ruby/setup-ruby@v1
+        with:
+          ruby-version: ${{ matrix.ruby }}
+          bundler-cache: true
+
+      - name: Run prepare test environment
+        env:
+          RAILS_ENV: test
+          SCMS: subversion,git,git_utf8,filesystem,bazaar,cvs
+        run: |
+          bundle exec rake ci:about
+          bundle exec rake ci:setup
+          bundle exec rake db:environment:set
+
+      - name: Run tests
+        run: |
+          bin/rails test
+
+      - name: Run bazaar non ascii test
+        env:
+          LANG: en_US.ISO8859-1
+          LC_ALL: en_US.ISO8859-1
+        run: |
+          bin/rails test test/unit/repository_bazaar_test.rb
+
+      - name: Run autoload test
+        run: |
+          bin/rails test:autoload
diff --git a/.stylelintrc b/.stylelintrc
index ea5c7df0f..6ee7b505e 100644
--- a/.stylelintrc
+++ b/.stylelintrc
@@ -22,5 +22,8 @@
     "no-duplicate-selectors": true,
     "no-empty-source": true,
     "no-invalid-double-slash-comments": true,
-  }
+  },
+  "ignoreFiles": [
+    "app/assets/stylesheets/jquery/*.css"
+  ]
 }
diff --git a/Gemfile b/Gemfile
index 732333daf..18f4c7265 100644
--- a/Gemfile
+++ b/Gemfile
@@ -113,6 +113,7 @@ group :test do
   gem 'rubocop', '~> 1.68.0', require: false
   gem 'rubocop-performance', '~> 1.22.0', require: false
   gem 'rubocop-rails', '~> 2.27.0', require: false
+  gem 'bundle-audit', require: false
 end
 
 local_gemfile = File.join(File.dirname(__FILE__), "Gemfile.local")
-- 
2.45.2

