Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add release task #602

Merged
merged 2 commits into from Oct 5, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 23 additions & 0 deletions spec/tasks/build/release_spec.cr
@@ -0,0 +1,23 @@
require "../../../spec_helper"

include CleanupHelper

describe Build::Release do
it "creates an executable if a `src/server.cr` file exists" do
with_cleanup do
Dir.mkdir_p("./src")
File.write "./src/server.cr", "puts 1"
Build::Release.new.call
File.exists?("./server").should be_true
end
end

it "does not create executable if the build fails" do
with_cleanup do
Dir.mkdir_p("./src")
File.write "./src/server.cr", %({{ raise "this build will fail" }})
Build::Release.new.call
File.exists?("./server").should be_false
end
end
end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice specs!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks 😄

22 changes: 22 additions & 0 deletions tasks/build/release.cr
@@ -0,0 +1,22 @@
require "lucky_cli"
require "colorize"

class Build::Release < LuckyCli::Task
include LuckyCli::TextHelpers

banner "Compile app for production"

def call
command = "crystal build --release src/server.cr"

log "Building binary with '#{command}"
process = Process.run(command, shell: true, output: STDOUT, error: STDERR)
if process.success?
log "Build succeeded - binary saved at './server'"
end
end

def log(message)
puts " #{green_arrow} #{message}"
end
end