Skip to content
Myr

Add script for updating release assets

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Junegunn Choi · committed by Junegunn Choi · parent 4c3ae84 · Browse files · 1 file+41 added−0 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+41 added−0 removed

  • other:+41 added−0 removed

1 file+41 added−0 removed

added:src/update_assets.rb+41 added
1#!/usr/bin/env ruby23# http://www.rubydoc.info/github/rest-client/rest-client/RestClient4require 'rest_client'56if ARGV.length < 37 puts "usage: #$0 <token> <version> <files...>"8end910token, version, *files = ARGV11base = "https://api.github.com/repos/junegunn/fzf-bin/releases"1213# List releases14rels = JSON.parse(RestClient.get(base, :authorization => "token #{token}"))15rel = rels.find { |r| r['tag_name'] == version }16unless rel17 puts "#{version} not found"18 exit 119end2021# List assets22assets = Hash[rel['assets'].map { |a| a.values_at *%w[name id] }]2324files.select { |f| File.exists? f }.each do |file|25 name = File.basename file2627 if asset_id = assets[name]28 puts "#{name} found. Deleting asset id #{asset_id}."29 RestClient.delete "#{base}/assets/#{asset_id}",30 :authorization => "token #{token}"31 else32 puts "#{name} not found"33 end3435 puts "Uploading #{name}"36 RestClient.post(37 "#{base.sub 'api', 'uploads'}/#{rel['id']}/assets?name=#{name}",38 File.read(file),39 :authorization => "token #{token}",40 :content_type => "application/octet-stream")41end