Class: Ace::Demo::Molecules::GhAssetUploader
- Inherits:
-
Object
- Object
- Ace::Demo::Molecules::GhAssetUploader
- Defined in:
- lib/ace/demo/molecules/gh_asset_uploader.rb
Constant Summary collapse
- RELEASE_TAG =
"demo-assets"- RELEASE_TITLE =
"Demo Assets"- RELEASE_NOTES =
"Auto-generated release for demo GIF hosting"
Instance Method Summary collapse
-
#initialize(now: -> { Time.now.to_i }, gh_bin: "gh") ⇒ GhAssetUploader
constructor
A new instance of GhAssetUploader.
- #upload(file_path:, dry_run: false) ⇒ Object
Constructor Details
#initialize(now: -> { Time.now.to_i }, gh_bin: "gh") ⇒ GhAssetUploader
Returns a new instance of GhAssetUploader.
15 16 17 18 |
# File 'lib/ace/demo/molecules/gh_asset_uploader.rb', line 15 def initialize(now: -> { Time.now.to_i }, gh_bin: "gh") @now = now @gh_bin = gh_bin end |
Instance Method Details
#upload(file_path:, dry_run: false) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/ace/demo/molecules/gh_asset_uploader.rb', line 20 def upload(file_path:, dry_run: false) asset_name = stamped_asset_name(file_path) if dry_run repo = ENV.fetch("GITHUB_REPOSITORY", "OWNER/REPO") asset_url = "https://github.com/#{repo}/releases/download/#{RELEASE_TAG}/#{asset_name}" return {asset_name: asset_name, asset_url: asset_url, dry_run: true} end raise ArgumentError, "Recording file not found: #{file_path}" unless File.exist?(file_path) repo = repo_name_with_owner asset_url = "https://github.com/#{repo}/releases/download/#{RELEASE_TAG}/#{asset_name}" ensure_release_exists! Dir.mktmpdir("ace_demo_attach") do |tmpdir| upload_path = File.join(tmpdir, asset_name) FileUtils.cp(file_path, upload_path) run_gh!("release", "upload", RELEASE_TAG, upload_path, "--clobber") end {asset_name: asset_name, asset_url: asset_url, dry_run: false} end |