Skip to content

Commit

Permalink
Merge pull request #8 from hidakatsuya/dev/redmine-version-envs
Browse files Browse the repository at this point in the history
Add Redmine version extraction and environment-specific adjustments based on Redmine version
  • Loading branch information
hidakatsuya authored Jul 11, 2024
2 parents 84646e2 + 86ecd00 commit 860124d
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 16 deletions.
26 changes: 18 additions & 8 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,25 +60,35 @@ jobs:
database: ${{ matrix.redmine-database }}
ruby-version: ${{ matrix.ruby-version }}

- name: Define Redmine version environment variables
run: ./scripts/set-version-envs.sh
env:
REDMINE_DIR: ${{ env.REDMINE_SRC }}

- name: Install a plugin for testing
run: |
cp -R ../.github/hello_world plugins/
bin/rails redmine:plugins:migrate
working-directory: ${{ env.REDMINE_SRC }}

- run: |
- name: Test Redmine environment
run: |
about=$(bin/rails r "require 'redmine/version'; puts Redmine::Info.environment")
echo "$about"
echo "$about" | grep "${{ matrix.expected-about-db-adapter }}"
echo "$about" | grep "${{ matrix.expected-about-redmine-version }}"
echo "$about" | grep "hello_world"
working-directory: ${{ env.REDMINE_SRC }}

- run: |
bin/rails test test/unit/news_test.rb
# Run system test only when Zeitwerk is enabled (Redmine >= 5.0 or RedMica >= 2.1)
if grep -q zeitwerk config/application.rb ; then
bin/rails test test/system/my_page_test.rb
fi
bin/rails redmine:plugins:test
- name: Run unit test
run: bin/rails test test/unit/news_test.rb
working-directory: ${{ env.REDMINE_SRC }}

- name: Run system test if Redmine >= 5.0
if: ${{ env.REDMINE_VERSION_MAJOR >= 5 }}
run: bin/rails test test/system/my_page_test.rb
working-directory: ${{ env.REDMINE_SRC }}

- name: Run plugin test
run: bin/rails redmine:plugins:test
working-directory: ${{ env.REDMINE_SRC }}
18 changes: 10 additions & 8 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ runs:
ref: ${{ inputs.version }}
path: ${{ inputs.path }}

- name: Define Redmine version environment variables
run: ./scripts/set-version-envs.sh
shell: bash
env:
REDMINE_DIR: ${{ inputs.path }}

- name: Install dependencies
run: |
sudo apt-get update; \
Expand Down Expand Up @@ -136,14 +142,10 @@ runs:
shell: bash
working-directory: ${{ inputs.path }}

- name: Adjust Gemfile
run: |
# Ref: https://github.com/agileware-jp/redmine-plugin-orb/pull/70
# https://www.redmine.org/issues/40802
if grep -q "require 'blankslate'" lib/redmine/views/builders/structure.rb
then
echo 'gem "blankslate"' >> Gemfile
fi
# https://www.redmine.org/issues/40802
- name: Fix LoadError in Redmine 4.2
if: ${{ env.REDMINE_VERSION_MAJOR < 5 }}
run: echo "gem 'builder', '~> 3.2.4'" >> Gemfile.local
shell: bash
working-directory: ${{ inputs.path }}

Expand Down
17 changes: 17 additions & 0 deletions scripts/set-version-envs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash

set -eu

file=$REDMINE_DIR/lib/redmine/version.rb

version_major=$(grep -oE 'MAJOR *= *[0-9]+' $file | awk 'NR==1 {print $3}')
version_minor=$(grep -oE 'MINOR *= *[0-9]+' $file | awk 'NR==1 {print $3}')
version_tiny=$(grep -oE 'TINY *= *[0-9]+' $file | awk 'NR==1 {print $3}')
version_branch=$(grep -oE 'BRANCH *= *'\''.+?' $file | awk -F"'" 'NR==1 {print $2}')

echo "Redmine Version: $version_major.$version_minor.$version_tiny.$version_branch"

echo "REDMINE_VERSION_MAJOR=$version_major" >> $GITHUB_ENV
echo "REDMINE_VERSION_MINOR=$version_minor" >> $GITHUB_ENV
echo "REDMINE_VERSION_TINY=$version_tiny" >> $GITHUB_ENV
echo "REDMINE_VERSION_BRANCH=$version_branch" >> $GITHUB_ENV

0 comments on commit 860124d

Please sign in to comment.