Sha256: 6339d63b3554195228f634cd720a5c59de1d62fe7286dd617a258d4fe926b9d5

Contents?: true

Size: 1.46 KB

Versions: 1

Compression:

Stored size: 1.46 KB

Contents

require 'json'

def rake_task(name, argument_hash)
  Rake::Task[name].execute Rake::TaskArguments.new(argument_hash.keys, argument_hash.values)
end

def git_tag
  hosting_key = @deploy_status['result']['hosting']
  "firebase-#{hosting_key}"
end

def promote(from: :development, to: :staging)
  sh 'firebase', 'promote', from.to_s, to.to_s
  rake_task :tag, environment: to, ref: git_tag(from)
end

namespace :middleman do
  desc 'Build site into /build directory'
  task :build do
    sh *%w(middleman build --clean)
  end
end

namespace :firebase do
  desc 'Build and deploy to Firebase'
  task deploy: :'deploy:all'

  task :tag, [:environment, :ref] do |_, args|
    args.with_defaults ref: 'head'
    sh 'git', 'tag', git_tag, args[:ref]
  end

  namespace :deploy do
    task all: ['middleman:build', :push] do
      rake_task :tag, environment: 'development'
    end

    task :push do
      git_commit = `git rev-parse HEAD`.strip
      deploy_output = `firebase deploy --only hosting -j -m 'Git commit #{git_commit}'`
      deploy_output.sub! %r(\A[^{]*), ''
      @deploy_status = JSON.parse deploy_output
      warn "Deploy status:"
      warn @deploy_status.inspect
    end
  end

  namespace :promote do
    desc 'Promote current development version to staging'
    task :staging do
      promote from: :development, to: :staging
    end

    desc 'Promote current staging version to production'
    task :production do
      promote from: :staging, to: :production
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
middleman-firebase-0.1.1 lib/middleman/firebase/tasks/deploy.rake