Sha256: 72911eb3d0ad4e2de78a1fdec3364019cd9ad160170c0af7ce11ef7fae1c9c5e

Contents?: true

Size: 1.44 KB

Versions: 23

Compression:

Stored size: 1.44 KB

Contents

require 'thor'
require 'thegarage/gitx'
require 'thegarage/gitx/cli/base_command'

module Thegarage
  module Gitx
    module Cli
      class BuildtagCommand < BaseCommand
        TAGGABLE_BRANCHES = %w( master staging )

        desc 'buildtag', 'create a tag for the current build and push it back to origin (supports Travis CI and Codeship)'
        def buildtag
          fail "Unknown branch. Environment variables TRAVIS_BRANCH or CI_BRANCH are required" unless branch_name
          fail "Branch must be one of the supported taggable branches: #{TAGGABLE_BRANCHES}" unless TAGGABLE_BRANCHES.include?(branch_name)

          label = "buildtag generated by build #{build_number}"
          create_build_tag(branch_name, label)
        end

        private

        # pull the current branch name from environment variables
        # supports Travis CI or Codeship variables
        # see https://www.codeship.io/documentation/continuous-integration/set-environment-variables/
        def branch_name
          ENV['TRAVIS_BRANCH'] || ENV['CI_BRANCH']
        end

        def build_number
          ENV['TRAVIS_BUILD_NUMBER'] || ENV['CI_BUILD_NUMBER']
        end

        def create_build_tag(branch, label)
          timestamp = Time.now.utc.strftime '%Y-%m-%d-%H-%M-%S'
          git_tag = "build-#{branch}-#{timestamp}"
          run_cmd "git tag #{git_tag} -a -m '#{label}'"
          run_cmd "git push origin #{git_tag}"
        end
      end
    end
  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
thegarage-gitx-2.11.0 lib/thegarage/gitx/cli/buildtag_command.rb
thegarage-gitx-2.10.2 lib/thegarage/gitx/cli/buildtag_command.rb
thegarage-gitx-2.10.1 lib/thegarage/gitx/cli/buildtag_command.rb
thegarage-gitx-2.10.0 lib/thegarage/gitx/cli/buildtag_command.rb
thegarage-gitx-2.9.0 lib/thegarage/gitx/cli/buildtag_command.rb
thegarage-gitx-2.8.1 lib/thegarage/gitx/cli/buildtag_command.rb
thegarage-gitx-2.8.0 lib/thegarage/gitx/cli/buildtag_command.rb
thegarage-gitx-2.7.2 lib/thegarage/gitx/cli/buildtag_command.rb
thegarage-gitx-2.7.1 lib/thegarage/gitx/cli/buildtag_command.rb
thegarage-gitx-2.7.0 lib/thegarage/gitx/cli/buildtag_command.rb
thegarage-gitx-2.6.0 lib/thegarage/gitx/cli/buildtag_command.rb
thegarage-gitx-2.5.1 lib/thegarage/gitx/cli/buildtag_command.rb
thegarage-gitx-2.5.0 lib/thegarage/gitx/cli/buildtag_command.rb
thegarage-gitx-2.5.0.beta5 lib/thegarage/gitx/cli/buildtag_command.rb
thegarage-gitx-2.5.0.beta4 lib/thegarage/gitx/cli/buildtag_command.rb
thegarage-gitx-2.5.0.beta3 lib/thegarage/gitx/cli/buildtag_command.rb
thegarage-gitx-2.5.0.beta2 lib/thegarage/gitx/cli/buildtag_command.rb
thegarage-gitx-2.5.0.beta1 lib/thegarage/gitx/cli/buildtag_command.rb
thegarage-gitx-2.4.2 lib/thegarage/gitx/cli/buildtag_command.rb
thegarage-gitx-2.5.0.alpha1 lib/thegarage/gitx/cli/buildtag_command.rb