Skip to content

Commit

Permalink
Prototype version and rename to Rexer
Browse files Browse the repository at this point in the history
  • Loading branch information
hidakatsuya committed Aug 14, 2024
1 parent 5d3972a commit 1d05dc2
Show file tree
Hide file tree
Showing 52 changed files with 1,376 additions and 140 deletions.
29 changes: 29 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Build

on:
push:
branches:
- main
- "dev/**"
pull_request:

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- uses: ruby/setup-ruby@v1
with:
ruby-version: "3.3"
bundler-cache: true

- name: Lint
run: bundle exec rake standard

- name: Set up test
run: bundle exec rake rexer:test:build_integration_test_image

- name: Run tests
run: bundle exec rake test
27 changes: 0 additions & 27 deletions .github/workflows/main.yml

This file was deleted.

2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@
/pkg/
/spec/reports/
/tmp/
/Gemfile.lock
/*.gem
3 changes: 0 additions & 3 deletions .standard.yml

This file was deleted.

5 changes: 0 additions & 5 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
# frozen_string_literal: true

source "https://rubygems.org"

# Specify your gem's dependencies in redminep.gemspec
gemspec

gem "rake", "~> 13.0"

gem "test-unit", "~> 3.0"

gem "standard", "~> 1.3"
146 changes: 134 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,34 +1,156 @@
# Redminep
# Rexer: Redmine Extension manager

TODO: Delete this and the text below, and describe your gem
Rexer is a tool for managing Redmine Extension, which means Redmine [Plugin](https://www.redmine.org/projects/redmine/wiki/Plugins) and [Theme](https://www.redmine.org/projects/redmine/wiki/Themes) in this tool.

Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/redminep`. To experiment with that code, run `bin/console` for an interactive prompt.
It is mainly aimed at helping with the development of Redmine and its plugins, allowing you to define extensions in a Ruby DSL and install, uninstall, update, and switch between different sets of the extensions.

## Installation
[![Build](https://github.com/hidakatsuya/rexer/actions/workflows/build.yml/badge.svg)](https://github.com/hidakatsuya/rexer/actions/workflows/build.yml)
[![Gem Version](https://badge.fury.io/rb/rexer.svg)](https://badge.fury.io/rb/rexer)

TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
## Installation

Install the gem and add to the application's Gemfile by executing:

$ bundle add UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
bundle add rexer

If bundler is not being used to manage dependencies, install the gem by executing:

$ gem install UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
gem install rexer

## Usage

TODO: Write usage instructions here
### Quick Start

First, create a `.extensions.rb` file in the root directory of the Redmine application.

```ruby
theme :bleuclair, github: { repo: "farend/redmine_theme_farend_bleuclair", branch: "support-propshaft" }

plugin :view_customize, github: { repo: "onozaty/redmine-view-customize", tag: "v3.5.2" }
plugin :redmine_issues_panel, git: { url: "https://github.com/redmica/redmine_issues_panel", tag: "v1.0.2" }
```

Then, run the following command in the root directory of the Redmine application.

```
rex install
```

This command installs plugins and themes defined in the `.extensions.rb` file and generates the `.extensions.lock` file.

> [!NOTE]
> The `.extensions.lock` file is a file that locks the state of the installed extensions, but it's NOT a file that locks the version of the extensions.
If you want to uninstall the extensions, run the following command.

```
rex uninstall
```

This command uninstalls the extensions and deletes the `.extensions.lock` file.

### Commands

```
$ rex
Commands:
rex help [COMMAND] # Describe available commands or one specific command
rex install [ENV] # Install extensions for the specified environment
rex state # Show the current state of the installed extensions
rex switch [ENV] # Uninstall extensions for the currently installed environment and install extensions for the specified environment
rex uninstall # Uninstall extensions for the currently installed environment
rex update # Update extensions for the currently installed environment to the latest version
rex version # Show Rexer version
```

### Defining environments and extensions for the environment

```ruby
theme :bleuclair, github: { repo: "farend/redmine_theme_farend_bleuclair" }
plugin :redmine_issues_panel, git: { url: "https://github.com/redmica/redmine_issues_panel" }

env :stable do
theme :bleuclair, github: { repo: "farend/redmine_theme_farend_bleuclair", branch: "support-propshaft" }
plugin :redmine_issues_panel, git: { url: "https://github.com/redmica/redmine_issues_panel", tag: "v1.0.2" }
end
```

In above example, the `bleuclair` theme and the `redmine_issues_panel` plugin are defined for the `default` environment. The `bleuclair` theme and the `redmine_issues_panel` plugin are defined for the `stable` environment.

If you want to install extensions for the `default` environment, run the following command.

```
rex install
or
rex install default
```

Similarly, if you want to install extensions for the `stable` environment, run the following command.

```
rex install stable
```

In addition, you can switch between environments.

```
rex switch stable
or
rex install stable
```

The above command uninstalls the extensions for the currently installed environment and installs the extensions for the `stable` environment.

### Defining hooks

You can define hooks for each extension.

```ruby
plugin :redmica_s3, github: { repo: "redmica/redmica_s3" } do
installed do
Pathname.new("config", "s3.yml").write <<~YAML
access_key_id: ...
YAML
end

uninstalled do
Pathname.new("config", "s3.yml").delete
end

updated do
puts "updated"
end
end
```

## Developing

### Running integration tests

First, you need to build the docker image for the integration tests.

```
rake rexer:test:build_integration_test_image
```

Then, you can run the integration tests.

```
rake test
```

## Development
### Formatting and Linting code

After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test-unit` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
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.

To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
```
rake standard
rake standard:fix
```

## Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/redminep.
Bug reports and pull requests are welcome on GitHub at https://github.com/hidakatsuya/rexer.

## License

Expand Down
15 changes: 11 additions & 4 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
# frozen_string_literal: true

require "bundler/gem_tasks"
require "rake/testtask"
require "standard/rake"

Rake::TestTask.new(:test) do |t|
t.libs << "test"
t.libs << "lib"
t.test_files = FileList["test/**/*_test.rb"]
t.warning = false
end

require "standard/rake"

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
end
end
3 changes: 1 addition & 2 deletions bin/console
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

require "bundler/setup"
require "redminep"
require "rexer"

# You can add fixtures and/or initialization code here to make experimenting
# with your gem easier. You can also use a different console, if you like.
Expand Down
5 changes: 5 additions & 0 deletions bin/dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env ruby

require_relative "../lib/rexer"

Rexer::Cli.start(ARGV)
8 changes: 0 additions & 8 deletions bin/setup

This file was deleted.

3 changes: 0 additions & 3 deletions exe/redminep

This file was deleted.

11 changes: 11 additions & 0 deletions exe/rex
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env ruby

require "rexer"

begin
Rexer::Cli.start(ARGV)
rescue => e
puts "ERROR (#{e.class}): #{e.message}"
puts e.backtrace if ENV["VERBOSE"]
exit 1
end
8 changes: 0 additions & 8 deletions lib/redminep.rb

This file was deleted.

5 changes: 0 additions & 5 deletions lib/redminep/version.rb

This file was deleted.

16 changes: 16 additions & 0 deletions lib/rexer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module Rexer
def self.definition_file
".extensions.rb"
end

def self.definition_lock_file
".extensions.lock"
end
end

require "pathname"
require "zeitwerk"

loader = Zeitwerk::Loader.for_gem
loader.setup
loader.eager_load
50 changes: 50 additions & 0 deletions lib/rexer/cli.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
require "thor"

module Rexer
class Cli < Thor
def self.exit_on_failure? = true

class_option :verbose, type: :boolean, aliases: "-v", desc: "Detailed output"

desc "install [ENV]", "Install the definitions in .extensions.rb for the specified environment"
def install(env = "default")
Commands::Install.new.call(env&.to_sym)
end

desc "uninstall", "Uninstall extensions for the currently installed environment based on the state in .extensions.lock and remove the lock file"
def uninstall
Commands::Uninstall.new.call
end

desc "switch [ENV]", "Uninstall extensions for the currently installed environment and install extensions for the specified environment"
def switch(env = "default")
Commands::Switch.new.call(env&.to_sym)
end

desc "update", "Update extensions for the currently installed environment to the latest version"
def update
Commands::Update.new.call
end

desc "state", "Show the current state of the installed extensions"
def state
Commands::State.new.call
end

desc "version", "Show Rexer version"
def version
puts Rexer::VERSION
end

def initialize(*)
super
initialize_options
end

private

def initialize_options
ENV["VERBOSE"] = "1" if options[:verbose]
end
end
end
Loading

0 comments on commit 1d05dc2

Please sign in to comment.