Skip to content

Instantly share code, notes, and snippets.

Revisions

  1. jensendarren revised this gist Oct 6, 2012. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion tddium_post_build.rake
    Original file line number Diff line number Diff line change
    @@ -48,11 +48,12 @@ namespace :tddium do

    new_relic_api_key = ENV["NEW_RELIC_API_KEY"]
    application_id = ENV["NEW_RELIC_APPLICATION_ID"]
    user_name = ENV['TDDIUM_USER_NAME']

    if new_relic_api_key && application_id
    NewRelicApi.api_key = new_relic_api_key

    NewRelicApi::Deployment.create :application_id => application_id, :description => "Should be the commit sha", :user => "Should be the user who push"
    NewRelicApi::Deployment.create :application_id => application_id, :user => user_name
    end

    end
  2. jensendarren revised this gist Oct 5, 2012. 1 changed file with 11 additions and 1 deletion.
    12 changes: 11 additions & 1 deletion tddium_post_build.rake
    Original file line number Diff line number Diff line change
    @@ -45,5 +45,15 @@ namespace :tddium do

    puts "Restarting Heroku..."
    cmd "bundle exec heroku restart --app #{app_name}" or abort "aborted heroku restart"

    new_relic_api_key = ENV["NEW_RELIC_API_KEY"]
    application_id = ENV["NEW_RELIC_APPLICATION_ID"]

    if new_relic_api_key && application_id
    NewRelicApi.api_key = new_relic_api_key

    NewRelicApi::Deployment.create :application_id => application_id, :description => "Should be the commit sha", :user => "Should be the user who push"
    end

    end
    end
    end
  3. @semipermeable semipermeable revised this gist Aug 8, 2012. 1 changed file with 13 additions and 5 deletions.
    18 changes: 13 additions & 5 deletions tddium_post_build.rake
    Original file line number Diff line number Diff line change
    @@ -12,9 +12,6 @@ namespace :tddium do
    return unless ENV["TDDIUM_MODE"] == "ci"
    return unless ENV["TDDIUM_BUILD_STATUS"] == "passed"

    puts "Resetting workspace to HEAD"
    cmd "git reset --hard HEAD" or abort "could not reset git workspace"

    dir = File.expand_path("~/.heroku/")
    heroku_email = ENV["HEROKU_EMAIL"]
    heroku_api_key = ENV["HEROKU_API_KEY"]
    @@ -32,10 +29,21 @@ namespace :tddium do
    f.write("\n")
    end

    File.open(File.expand_path("~/.netrc"), "a+") do |f|
    ['api', 'code'].each do |host|
    f.puts "machine #{host}.heroku.com"
    f.puts " login #{heroku_email}"
    f.puts " password #{heroku_api_key}"
    end
    end

    puts "Pushing to Heroku: #{push_target}..."
    cmd "git push #{push_target} #{current_branch}:master --force" or abort "could not push to #{push_target}"
    cmd "git push #{push_target} HEAD:master --force" or abort "could not push to #{push_target}"

    puts "Running Heroku Migrations..."
    cmd "heroku run rake db:migrate --app #{app_name}" or abort "aborted to run migrations"
    cmd "heroku run rake db:migrate --app #{app_name}" or abort "aborted migrations"

    puts "Restarting Heroku..."
    cmd "bundle exec heroku restart --app #{app_name}" or abort "aborted heroku restart"
    end
    end
  4. @semipermeable semipermeable revised this gist May 9, 2012. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion tddium_post_build.rake
    Original file line number Diff line number Diff line change
    @@ -18,7 +18,7 @@ namespace :tddium do
    dir = File.expand_path("~/.heroku/")
    heroku_email = ENV["HEROKU_EMAIL"]
    heroku_api_key = ENV["HEROKU_API_KEY"]
    current_branch = `git symbolic-ref HEAD 2>/dev/null | cut -d"/" -f 3`.strip
    current_branch = `git symbolic-ref HEAD 2>/dev/null | cut -d"/" -f 3-`.strip
    app_name = ENV["HEROKU_APP_NAME"]
    push_target = "[email protected]:#{app_name}.git"

  5. @semipermeable semipermeable revised this gist May 8, 2012. 1 changed file with 15 additions and 7 deletions.
    22 changes: 15 additions & 7 deletions tddium_post_build.rake
    Original file line number Diff line number Diff line change
    @@ -5,7 +5,15 @@ end
    namespace :tddium do
    desc "post_build_hook"
    task :post_build_hook do
    cmd "git reset --hard HEAD" or fail "could not reset git workspace"
    # This build hook should only run after CI builds.
    #
    # There are other cases where we'd want to run something after every build,
    # or only after manual builds.
    return unless ENV["TDDIUM_MODE"] == "ci"
    return unless ENV["TDDIUM_BUILD_STATUS"] == "passed"

    puts "Resetting workspace to HEAD"
    cmd "git reset --hard HEAD" or abort "could not reset git workspace"

    dir = File.expand_path("~/.heroku/")
    heroku_email = ENV["HEROKU_EMAIL"]
    @@ -14,9 +22,9 @@ namespace :tddium do
    app_name = ENV["HEROKU_APP_NAME"]
    push_target = "[email protected]:#{app_name}.git"

    fail "invalid current branch" unless current_branch
    abort "invalid current branch" unless current_branch

    FileUtils.mkdir_p(dir) or fail "Could not create #{dir}"
    FileUtils.mkdir_p(dir) or abort "Could not create #{dir}"

    puts "Writing Heroku Credentials"
    File.open(File.join(dir, "credentials"), "w") do |f|
    @@ -25,9 +33,9 @@ namespace :tddium do
    end

    puts "Pushing to Heroku: #{push_target}..."
    cmd "git push #{push_target} #{current_branch}:master --force" or fail "could not push to #{push_target}"
    cmd "git push #{push_target} #{current_branch}:master --force" or abort "could not push to #{push_target}"

    puts "Running Heroku Migrations..."
    cmd "heroku run rake db:migrate --app #{app_name}" or fail "failed to run migrations"
    cmd "heroku run rake db:migrate --app #{app_name}" or abort "aborted to run migrations"
    end
    end
    end
  6. @semipermeable semipermeable created this gist May 8, 2012.
    33 changes: 33 additions & 0 deletions tddium_post_build.rake
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,33 @@
    def cmd(c)
    system c
    end

    namespace :tddium do
    desc "post_build_hook"
    task :post_build_hook do
    cmd "git reset --hard HEAD" or fail "could not reset git workspace"

    dir = File.expand_path("~/.heroku/")
    heroku_email = ENV["HEROKU_EMAIL"]
    heroku_api_key = ENV["HEROKU_API_KEY"]
    current_branch = `git symbolic-ref HEAD 2>/dev/null | cut -d"/" -f 3`.strip
    app_name = ENV["HEROKU_APP_NAME"]
    push_target = "[email protected]:#{app_name}.git"

    fail "invalid current branch" unless current_branch

    FileUtils.mkdir_p(dir) or fail "Could not create #{dir}"

    puts "Writing Heroku Credentials"
    File.open(File.join(dir, "credentials"), "w") do |f|
    f.write([heroku_email, heroku_api_key].join("\n"))
    f.write("\n")
    end

    puts "Pushing to Heroku: #{push_target}..."
    cmd "git push #{push_target} #{current_branch}:master --force" or fail "could not push to #{push_target}"

    puts "Running Heroku Migrations..."
    cmd "heroku run rake db:migrate --app #{app_name}" or fail "failed to run migrations"
    end
    end