verify_templates.rb 737 Bytes
Newer Older
1 2
#!/usr/bin/env ruby

3 4 5
require 'net/http'
require 'json'

6
LINTER_URI = URI.parse 'https://gitlab.com/api/v4/ci/lint'
7

8 9
def verify(file)
  response = Net::HTTP.post_form(LINTER_URI, content: File.read(file))
10 11 12 13 14 15 16 17 18 19

  file = file.match(/((\w|\+|#)+)\.gitlab-ci/)[1]

  if JSON.parse(response.body)['status'] == 'valid'
    puts "\e[32mvalid\e[0m: #{file}" # Color 'valid' green
  else
    puts "invalid: #{file}"
    exit(1)
  end
end
20

21 22 23 24 25
if ARGV.empty?
  Dir.glob("#{File.dirname(__FILE__)}/**/*.yml").each { |file| verify(file) }

  # Given we test all the templates, the coverage is 100%, always. To showcase
  # how this is done, we print it here.
26
  # Regexp used to parse this: Coverage:\s(\d+)
27 28 29 30
  puts 'Coverage: 100%'
else
  verify(ARGV[0])
end