shipit-engine 0.37.0 → 0.38.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/app/controllers/shipit/api/stacks_controller.rb +25 -1
- data/app/helpers/shipit/api_clients_helper.rb +12 -0
- data/app/jobs/shipit/continuous_delivery_job.rb +4 -1
- data/app/models/shipit/stack.rb +8 -0
- data/app/models/shipit/task_execution_strategy/default.rb +1 -1
- data/app/views/shipit/api_clients/show.html.erb +1 -1
- data/db/migrate/20230703181143_change_commit_deployment_statuses_github_id_to_big_int.rb +5 -0
- data/lib/shipit/octokit_iterator.rb +2 -0
- data/lib/shipit/stack_commands.rb +10 -0
- data/lib/shipit/task_commands.rb +1 -1
- data/lib/shipit/version.rb +1 -1
- data/test/controllers/api/base_controller_test.rb +1 -1
- data/test/controllers/api/ccmenu_controller_test.rb +1 -1
- data/test/controllers/api/commits_controller_test.rb +1 -1
- data/test/controllers/api/deploys_controller_test.rb +1 -1
- data/test/controllers/api/hooks_controller_test.rb +1 -1
- data/test/controllers/api/locks_controller_test.rb +1 -1
- data/test/controllers/api/merge_requests_controller_test.rb +1 -1
- data/test/controllers/api/outputs_controller_test.rb +1 -1
- data/test/controllers/api/release_statuses_controller_test.rb +1 -1
- data/test/controllers/api/rollback_controller_test.rb +1 -1
- data/test/controllers/api/stacks_controller_test.rb +52 -1
- data/test/controllers/api/tasks_controller_test.rb +1 -1
- data/test/dummy/db/schema.rb +2 -2
- data/test/helpers/api_helper.rb +13 -0
- data/test/models/shipit/stacks_test.rb +30 -0
- data/test/unit/deploy_commands_test.rb +94 -6
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f671228679f81a64a70284699951ea5cc8fce83e82a56263cf6a4f52055f5976
|
4
|
+
data.tar.gz: 0d795762874714a9d592edb0dd3fd1b599f1819edc06d1085252a9e26ef0073b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6c55d8a3f3ab16affd874abd8c15e51c19a29e81ddb3131a4695d9ca2ba409e312e40892ddbd66ec6bca32ce403254f02de632dbab06a97306c6a0da5e684c2e
|
7
|
+
data.tar.gz: fd7b4ad69bd0b03a486a38a4ce2dcf0802581aee836e44f1390f362aeace5b1fbb30f24bd3a5579da89e0bfca8f588ed16d121e9be7a4afd7f7f1efda208a97f
|
@@ -46,9 +46,13 @@ module Shipit
|
|
46
46
|
accepts :ignore_ci, Boolean
|
47
47
|
accepts :merge_queue_enabled, Boolean
|
48
48
|
accepts :continuous_deployment, Boolean
|
49
|
+
accepts :archived, Boolean
|
49
50
|
end
|
50
51
|
def update
|
51
|
-
stack.update(
|
52
|
+
stack.update(update_params)
|
53
|
+
|
54
|
+
update_archived
|
55
|
+
|
52
56
|
render_resource(stack)
|
53
57
|
end
|
54
58
|
|
@@ -78,6 +82,26 @@ module Shipit
|
|
78
82
|
@stack ||= stacks.from_param!(params[:id])
|
79
83
|
end
|
80
84
|
|
85
|
+
def update_archived
|
86
|
+
if key?(:archived)
|
87
|
+
if params[:archived]
|
88
|
+
stack.archive!(nil)
|
89
|
+
elsif stack.archived?
|
90
|
+
stack.unarchive!
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
def key?(key)
|
96
|
+
params.to_h.key?(key)
|
97
|
+
end
|
98
|
+
|
99
|
+
def update_params
|
100
|
+
params.select do |key, _|
|
101
|
+
%i(environment branch deploy_url ignore_ci merge_queue_enabled continuous_deployment).include?(key)
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
81
105
|
def repository
|
82
106
|
@repository ||= Repository.find_or_create_by(owner: repo_owner, name: repo_name)
|
83
107
|
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module Shipit
|
3
|
+
module ApiClientsHelper
|
4
|
+
def api_client_token(api_client)
|
5
|
+
if api_client.created_at >= 5.minutes.ago && current_user == api_client.creator
|
6
|
+
api_client.authentication_token
|
7
|
+
else
|
8
|
+
"#{api_client.authentication_token[0..5]}************************"
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -8,7 +8,10 @@ module Shipit
|
|
8
8
|
|
9
9
|
def perform(stack)
|
10
10
|
return unless stack.continuous_deployment?
|
11
|
-
|
11
|
+
|
12
|
+
# checks if there are any tasks running, including concurrent tasks
|
13
|
+
return if stack.occupied?
|
14
|
+
|
12
15
|
stack.trigger_continuous_delivery
|
13
16
|
end
|
14
17
|
end
|
data/app/models/shipit/stack.rb
CHANGED
@@ -13,6 +13,16 @@ module Shipit
|
|
13
13
|
super.merge(@stack.env)
|
14
14
|
end
|
15
15
|
|
16
|
+
def fetch_commit(commit)
|
17
|
+
create_directories
|
18
|
+
if valid_git_repository?(@stack.git_path)
|
19
|
+
git('fetch', 'origin', '--quiet', '--tags', commit.sha, env: env, chdir: @stack.git_path)
|
20
|
+
else
|
21
|
+
@stack.clear_git_cache!
|
22
|
+
git_clone(@stack.repo_git_url, @stack.git_path, branch: @stack.branch, env: env, chdir: @stack.deploys_path)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
16
26
|
def fetch
|
17
27
|
create_directories
|
18
28
|
if valid_git_repository?(@stack.git_path)
|
data/lib/shipit/task_commands.rb
CHANGED
data/lib/shipit/version.rb
CHANGED
@@ -3,7 +3,7 @@ require 'test_helper'
|
|
3
3
|
|
4
4
|
module Shipit
|
5
5
|
module Api
|
6
|
-
class MergeRequestsControllerTest <
|
6
|
+
class MergeRequestsControllerTest < ApiControllerTestCase
|
7
7
|
setup do
|
8
8
|
@stack = shipit_stacks(:shipit)
|
9
9
|
@merge_request = shipit_merge_requests(:shipit_pending)
|
@@ -3,7 +3,7 @@ require 'test_helper'
|
|
3
3
|
|
4
4
|
module Shipit
|
5
5
|
module Api
|
6
|
-
class StacksControllerTest <
|
6
|
+
class StacksControllerTest < ApiControllerTestCase
|
7
7
|
setup do
|
8
8
|
authenticate!
|
9
9
|
@stack = shipit_stacks(:shipit)
|
@@ -114,6 +114,57 @@ module Shipit
|
|
114
114
|
refute @stack.continuous_deployment
|
115
115
|
end
|
116
116
|
|
117
|
+
test "#update does not perform archive when key is not provided" do
|
118
|
+
refute_predicate @stack, :archived?
|
119
|
+
refute_predicate @stack, :locked?
|
120
|
+
|
121
|
+
patch :update, params: { id: @stack.to_param }
|
122
|
+
|
123
|
+
@stack.reload
|
124
|
+
refute_predicate @stack, :archived?
|
125
|
+
refute_predicate @stack, :locked?
|
126
|
+
end
|
127
|
+
|
128
|
+
test "#update does not perform unarchive when key is not provided" do
|
129
|
+
@stack.archive!(shipit_users(:walrus))
|
130
|
+
assert_predicate @stack, :locked?
|
131
|
+
assert_predicate @stack, :archived?
|
132
|
+
|
133
|
+
patch :update, params: { id: @stack.to_param }
|
134
|
+
|
135
|
+
@stack.reload
|
136
|
+
assert_predicate @stack, :locked?
|
137
|
+
assert_predicate @stack, :archived?
|
138
|
+
end
|
139
|
+
|
140
|
+
test "#update allows to archive the stack" do
|
141
|
+
refute_predicate @stack, :archived?
|
142
|
+
refute_predicate @stack, :locked?
|
143
|
+
|
144
|
+
patch :update, params: { id: @stack.to_param, archived: true }
|
145
|
+
|
146
|
+
@stack.reload
|
147
|
+
assert_predicate @stack, :locked?
|
148
|
+
assert_predicate @stack, :archived?
|
149
|
+
assert_instance_of AnonymousUser, @stack.lock_author
|
150
|
+
assert_equal "Archived", @stack.lock_reason
|
151
|
+
end
|
152
|
+
|
153
|
+
test "#update allows to unarchive the stack" do
|
154
|
+
@stack.archive!(shipit_users(:walrus))
|
155
|
+
assert_predicate @stack, :locked?
|
156
|
+
assert_predicate @stack, :archived?
|
157
|
+
|
158
|
+
patch :update, params: { id: @stack.to_param, archived: false }
|
159
|
+
|
160
|
+
@stack.reload
|
161
|
+
refute_predicate @stack, :archived?
|
162
|
+
refute_predicate @stack, :locked?
|
163
|
+
assert_nil @stack.locked_since
|
164
|
+
assert_nil @stack.lock_reason
|
165
|
+
assert_instance_of AnonymousUser, @stack.lock_author
|
166
|
+
end
|
167
|
+
|
117
168
|
test "#index returns a list of stacks" do
|
118
169
|
stack = Stack.last
|
119
170
|
get :index
|
data/test/dummy/db/schema.rb
CHANGED
@@ -10,7 +10,7 @@
|
|
10
10
|
#
|
11
11
|
# It's strongly recommended that you check this file into your version control system.
|
12
12
|
|
13
|
-
ActiveRecord::Schema.define(version:
|
13
|
+
ActiveRecord::Schema.define(version: 2023_07_03_181143) do
|
14
14
|
|
15
15
|
create_table "api_clients", force: :cascade do |t|
|
16
16
|
t.text "permissions", limit: 65535
|
@@ -42,7 +42,7 @@ ActiveRecord::Schema.define(version: 2021_11_03_154121) do
|
|
42
42
|
create_table "commit_deployment_statuses", force: :cascade do |t|
|
43
43
|
t.integer "commit_deployment_id"
|
44
44
|
t.string "status"
|
45
|
-
t.
|
45
|
+
t.bigint "github_id"
|
46
46
|
t.string "api_url"
|
47
47
|
t.datetime "created_at", null: false
|
48
48
|
t.datetime "updated_at", null: false
|
data/test/helpers/api_helper.rb
CHANGED
@@ -8,3 +8,16 @@ module ApiHelper
|
|
8
8
|
request.headers['Authorization'] = "Basic #{Base64.encode64(client.authentication_token)}"
|
9
9
|
end
|
10
10
|
end
|
11
|
+
|
12
|
+
module Shipit
|
13
|
+
class ApiControllerTestCase < ActionController::TestCase
|
14
|
+
private
|
15
|
+
|
16
|
+
def process(_action, **kwargs)
|
17
|
+
if kwargs[:method] != "GET"
|
18
|
+
kwargs[:as] ||= :json
|
19
|
+
end
|
20
|
+
super
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -278,6 +278,36 @@ module Shipit
|
|
278
278
|
end
|
279
279
|
end
|
280
280
|
|
281
|
+
test "#active_task? is false if stack has a concurrent deploy in active state" do
|
282
|
+
@stack.trigger_deploy(shipit_commits(:third), AnonymousUser.new, force: true)
|
283
|
+
refute @stack.active_task?
|
284
|
+
end
|
285
|
+
|
286
|
+
test "#occupied? is false if stack has no deploy in either pending or running state" do
|
287
|
+
@stack.deploys.active.destroy_all
|
288
|
+
refute @stack.occupied?
|
289
|
+
end
|
290
|
+
|
291
|
+
test "#occupied? is false if stack has no deploy at all" do
|
292
|
+
@stack.deploys.destroy_all
|
293
|
+
refute @stack.occupied?
|
294
|
+
end
|
295
|
+
|
296
|
+
test "occupied? is true if stack has a concurrent deploy in active state" do
|
297
|
+
@stack.trigger_deploy(shipit_commits(:third), AnonymousUser.new, force: true)
|
298
|
+
assert @stack.occupied?
|
299
|
+
end
|
300
|
+
|
301
|
+
test "occupied? is true if stack has a deploy in pending state" do
|
302
|
+
@stack.trigger_deploy(shipit_commits(:third), AnonymousUser.new)
|
303
|
+
assert @stack.occupied?
|
304
|
+
end
|
305
|
+
|
306
|
+
test "#occupied? is true if a rollback is ongoing" do
|
307
|
+
shipit_deploys(:shipit_complete).trigger_rollback(AnonymousUser.new)
|
308
|
+
assert @stack.occupied?
|
309
|
+
end
|
310
|
+
|
281
311
|
test "#deployable? returns true if the stack is not locked, not awaiting provision, and is not deploying" do
|
282
312
|
@stack.deploys.destroy_all
|
283
313
|
@stack.update!(lock_reason: nil, awaiting_provision: false)
|
@@ -21,6 +21,100 @@ module Shipit
|
|
21
21
|
StackCommands.stubs(git_version: Gem::Version.new('1.8.4.3'))
|
22
22
|
end
|
23
23
|
|
24
|
+
test "#fetch_commit calls git fetch if repository cache already exist" do
|
25
|
+
@stack.git_path.stubs(:exist?).returns(true)
|
26
|
+
@stack.git_path.stubs(:empty?).returns(false)
|
27
|
+
|
28
|
+
command = @commands.fetch_commit(@deploy.until_commit)
|
29
|
+
|
30
|
+
assert_equal %W(git fetch origin --quiet --tags #{@deploy.until_commit.sha}), command.args
|
31
|
+
end
|
32
|
+
|
33
|
+
test "#fetch_commit calls git fetch in git_path directory if repository cache already exist" do
|
34
|
+
@stack.git_path.stubs(:exist?).returns(true)
|
35
|
+
@stack.git_path.stubs(:empty?).returns(false)
|
36
|
+
|
37
|
+
command = @commands.fetch_commit(@deploy.until_commit)
|
38
|
+
|
39
|
+
assert_equal @stack.git_path.to_s, command.chdir
|
40
|
+
end
|
41
|
+
|
42
|
+
test "#fetch_commit calls git clone if repository cache do not exist" do
|
43
|
+
@stack.git_path.stubs(:exist?).returns(false)
|
44
|
+
|
45
|
+
command = @commands.fetch_commit(@deploy.until_commit)
|
46
|
+
|
47
|
+
expected = %W(git clone --quiet --single-branch --recursive --branch master #{@stack.repo_git_url} #{@stack.git_path})
|
48
|
+
assert_equal expected, command.args.map(&:to_s)
|
49
|
+
end
|
50
|
+
|
51
|
+
test "#fetch_commit calls git clone if repository cache is empty" do
|
52
|
+
@stack.git_path.stubs(:exist?).returns(true)
|
53
|
+
@stack.git_path.stubs(:empty?).returns(true)
|
54
|
+
|
55
|
+
command = @commands.fetch_commit(@deploy.until_commit)
|
56
|
+
|
57
|
+
expected = %W(git clone --quiet --single-branch --recursive --branch master #{@stack.repo_git_url} #{@stack.git_path})
|
58
|
+
assert_equal expected, command.args
|
59
|
+
end
|
60
|
+
|
61
|
+
test "#fetch_commit calls git clone if repository cache corrupt" do
|
62
|
+
@stack.git_path.stubs(:exist?).returns(true)
|
63
|
+
@stack.git_path.stubs(:empty?).returns(false)
|
64
|
+
StackCommands.any_instance.expects(:git_cmd_succeeds?)
|
65
|
+
.with(@stack.git_path)
|
66
|
+
.returns(false)
|
67
|
+
|
68
|
+
command = @commands.fetch_commit(@deploy.until_commit)
|
69
|
+
|
70
|
+
expected = %W(git clone --quiet --single-branch --recursive --branch master #{@stack.repo_git_url} #{@stack.git_path})
|
71
|
+
assert_equal expected, command.args
|
72
|
+
end
|
73
|
+
|
74
|
+
test "#fetch_commit clears a corrupted git stash before cloning" do
|
75
|
+
@stack.expects(:clear_git_cache!)
|
76
|
+
@stack.git_path.stubs(:exist?).returns(true)
|
77
|
+
@stack.git_path.stubs(:empty?).returns(false)
|
78
|
+
StackCommands.any_instance.expects(:git_cmd_succeeds?)
|
79
|
+
.with(@stack.git_path)
|
80
|
+
.returns(false)
|
81
|
+
|
82
|
+
command = @commands.fetch_commit(@deploy.until_commit)
|
83
|
+
|
84
|
+
expected = %W(git clone --quiet --single-branch --recursive --branch master #{@stack.repo_git_url} #{@stack.git_path})
|
85
|
+
assert_equal expected, command.args
|
86
|
+
end
|
87
|
+
|
88
|
+
test "#fetch_commit does not use --single-branch if git is outdated" do
|
89
|
+
@stack.git_path.stubs(:exist?).returns(false)
|
90
|
+
StackCommands.stubs(git_version: Gem::Version.new('1.7.2.30'))
|
91
|
+
|
92
|
+
command = @commands.fetch_commit(@deploy.until_commit)
|
93
|
+
|
94
|
+
expected = %W(git clone --quiet --recursive --branch master #{@stack.repo_git_url} #{@stack.git_path})
|
95
|
+
assert_equal expected, command.args.map(&:to_s)
|
96
|
+
end
|
97
|
+
|
98
|
+
test "#fetch_commit calls git fetch in base_path directory if repository cache do not exist" do
|
99
|
+
@stack.git_path.stubs(:exist?).returns(false)
|
100
|
+
|
101
|
+
command = @commands.fetch_commit(@deploy.until_commit)
|
102
|
+
|
103
|
+
assert_equal @stack.deploys_path.to_s, command.chdir
|
104
|
+
end
|
105
|
+
|
106
|
+
test "#fetch_commit merges Shipit.env in ENVIRONMENT" do
|
107
|
+
Shipit.stubs(:env).returns("SPECIFIC_CONFIG" => 5)
|
108
|
+
command = @commands.fetch_commit(@deploy.until_commit)
|
109
|
+
assert_equal '5', command.env["SPECIFIC_CONFIG"]
|
110
|
+
end
|
111
|
+
|
112
|
+
test "#env uses the correct Github token for a stack" do
|
113
|
+
Shipit.github(organization: 'shopify').stubs(:token).returns('aS3cr3Tt0kEn')
|
114
|
+
command = @commands.fetch_commit(@deploy.until_commit)
|
115
|
+
assert_equal 'aS3cr3Tt0kEn', command.env["GITHUB_TOKEN"]
|
116
|
+
end
|
117
|
+
|
24
118
|
test "#fetch calls git fetch if repository cache already exist" do
|
25
119
|
@stack.git_path.stubs(:exist?).returns(true)
|
26
120
|
@stack.git_path.stubs(:empty?).returns(false)
|
@@ -109,12 +203,6 @@ module Shipit
|
|
109
203
|
assert_equal '5', command.env["SPECIFIC_CONFIG"]
|
110
204
|
end
|
111
205
|
|
112
|
-
test "#env uses the correct Github token for a stack" do
|
113
|
-
Shipit.github(organization: 'shopify').stubs(:token).returns('aS3cr3Tt0kEn')
|
114
|
-
command = @commands.fetch
|
115
|
-
assert_equal 'aS3cr3Tt0kEn', command.env["GITHUB_TOKEN"]
|
116
|
-
end
|
117
|
-
|
118
206
|
test "#clone clones the repository cache into the working directory" do
|
119
207
|
commands = @commands.clone
|
120
208
|
assert_equal 2, commands.size
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: shipit-engine
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.38.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jean Boussier
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-07-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: active_model_serializers
|
@@ -507,6 +507,7 @@ files:
|
|
507
507
|
- app/controllers/shipit/status_controller.rb
|
508
508
|
- app/controllers/shipit/tasks_controller.rb
|
509
509
|
- app/controllers/shipit/webhooks_controller.rb
|
510
|
+
- app/helpers/shipit/api_clients_helper.rb
|
510
511
|
- app/helpers/shipit/chunks_helper.rb
|
511
512
|
- app/helpers/shipit/deploys_helper.rb
|
512
513
|
- app/helpers/shipit/github_url_helper.rb
|
@@ -771,6 +772,7 @@ files:
|
|
771
772
|
- db/migrate/20210504200438_add_github_updated_at_to_check_runs.rb
|
772
773
|
- db/migrate/20210823075617_change_check_runs_github_updated_at_default.rb
|
773
774
|
- db/migrate/20211103154121_increase_github_team_slug_size.rb
|
775
|
+
- db/migrate/20230703181143_change_commit_deployment_statuses_github_id_to_big_int.rb
|
774
776
|
- lib/shipit-engine.rb
|
775
777
|
- lib/shipit.rb
|
776
778
|
- lib/shipit/cast_value.rb
|
@@ -1039,7 +1041,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
1039
1041
|
- !ruby/object:Gem::Version
|
1040
1042
|
version: '0'
|
1041
1043
|
requirements: []
|
1042
|
-
rubygems_version: 3.
|
1044
|
+
rubygems_version: 3.4.14
|
1043
1045
|
signing_key:
|
1044
1046
|
specification_version: 4
|
1045
1047
|
summary: Application deployment software
|