Commit fbf1eb5f authored by Cheryl Li's avatar Cheryl Li Committed by Austin Regnery

CI/CD Template for deploying Shopify Themes with Theme Kit

Changelog: changed

Add rspec for ThemeKit template

Add allow live flag

Update test structure

Make the branch naming flexible

Simplify expectation for staging only

Fix staging job `only` keyword

Using variables with the `only` keyword is only supported under the
`variables` keyword. In order to check that the pipeline is on the
default branch, we have to check that $CI_DEFAULT_BRANCH equals
$CI_COMMIT_BRANCH

Add a spec that the production job runs on tags

Remove aggregate failures

Add ThemeKit to exception list for AutDevops

Fix template specs

Fix rubocop error

Use long form environment

Add metric tracking

Add deploy prefix

Fix formatting after rebase

Add options for metrics collection

Add an empty line

Move options up

Remove duplicate entry

Remove extra whitespace
parent 208fb01e
...@@ -169,6 +169,7 @@ options: ...@@ -169,6 +169,7 @@ options:
- p_ci_templates_qualys_iac_security - p_ci_templates_qualys_iac_security
- p_ci_templates_liquibase - p_ci_templates_liquibase
- p_ci_templates_matlab - p_ci_templates_matlab
- p_ci_templates_themekit
distribution: distribution:
- ce - ce
- ee - ee
......
---
key_path: redis_hll_counters.ci_templates.p_ci_templates_themekit_monthly
description: ''
product_section: ''
product_stage: ''
product_group: ''
product_category: ''
value_type: number
status: active
milestone: "14.10"
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/52279
time_frame: 28d
data_source: redis_hll
data_category: optional
instrumentation_class: RedisHLLMetric
options:
events:
- p_ci_templates_themekit
distribution:
- ce
- ee
tier:
- free
- premium
- ultimate
...@@ -169,6 +169,7 @@ options: ...@@ -169,6 +169,7 @@ options:
- p_ci_templates_qualys_iac_security - p_ci_templates_qualys_iac_security
- p_ci_templates_liquibase - p_ci_templates_liquibase
- p_ci_templates_matlab - p_ci_templates_matlab
- p_ci_templates_themekit
distribution: distribution:
- ce - ce
- ee - ee
......
---
key_path: redis_hll_counters.ci_templates.p_ci_templates_themekit_weekly
description: ''
product_section: ''
product_stage: ''
product_group: ''
product_category: ''
value_type: number
status: active
milestone: "14.10"
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/52279
time_frame: 7d
data_source: redis_hll
data_category: optional
instrumentation_class: RedisHLLMetric
options:
events:
- p_ci_templates_themekit
distribution:
- ce
- ee
tier:
- free
- premium
- ultimate
...@@ -19,7 +19,8 @@ RSpec.describe "CI YML Templates" do ...@@ -19,7 +19,8 @@ RSpec.describe "CI YML Templates" do
'Security/DAST.gitlab-ci.yml', # DAST stage is defined inside AutoDevops yml 'Security/DAST.gitlab-ci.yml', # DAST stage is defined inside AutoDevops yml
'Security/DAST-API.gitlab-ci.yml', # no auto-devops 'Security/DAST-API.gitlab-ci.yml', # no auto-devops
'Security/API-Fuzzing.gitlab-ci.yml', # no auto-devops 'Security/API-Fuzzing.gitlab-ci.yml', # no auto-devops
'Terraform.gitlab-ci.yml' 'Terraform.gitlab-ci.yml',
'ThemeKit.gitlab-ci.yml' # No AutoDevops support
] ]
where(:template_name) do where(:template_name) do
......
# Shopify Theme Kit is a CLI tool for Shopify Themes: https://shopify.github.io/themekit/
# See the full usage of this template described in: https://medium.com/@gogl.alex/how-to-deploy-shopify-themes-automatically-1ac17ee1229c
image: python:2
stages:
- deploy:staging
- deploy:production
staging:
image: python:2
stage: deploy:staging
script:
- curl -s https://shopify.github.io/themekit/scripts/install.py | python
- theme deploy --env=staging
only:
variables:
- $CI_DEFAULT_BRANCH == $CI_COMMIT_BRANCH
production:
image: python:2
stage: deploy:production
script:
- curl -s https://shopify.github.io/themekit/scripts/install.py | python
- theme deploy --env=production --allow-live
only:
- tags
...@@ -219,6 +219,10 @@ ...@@ -219,6 +219,10 @@
category: ci_templates category: ci_templates
redis_slot: ci_templates redis_slot: ci_templates
aggregation: weekly aggregation: weekly
- name: p_ci_templates_themekit
category: ci_templates
redis_slot: ci_templates
aggregation: weekly
- name: p_ci_templates_terraform - name: p_ci_templates_terraform
category: ci_templates category: ci_templates
redis_slot: ci_templates redis_slot: ci_templates
......
...@@ -23,7 +23,8 @@ RSpec.describe 'CI YML Templates' do ...@@ -23,7 +23,8 @@ RSpec.describe 'CI YML Templates' do
exceptions = [ exceptions = [
'Security/DAST.gitlab-ci.yml', # DAST stage is defined inside AutoDevops yml 'Security/DAST.gitlab-ci.yml', # DAST stage is defined inside AutoDevops yml
'Security/DAST-API.gitlab-ci.yml', # no auto-devops 'Security/DAST-API.gitlab-ci.yml', # no auto-devops
'Security/API-Fuzzing.gitlab-ci.yml' # no auto-devops 'Security/API-Fuzzing.gitlab-ci.yml', # no auto-devops
'ThemeKit.gitlab-ci.yml'
] ]
context 'when including available templates in a CI YAML configuration' do context 'when including available templates in a CI YAML configuration' do
......
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe 'ThemeKit.gitlab-ci.yml' do
before do
allow(Gitlab::Template::GitlabCiYmlTemplate).to receive(:excluded_patterns).and_return([])
end
subject(:template) { Gitlab::Template::GitlabCiYmlTemplate.find('ThemeKit') }
describe 'the created pipeline' do
let(:pipeline_ref) { project.default_branch_or_main }
let(:project) { create(:project, :custom_repo, files: { 'README.md' => '' }) }
let(:user) { project.first_owner }
let(:service) { Ci::CreatePipelineService.new(project, user, ref: pipeline_ref) }
let(:pipeline) { service.execute!(:push).payload }
let(:build_names) { pipeline.builds.pluck(:name) }
before do
stub_ci_pipeline_yaml_file(template.content)
end
context 'on the default branch' do
it 'only creates staging deploy', :aggregate_failures do
expect(pipeline.errors).to be_empty
expect(build_names).to include('staging')
expect(build_names).not_to include('production')
end
end
context 'on a tag' do
let(:pipeline_ref) { '1.0' }
before do
project.repository.add_tag(user, pipeline_ref, project.default_branch_or_main)
end
it 'only creates a production deploy', :aggregate_failures do
expect(pipeline.errors).to be_empty
expect(build_names).to include('production')
expect(build_names).not_to include('staging')
end
end
context 'outside of the default branch' do
let(:pipeline_ref) { 'patch-1' }
before do
project.repository.create_branch(pipeline_ref, project.default_branch_or_main)
end
it 'has no jobs' do
expect { pipeline }.to raise_error(
Ci::CreatePipelineService::CreateError, 'No stages / jobs for this pipeline.'
)
end
end
end
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