Sha256: cd46e383dbbb5b4b52d20256ffd85bd160cc64ab16d03d370ec5e957cd3e03d3

Contents?: true

Size: 1.64 KB

Versions: 12

Compression:

Stored size: 1.64 KB

Contents

# frozen_string_literal: true

module Dpl
  module Providers
    class Snap < Provider
      register :snap

      status :stable

      description sq(<<-STR)
        tbd
      STR

      env :snap

      opt '--token TOKEN', 'Snap API token', required: true, secret: true
      opt '--snap STR', 'Path to the snap to be pushed (can be a glob)', default: '**/*.snap'
      opt '--channel CHAN', 'Channel into which the snap will be released', default: 'edge'

      apt 'snapd', 'snap'

      cmds apt_get_update: 'sudo apt-get update -qq',
           update_snapd: 'sudo apt-get install snapd',
           install: 'sudo snap install snapcraft --classic',
           login: 'echo "%{token}" | snapcraft login --with -',
           deploy: 'snapcraft push %{snap_path} --release=%{channel}'

      msgs login: 'Attemping to login ...',
           no_snaps: 'No snap found matching %{snap}',
           multiple_snaps: 'Multiple snaps found matching %{snap}: %{snap_paths}',
           deploy: 'Pushing snap %{snap_path}'

      def install
        return if which 'snapcraft'

        shell :apt_get_update
        shell :update_snapd
        shell :install
        ENV['PATH'] += ':/snap/bin'
      end

      def login
        shell :login, assert: 'Failed to authenticate: %{err}', success: '%{out}', capture: true
      end

      def validate
        error :no_snaps if snaps.empty?
        error :multiple_snaps if snaps.size > 1
      end

      def deploy
        shell :deploy
      end

      def snap_path
        snaps.first
      end

      def snap_paths
        snaps.join(', ')
      end

      def snaps
        @snaps ||= Dir[snap].sort
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 2 rubygems

Version Path
dpl-2.0.5.3 lib/dpl/providers/snap.rb
dpl-2.0.5.3.beta.1 lib/dpl/providers/snap.rb
dpl-2.0.5.2 lib/dpl/providers/snap.rb
dpl-2.0.5.2.beta.1 lib/dpl/providers/snap.rb
dpl-2.0.5.1 lib/dpl/providers/snap.rb
dpl-2.0.5.beta.2.1 lib/dpl/providers/snap.rb
dpl-2.0.5.beta.2 lib/dpl/providers/snap.rb
dpl-2.0.5 lib/dpl/providers/snap.rb
dpl-2.0.5.beta.1 lib/dpl/providers/snap.rb
dpl-2.0.5.beta lib/dpl/providers/snap.rb
travis_dpl_test-2.0.3.beta.4.ror.1 lib/dpl/providers/snap.rb
travis_dpl_test-2.0.3.beta.4.ror lib/dpl/providers/snap.rb