Sha256: a727f74adf7d548da8c8bd8d1af2d724a323ea538532ef8dac6d279e7a5ef790

Contents?: true

Size: 1.28 KB

Versions: 2

Compression:

Stored size: 1.28 KB

Contents

module PkgForge
  ##
  # Add upload methods to Forge
  class Forge
    attr_accessor :endpoint

    Contract None => nil
    def push!
      upload_artifacts!
    end

    private

    Contract HashOf[Symbol => String] => nil
    def add_artifact(params)
      state[:artifacts] ||= []
      state[:artifacts] << params
      nil
    end

    Contract None => nil
    def expose_artifacts!
      FileUtils.mkdir_p 'pkg'
      return unless state[:artifacts]
      state[:artifacts].each do |artifact|
        dest = File.join('pkg', artifact[:long_name] || artifact[:name])
        FileUtils.cp artifact[:source], dest
        FileUtils.chmod 0o0644, dest
      end
      nil
    end

    Contract None => nil
    def upload_artifacts!
      return unless state[:artifacts]
      state[:artifacts].each do |artifact|
        args = ['targit', '--authfile', '.creds_github', '--create', '--force']
        args += ['--name', artifact[:name]]
        args += ['--endpoint', endpoint] if endpoint
        args += ["#{org}/#{name}", version, artifact[:source]]
        run args
      end
      nil
    end
  end

  module DSL
    ##
    # Add upload methods to Forge DSL
    class Forge
      Contract String => nil
      def endpoint(value)
        @forge.endpoint = value
        nil
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
pkgforge-0.29.1 lib/pkgforge/components/upload.rb
pkgforge-0.29.0 lib/pkgforge/components/upload.rb