在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:Sage/fudge开源软件地址:https://github.com/Sage/fudge开源编程语言:Ruby 100.0%开源软件介绍:FudgeDescriptionFudge is a CI build tool for Ruby/Rails projects. Features
InstallationAdd to your project's Gemfile: gem 'fudge' Run in your project root:
UsageTo create a blank Fudgefile, run in your project root:
To run the CI build (this is what you'd put in your CI server):
This will run the build named 'default'. To run a specific build in the Fudgefile:
To list builds defined in your Fudgefile:
The list of builds can be filtered to include only those whose name match a given string (case-insensitive):
Fudgefile syntaxTo define a build with a given name (or for a given branch): build :some_name do
end An optional description can be provided by supplying an about string (descriptions, if supplied, are output by the list command): build :some_name, :about => "Runs Rspec unit tests" do
end To define some tasks on that build: build :some_name do
task :rspec, :coverage => 100
end Any options passed to the task method will be passed to the task's initializer. You can also use one of the alternative method missing syntax: build :some_name do |b|
rspec :coverage => 100
end Composite TasksSome tasks are composite tasks, and can have tasks added to themselves, for example the each_directory task: build :some_name do
task :each_directory, '*' do
task :rspec
end
end Task GroupsYou can define task groups to be reused later on in your Fudgefile. For example: task_group :tests do
rspec
end
task_group :docs do
yard
end
task_group :quality do
cane
end
build :some_name do
task_group :tests
task_group :docs
task_group :quality
end
build :nodoc do
task_group :tests
end Task groups can take arguments, so you can make conditional task groups for sharing between build. For example: task_group :deploy do |to|
shell "cp -r site/ #{to}"
end
build :default do
task_group :deploy, '/var/www/dev'
end
build :production do
task_group :deploy, '/var/www/live'
end CallbacksYou can define success and failure callbacks using the following syntax: build :default do
rspec
on_success do
shell 'deploy.sh'
end
on_failure do
shell 'send_errors.sh'
end
end Build will by default run without callbacks enabled. To run a build with callbacks, run:
You can mix task groups with callbacks however you like, for example: task_group :deploy do
shell 'deploy.sh'
end
task_group :error_callbacks do
on_failure do
shell 'send_errors.sh'
end
end
build :default do
on_success do
task_group :deploy
end
task_group :error_callbacks
end Built-in tasksFudge supports several tasks by default. Most of them depend on a gem which also must be included in your project's brakemanRun the Brakeman Rails security scanner.
will fail if any security warnings are encountered.
will allow a maximum of two known security issues to get through. caneChecks code style using the cane gem. This can be run over the entire tree or in the enclosing subdirectory (
clean_bundler_envEnsures that the code block runs in a clean Bundler environment. each_directoryRun the resulting block in each directory (see examples above).
rakeRun a shellRun a generic shell command, requiring that it return success. sub_processLike shell, but does not spawn a new shell to run the command, and allows more control over the command's process and environment. See examples below. flayCode duplication can be detected by Flay. See examples below. flogFlog calculates code complexity using an ABC metric and allows for maximum individual values and maximum average values. This can be used to ensure that you are alerted quickly when new complex code is added to your project. See examples below. in_directoryRun the resulting block in a specific directory (as with rspecRun cucumberRun yardRuns YARD to ensure documentation coverage.
will require 100% coverage, and show all code that is not documented. Defining tasksA task is a class that responds to two methods:
For example, here is a simple task which will print some output and always pass: class LoudTask < Fudge::Tasks::Task
def self.name
:loud
end
def run
puts "I WAS RUN"
true
end
end Registering your taskTo make your task available to Fudge, you simply register it in require 'fudge'
Fudge::Tasks.register(LoudTask) This will make the build :some_name do
task :loud
end Extending the Shell taskMany tasks simply run a shell command and may accept some extra configuration options. To define a task of this kind, you can sublcass class LsTask < Fudge::Tasks::Shell
def cmd
"ls #{arguments}"
end
end The build :default do
task :ls, '-l', '-a'
end would run the command You can take hash-like options, which will automatically be set if you have an attribute with the same name. For example: class LsTask < Fudge::Tasks::Shell
attr_accessor :all
def cmd
arguments << ' -a' if all
"ls #{arguments}"
end
end Now this task can be used like so: build :default do
task :ls, :all => true
end Checking output with the Shell taskYou can define that some output from a command is required by responding to class LsTask < Fudge::Tasks::Shell
def cmd
"ls #{arguments}"
end
def check_for
/4 files found/
end
end The above task will only pass if the output contains "4 files found". If you want to do some further processing on the contents matched by the regexp, you can provide an array with the second element being a lambda, which wil be called to process the output: class LsTask < Fudge::Tasks::Shell
def cmd
"ls #{arguments}"
end
def check_for
[/(\d+) files found/, lambda { |n| n.to_i >= 4 }]
end
end The above task will only pass if the output contains "n files found", where n is a number, and also n is at least 4. Using the SubProcess taskThis task is useful if you want to set an environment variable for a shell command, but the command won't allow the variable to be supplied at the end of the command line. That is, if something like this doesn't work because the command treats the variable assignment as a parameter: task :shell, 'awkward_command SOME_VAR=true'
# This won't work either because shell tries to run a command called SOME_VAR=:
task :shell, 'SOME_VAR=true awkward_command' SubProcess allows you to set the variable this way: task :sub_process, 'awkward_command', :environment => { 'SOME_VAR' => 'true' } SubProcess is also useful if you need to manipulate the process's execution environment, for example, by clearing environment variables, or redirecting IO. For example, this invocatin will unset all environment variables, except SOME_VAR which is explicitly supplied, before running command: task :sub_process, 'command', :environment => { 'SOME_VAR' => 'true' },
:spawn_options => { :unsetenv_others => true } See the Ruby doc for Process::spawn for details of the options that can be passed in This task should otherwise act like the Shell task. Defining composite tasksSome tasks may require you to run a number of commands one after the other. You can hook into other fudge tasks by including the Fudge DSL into your composite task: class DeployTask < Fudge::Tasks::CompositeTask
include Fudge::TaskDSL
def self.name
:deploy
end
def initialize(*args)
super
task :shell, 'build_docs.sh'
task :shell, 'cp -r docs/ /var/ww/deploy/docs'
end
end
Fudge::Tasks.register(DeployTask) The above will run the given tasks in the order defined, and only pass if both tasks pass. It can then be used in a FudgeFile like so: build :default do
task :deploy
end Setting per-directory options for tasksSometimes you'll want different options to be used for specific subdirectories. This is especially useful with code metric tools. Instead of having all of these values listed explicitly in your Fudgefile you can instead place them in a So instead of this in your in_directory 'meta_addresses' do
task :flay, :exclude => '^\.\/(db|factories|spec)\/'
task :flog, :exclude => '^\.\/(db|factories|spec)\/', :max => 20, :average => 5, :methods => true
end
in_directory 'meta_banks' do
task :flay, :exclude => '^\.\/(db|factories|spec)\/', :max => 172
task :flog, :exclude => '^\.\/(db|factories|spec)\/', :max => 74.9, :average => 9.1, :methods => true
end you can just have this: each_directory 'meta_*' do
task :flay, :exclude => '^\.\/(db|factories|spec)\/'
task :flog, :exclude => '^\.\/(db|factories|spec)\/', :methods => true
end and this in your
and this in your
You can set the default values in your LicenseThis gem is available as open source under the terms of the MIT licence. Copyright (c) 2018 Sage Group Plc. All rights reserved. |
2022-08-15
2022-08-17
2022-09-23
2023-10-27
2022-08-18
请发表评论