Skip to content

Instantly share code, notes, and snippets.

@apotterri
Last active July 23, 2020 11:42
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save apotterri/03eb556ba6dce6c1238430cb757a13c0 to your computer and use it in GitHub Desktop.
Ruby program to upload an AppLand Mapset from CI (Travis).
#!/usr/bin/env ruby
# frozen_string_literal: true
def env_var(key)
var = ENV[key]
if var.nil? || var.empty?
nil
else
var
end
end
def env_var?(key)
!env_var(key).nil?
end
def debug?
env_var?('DEBUG')
end
def dry_run?
env_var?('DRY_RUN')
end
def ci_branch
# In pull requests, TRAVIS_BRANCH is "master". Huh?
env_var('TRAVIS_PULL_REQUEST_BRANCH') || env_var('TRAVIS_BRANCH')
end
def ci?
!ci_branch.nil?
end
def git_last_tag
tag = `git describe --tags --abbrev=0`.strip
puts "tag: #{tag}" if debug?
tag.empty? ? nil : tag
end
def git_commits_since_tag(tag)
`git log #{git_last_tag}..HEAD --oneline`.split("\n").length.tap do |length|
puts "commits since #{tag}: #{length}" if debug?
end
end
args = %w(appland upload)
if ci_branch
args << [ '-b', ci_branch ]
end
if ci?
args << %w(-e ci)
args << '--no-open'
end
if ci_branch == 'master'
tag = git_last_tag
if tag && git_commits_since_tag(tag) == 0
args << '-v'
args << tag
end
end
args += ARGV unless ARGV.length == 0
args << 'tmp/appmap/rspec'
puts args.join(' ') if debug?
Kernel.exec(args.join(' ')) unless dry_run?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment