Skip to content

Commit

Permalink
Add a task for deleting accidental deployments. #3.
Browse files Browse the repository at this point in the history
  • Loading branch information
rsutphin committed Oct 10, 2012
1 parent bffd971 commit 1068078
Showing 1 changed file with 50 additions and 7 deletions.
57 changes: 50 additions & 7 deletions tasks/release.rake
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
desc "Do the full release process"
task :release => [:clean, :package, :deploy]

GITHUB_REPO_USER = 'NUBIC'
GITHUB_REPO_NAME = 'suite_authorization_source.rb'

task :github_credentials do |t|
require 'highline'

Expand All @@ -18,6 +21,14 @@ task :github_credentials do |t|
end
end

def github_downloads
creds = task(:github_credentials)
@github_downloads ||= Github::Repos::Downloads.new(
:login => creds.login,
:password => creds.password
)
end

desc "Uploads the current artifacts to GitHub"
task :deploy => :github_credentials do
require 'github_api'
Expand All @@ -33,19 +44,13 @@ task :deploy => :github_credentials do
end
end

creds = task(:github_credentials)
github_downloads = Github::Repos::Downloads.new(
:login => creds.login,
:password => creds.password
)

projs.each do |pub_proj|
pkg = pub_proj.packages.first
pkg_file = pkg.to_s
target_file_name = "#{pub_proj.version}/#{File.basename pkg_file}"

info "Telling GitHub about #{target_file_name}"
created = github_downloads.create('NUBIC', 'suite_authorization_source.rb',
created = github_downloads.create(GITHUB_REPO_USER, GITHUB_REPO_NAME,
'name' => target_file_name,
'size' => File.size(pkg_file),
'description' => "#{pub_proj.name} #{pub_proj.version}",
Expand All @@ -56,3 +61,41 @@ task :deploy => :github_credentials do
github_downloads.upload(created, pkg_file)
end
end

namespace :deploy do
task :delete, :version, :needs => :github_credentials do |t, args|
require 'github_api'

unless args[:version] =~ /\d+\.\d+\.\d+/
fail "For safety, only delete one version at a time (not #{args[:version]})."
end

trace 'Looking up downloads for NUBIC/suite_authorization_source.rb'
matches = github_downloads.list(GITHUB_REPO_USER, GITHUB_REPO_NAME).select do |dl|
dl['description'] =~ /#{Regexp.escape args[:version]}/
end

if matches.empty?
info "No downloads match #{args[:version]}"
else
info "Press enter to delete the following files UNRECOVERABLY:"
matches.each do |match|
info " - #{match['description']}"
info " #{match['html_url']}"
end
info "or press ^C to abort."
begin
$stdin.gets
rescue Interrupt
info "\nNothing deleted."
exit(0)
end

info "Deleting matches."
matches.each do |match|
trace "Deleting #{match.inspect}"
github_downloads.delete(GITHUB_REPO_USER, GITHUB_REPO_NAME, match['id'])
end
end
end
end

0 comments on commit 1068078

Please sign in to comment.