Commit c5536a37 authored by Rémy Coutable's avatar Rémy Coutable

Merge branch 'docs/trigger-preview' into 'master'

Add script and job to trigger a docs build

See merge request !13954
parents 4ae8e20c ecdab9f9
......@@ -40,6 +40,7 @@ stages:
- test
- post-test
- pages
- post-cleanup
# Predefined scopes
.dedicated-runner: &dedicated-runner
......@@ -153,8 +154,7 @@ stages:
- master@gitlab/gitlabhq
- master@gitlab/gitlab-ee
# Trigger a package build on omnibus-gitlab repository
# Trigger a package build in omnibus-gitlab repository
build-package:
image: ruby:2.3-alpine
before_script: []
......@@ -166,11 +166,47 @@ build-package:
cache: {}
when: manual
script:
- scripts/trigger-build
- scripts/trigger-build-omnibus
only:
- //@gitlab-org/gitlab-ce
- //@gitlab-org/gitlab-ee
# Review docs base
.review-docs: &review-docs
image: ruby:2.4-alpine
before_script: []
services: []
variables:
SETUP_DB: "false"
USE_BUNDLE_INSTALL: "false"
cache: {}
when: manual
only:
- branches
# Trigger a docs build in gitlab-docs
# Useful to preview the docs changes live
review-docs-deploy:
<<: *review-docs
stage: build
environment:
name: review-docs/$CI_COMMIT_REF_NAME
on_stop: review-docs-cleanup
script:
- gem install gitlab --no-doc
- scripts/trigger-build-docs deploy
# Cleanup remote environment of gitlab-docs
review-docs-cleanup:
<<: *review-docs
stage: post-cleanup
environment:
name: review-docs/$CI_COMMIT_REF_NAME
action: stop
script:
- gem install gitlab --no-doc
- scripts/trigger-build-docs cleanup
# Retrieve knapsack and rspec_flaky reports
retrieve-tests-metadata:
<<: *tests-metadata-state
......
......@@ -103,3 +103,24 @@ If that job fails, read the instructions in the job log for what to do next.
Contributors do not need to submit their changes to EE, GitLab Inc. employees
on the other hand need to make sure that their changes apply cleanly to both
CE and EE.
## Previewing the changes live
If you want to preview your changes live, you can use the manual `build-docs`
job in your merge request.
![Manual trigger a docs build](img/manual_build_docs.png)
This job will:
1. Create a new branch in the [gitlab-docs](https://gitlab.com/gitlab-com/gitlab-docs)
project named after the scheme: `<CE/EE-branch-slug>-built-from-ce-ee`
1. Trigger a pipeline and build the docs site with your changes
Look for the docs URL at the output of the `build-docs` job.
>**Note:**
Make sure that you always delete the branch of the merge request you were
working on. If you don't, the remote docs branch won't be removed either,
and the server where the Review Apps are hosted will eventually be out of
disk space.
#!/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
#
# Dummy way to find out in which repo we are, CE or EE
#
def is_ee?
File.exists?('CHANGELOG-EE.md')
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
#
# Remove a remote branch in gitlab-docs
#
def remove_remote_branch
Gitlab.delete_branch(GITLAB_DOCS_REPO, @docs_branch)
puts "Remote branch '#{@docs_branch}' deleted"
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
#
# When the first argument is deploy then create the branch and trigger pipeline
# When it is 'stop', it deleted the remote branch. That way, we ensure there
# are no stale remote branches and the Review server doesn't fill.
#
case ARGV[0]
when 'deploy'
create_remote_branch
trigger_pipeline
when 'cleanup'
remove_remote_branch
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment