-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Merge jobs and executor * Renamed executors to jobs * Renamed commands directory * Moved application to separate file * No more models * Capturing multiple signals in one block * Adjusting config tests * Adjusting coding style
- Loading branch information
1 parent
cab2099
commit 253cc6b
Showing
14 changed files
with
285 additions
and
284 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,51 @@ | ||
require "./spec_helper" | ||
|
||
describe "Config" do | ||
it "should load the config file" do | ||
config = Werk::Model::Config.load_file("werk.yml") | ||
|
||
config.is_a?(Werk::Model::Config).should eq true | ||
it "empty" do | ||
expect_raises(Exception, "Empty configuration!") do | ||
config = Werk::Config.load_string("") | ||
end | ||
end | ||
|
||
it "should fail for non existing file" do | ||
expect_raises(Exception, "Configuration file missing!") do | ||
Werk::Model::Config.load_file("werk.yaml") | ||
it "invalid" do | ||
expect_raises(Exception, /^Parse error/) do | ||
config = Werk::Config.load_string(%( | ||
version: 1 | ||
jobs: | ||
main: | ||
executor: shell | ||
)) | ||
end | ||
end | ||
|
||
it "should fail for empty content" do | ||
temp = File.tempfile | ||
File.write(temp.path, "") | ||
it "valid" do | ||
config = Werk::Config.load_string(%( | ||
version: 1.0 | ||
expect_raises(Exception, "Configuration file is empty!") do | ||
Werk::Model::Config.load_file(temp.path) | ||
end | ||
jobs: | ||
shell: | ||
executor: local | ||
container: | ||
executor: docker | ||
)) | ||
|
||
temp.delete | ||
config.should be_a Werk::Config | ||
config.version.should eq "1.0" | ||
config.jobs.keys.should eq ["shell", "container"] | ||
|
||
config.jobs["shell"].should be_a Werk::Job::Local | ||
config.jobs["container"].should be_a Werk::Job::Docker | ||
end | ||
|
||
it "should fail with parsing error" do | ||
temp = File.tempfile | ||
File.write(temp.path, "jobs: []") | ||
it "should load the config file" do | ||
config = Werk::Config.load_file("werk.yml") | ||
config.should be_a Werk::Config | ||
end | ||
|
||
expect_raises(Exception, "Parse error at line 1, column 7") do | ||
Werk::Model::Config.load_file(temp.path) | ||
it "should fail for non existing file" do | ||
expect_raises(Exception, "Configuration file missing!") do | ||
Werk::Config.load_file("werk.yaml") | ||
end | ||
|
||
temp.delete | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
require "spec" | ||
require "../src/model/*" | ||
require "../src/executor/*" | ||
|
||
require "../src/config" | ||
require "../src/report" | ||
require "../src/jobs/*" | ||
require "../src/utils/*" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
require "admiral" | ||
|
||
require "./version" | ||
require "./commands/*" | ||
|
||
module Werk | ||
class Application < Admiral::Command | ||
define_version Werk::VERSION | ||
define_help description: "Werk" | ||
|
||
register_sub_command plan : Werk::Command::Plan, | ||
description: "Display execution plan" | ||
|
||
register_sub_command run : Werk::Command::Run, | ||
description: "Run a job by name" | ||
|
||
def run | ||
puts help | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
require "yaml" | ||
|
||
module Werk | ||
class Config | ||
include YAML::Serializable | ||
|
||
# Configuration file version. | ||
@[YAML::Field(key: "version")] | ||
getter version = "1" | ||
|
||
# Description for the configuration file | ||
@[YAML::Field(key: "description")] | ||
getter description = "" | ||
|
||
@[YAML::Field(key: "dotenv")] | ||
getter dotenv = Set(String).new | ||
|
||
# List of global variables | ||
@[YAML::Field(key: "variables")] | ||
property variables = Hash(String, String).new | ||
|
||
@[YAML::Field(key: "max_jobs")] | ||
property max_jobs : UInt32 = 32_u32 | ||
|
||
# Jobs available in the current configuration | ||
@[YAML::Field(key: "jobs")] | ||
getter jobs = Hash(String, Config::Job).new | ||
|
||
# Load configuration from file | ||
def self.load_file(path : String) | ||
unless File.exists?(path) | ||
raise "Configuration file missing!" | ||
end | ||
|
||
content = File.read(path) | ||
self.load_string(content) | ||
end | ||
|
||
def self.load_string(content : String) | ||
if content.empty? | ||
raise "Empty configuration!" | ||
end | ||
|
||
self.from_yaml(content) | ||
rescue yaml_ex : YAML::ParseException | ||
raise "Parse error at line #{yaml_ex.line_number}, column #{yaml_ex.column_number}" | ||
end | ||
|
||
abstract class Job | ||
include YAML::Serializable | ||
|
||
# The description for the job | ||
@[YAML::Field(key: "description")] | ||
getter description = "" | ||
|
||
# List of dotenv files to be loaded | ||
@[YAML::Field(key: "dotenv")] | ||
getter dotenv = Set(String).new | ||
|
||
# A list of variables to be passed to the job | ||
@[YAML::Field(key: "variables")] | ||
property variables = Hash(String, String).new | ||
|
||
# List commands | ||
@[YAML::Field(key: "commands")] | ||
getter commands = Array(String).new | ||
|
||
# Dependencies list | ||
@[YAML::Field(key: "needs")] | ||
getter needs = Array(String).new | ||
|
||
# Signals if the job is allowed to fail or not. | ||
@[YAML::Field(key: "can_fail")] | ||
getter can_fail = false | ||
|
||
# Suppress job output to STDOUT | ||
@[YAML::Field(key: "silent")] | ||
getter silent = false | ||
|
||
@[YAML::Field(key: "executor")] | ||
getter executor : String | ||
|
||
@[YAML::Field(key: "interpreter")] | ||
getter interpreter = "/bin/sh" | ||
|
||
use_yaml_discriminator "executor", { | ||
local: Werk::Job::Local, | ||
docker: Werk::Job::Docker, | ||
} | ||
|
||
abstract def run(session_id : UUID, name : String, context : String) : {Int32, String} | ||
|
||
def get_script_content | ||
[ | ||
"#!#{@interpreter}", | ||
].concat(@commands).join("\n") | ||
end | ||
|
||
def get_script_file | ||
script = File.tempfile | ||
content = get_script_content | ||
File.write(script.path, content) | ||
File.chmod(script.path, 0o755) | ||
|
||
script | ||
end | ||
end | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.