blob: 42ba024da703503d264b292f5797789e06b62bf3 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
#!/usr/bin/env ruby
require 'gitlab'
#
# Give the remote branch a different name than the current one
# in order to avoid conflicts
#
@docs_branch = "#{ENV["CI_COMMIT_REF_SLUG"]}-built-from-ce-ee"
GITLAB_DOCS_REPO = 'gitlab-com/gitlab-docs'
#
# Configure credentials to be used with gitlab gem
#
Gitlab.configure do |config|
config.endpoint = 'https://gitlab.com/api/v4'
config.private_token = ENV["DOCS_API_TOKEN"] # GitLab Docs bot access token which has only Developer access to gitlab-docs
end
#
# Create a remote branch in gitlab-docs
#
def create_remote_branch
Gitlab.create_branch(GITLAB_DOCS_REPO, @docs_branch, 'master')
puts "Remote branch '#{@docs_branch}' created"
rescue Gitlab::Error::BadRequest => e
puts "Remote branch '#{@docs_branch}' already exists"
end
#
# Dummy way to find out in which repo we are, CE or EE
#
def is_ee?
File.exists?('CHANGELOG-EE.md')
end
#
# Trigger a pipeline in gitlab-docs
#
def trigger_pipeline
# Overriding vars in https://gitlab.com/gitlab-com/gitlab-docs/blob/master/.gitlab-ci.yml
param_name = is_ee? ? 'BRANCH_EE' : 'BRANCH_CE'
# The review app URL
app_url = "http://#{@docs_branch}.#{ENV["DOCS_REVIEW_APPS_DOMAIN"]}/#{is_ee? ? 'ee' : 'ce'}"
# Create the pipeline
puts "=> Triggering a pipeline..."
pipeline = Gitlab.run_trigger(GITLAB_DOCS_REPO, ENV["DOCS_TRIGGER_TOKEN"], @docs_branch, { param_name => ENV["CI_COMMIT_REF_NAME"] })
puts "=> Pipeline created:"
puts ""
puts "https://gitlab.com/gitlab-com/gitlab-docs/pipelines/#{pipeline.id}"
puts ""
puts "=> Preview your changes live at:"
puts ""
puts app_url
puts ""
end
create_remote_branch
trigger_pipeline
|