shipit-engine 0.34.0 → 0.36.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/README.md +7 -7
- data/app/assets/stylesheets/_pages/_deploy.scss +2 -1
- data/app/controllers/concerns/shipit/authentication.rb +5 -1
- data/app/controllers/shipit/api/base_controller.rb +13 -1
- data/app/controllers/shipit/api/rollbacks_controller.rb +1 -1
- data/app/controllers/shipit/api/stacks_controller.rb +8 -2
- data/app/controllers/shipit/api/tasks_controller.rb +19 -2
- data/app/helpers/shipit/stacks_helper.rb +11 -0
- data/app/models/concerns/shipit/deferred_touch.rb +3 -3
- data/app/models/shipit/anonymous_user.rb +4 -0
- data/app/models/shipit/commit_checks.rb +3 -3
- data/app/models/shipit/rollback.rb +5 -0
- data/app/models/shipit/task.rb +3 -3
- data/app/models/shipit/user.rb +23 -9
- data/app/serializers/shipit/stack_serializer.rb +1 -1
- data/app/views/shipit/deploys/_deploy.html.erb +1 -5
- data/app/views/shipit/stacks/_banners.html.erb +1 -1
- data/app/views/shipit/stacks/_settings_form.erb +55 -0
- data/app/views/shipit/stacks/settings.html.erb +1 -55
- data/app/views/shipit/stacks/show.html.erb +1 -1
- data/config/locales/en.yml +1 -1
- data/config/routes.rb +4 -0
- data/db/migrate/20210504200438_add_github_updated_at_to_check_runs.rb +1 -1
- data/db/migrate/20210823075617_change_check_runs_github_updated_at_default.rb +5 -0
- data/db/migrate/20211103154121_increase_github_team_slug_size.rb +5 -0
- data/lib/shipit/commands.rb +12 -6
- data/lib/shipit/engine.rb +13 -5
- data/lib/shipit/stack_commands.rb +3 -3
- data/lib/shipit/task_commands.rb +1 -1
- data/lib/shipit/version.rb +1 -1
- data/lib/shipit.rb +5 -2
- data/test/controllers/api/hooks_controller_test.rb +1 -1
- data/test/controllers/api/rollback_controller_test.rb +1 -0
- data/test/controllers/api/stacks_controller_test.rb +25 -0
- data/test/controllers/api/tasks_controller_test.rb +56 -0
- data/test/controllers/stacks_controller_test.rb +11 -0
- data/test/dummy/config/application.rb +1 -2
- data/test/dummy/db/schema.rb +2 -2
- data/test/fixtures/shipit/check_runs.yml +3 -3
- data/test/fixtures/shipit/commits.yml +101 -101
- data/test/fixtures/shipit/deliveries.yml +1 -1
- data/test/fixtures/shipit/merge_requests.yml +19 -19
- data/test/fixtures/shipit/stacks.yml +28 -28
- data/test/fixtures/shipit/statuses.yml +16 -16
- data/test/fixtures/shipit/tasks.yml +65 -65
- data/test/fixtures/shipit/users.yml +2 -5
- data/test/models/commits_test.rb +6 -6
- data/test/models/deploys_test.rb +22 -0
- data/test/models/tasks_test.rb +2 -2
- data/test/models/team_test.rb +21 -2
- data/test/models/users_test.rb +29 -9
- data/test/unit/deploy_commands_test.rb +7 -7
- metadata +170 -167
@@ -16,7 +16,7 @@ module Shipit
|
|
16
16
|
def fetch
|
17
17
|
create_directories
|
18
18
|
if valid_git_repository?(@stack.git_path)
|
19
|
-
git('fetch', 'origin', '--tags', @stack.branch, env: env, chdir: @stack.git_path)
|
19
|
+
git('fetch', 'origin', '--quiet', '--tags', @stack.branch, env: env, chdir: @stack.git_path)
|
20
20
|
else
|
21
21
|
@stack.clear_git_cache!
|
22
22
|
git_clone(@stack.repo_git_url, @stack.git_path, branch: @stack.branch, env: env, chdir: @stack.deploys_path)
|
@@ -72,7 +72,7 @@ module Shipit
|
|
72
72
|
).run!
|
73
73
|
|
74
74
|
git_dir = File.join(dir, @stack.repo_name)
|
75
|
-
git('checkout', commit.sha, chdir: git_dir).run! if commit
|
75
|
+
git('-c', 'advice.detachedHead=false', 'checkout', commit.sha, chdir: git_dir).run! if commit
|
76
76
|
yield Pathname.new(git_dir)
|
77
77
|
end
|
78
78
|
end
|
@@ -90,7 +90,7 @@ module Shipit
|
|
90
90
|
end
|
91
91
|
|
92
92
|
def git_clone(url, path, branch: 'master', **kwargs)
|
93
|
-
git('clone', *modern_git_args, '--recursive', '--branch', branch, url, path, **kwargs)
|
93
|
+
git('clone', '--quiet', *modern_git_args, '--recursive', '--branch', branch, url, path, **kwargs)
|
94
94
|
end
|
95
95
|
|
96
96
|
def modern_git_args
|
data/lib/shipit/task_commands.rb
CHANGED
data/lib/shipit/version.rb
CHANGED
data/lib/shipit.rb
CHANGED
@@ -5,7 +5,6 @@ require 'state_machines-activerecord'
|
|
5
5
|
require 'validate_url'
|
6
6
|
require 'responders'
|
7
7
|
require 'explicit-parameters'
|
8
|
-
require 'attr_encrypted'
|
9
8
|
|
10
9
|
require 'sass-rails'
|
11
10
|
require 'coffee-rails'
|
@@ -153,7 +152,11 @@ module Shipit
|
|
153
152
|
end
|
154
153
|
|
155
154
|
def user_access_tokens_key
|
156
|
-
|
155
|
+
if secrets.user_access_tokens_key.present?
|
156
|
+
secrets.user_access_tokens_key
|
157
|
+
elsif secrets.secret_key_base
|
158
|
+
Digest::SHA256.digest("user_access_tokens_key" + secrets.secret_key_base)
|
159
|
+
end
|
157
160
|
end
|
158
161
|
|
159
162
|
def host
|
@@ -96,6 +96,24 @@ module Shipit
|
|
96
96
|
assert_equal 'test', @stack.branch
|
97
97
|
end
|
98
98
|
|
99
|
+
test "#update updates the stack when nil deploy_url" do
|
100
|
+
@stack.update(deploy_url: nil)
|
101
|
+
@stack.update(continuous_deployment: true)
|
102
|
+
assert_nil @stack.deploy_url
|
103
|
+
assert @stack.continuous_deployment
|
104
|
+
|
105
|
+
patch :update, params: {
|
106
|
+
id: @stack.to_param,
|
107
|
+
continuous_deployment: false,
|
108
|
+
}
|
109
|
+
|
110
|
+
assert_response :ok
|
111
|
+
@stack.reload
|
112
|
+
|
113
|
+
assert_nil @stack.deploy_url
|
114
|
+
refute @stack.continuous_deployment
|
115
|
+
end
|
116
|
+
|
99
117
|
test "#index returns a list of stacks" do
|
100
118
|
stack = Stack.last
|
101
119
|
get :index
|
@@ -189,6 +207,13 @@ module Shipit
|
|
189
207
|
assert_response :forbidden
|
190
208
|
assert_json 'message', 'This operation requires the `write:stack` permission'
|
191
209
|
end
|
210
|
+
|
211
|
+
test "#refresh queues a GithubSyncJob" do
|
212
|
+
assert_enqueued_with(job: GithubSyncJob, args: [id: @stack.id]) do
|
213
|
+
post :refresh, params: { id: @stack.to_param }
|
214
|
+
end
|
215
|
+
assert_response :accepted
|
216
|
+
end
|
192
217
|
end
|
193
218
|
end
|
194
219
|
end
|
@@ -6,6 +6,7 @@ module Shipit
|
|
6
6
|
class TasksControllerTest < ActionController::TestCase
|
7
7
|
setup do
|
8
8
|
@stack = shipit_stacks(:shipit)
|
9
|
+
@user = shipit_users(:walrus)
|
9
10
|
authenticate!
|
10
11
|
end
|
11
12
|
|
@@ -90,6 +91,61 @@ module Shipit
|
|
90
91
|
assert_response :conflict
|
91
92
|
assert_json 'message', 'A task is already running.'
|
92
93
|
end
|
94
|
+
|
95
|
+
test "#trigger fails when user does not have deploy permission" do
|
96
|
+
@client.permissions.delete('deploy:stack')
|
97
|
+
@client.save!
|
98
|
+
|
99
|
+
assert_no_difference 'Task.count' do
|
100
|
+
post :trigger, params: { stack_id: @stack.to_param, task_name: 'restart' }
|
101
|
+
end
|
102
|
+
|
103
|
+
assert_response :forbidden
|
104
|
+
assert_json 'message', 'This operation requires the `deploy:stack` permission'
|
105
|
+
end
|
106
|
+
|
107
|
+
test "#abort aborts the task" do
|
108
|
+
task = shipit_deploys(:shipit_running)
|
109
|
+
task.ping
|
110
|
+
|
111
|
+
put :abort, params: { stack_id: @stack.to_param, id: task.id }
|
112
|
+
|
113
|
+
assert_response :accepted
|
114
|
+
assert_equal 'aborting', task.reload.status
|
115
|
+
end
|
116
|
+
|
117
|
+
test "#abort sets `aborted_by` to the current user" do
|
118
|
+
task = shipit_deploys(:shipit_running)
|
119
|
+
task.ping
|
120
|
+
request.headers['X-Shipit-User'] = @user.login
|
121
|
+
|
122
|
+
put :abort, params: { stack_id: @stack.to_param, id: task.id }
|
123
|
+
|
124
|
+
assert_equal task.reload.aborted_by, @user
|
125
|
+
end
|
126
|
+
|
127
|
+
test "#abort responds with method_not_allowed if the task is not currently running" do
|
128
|
+
task = shipit_deploys(:shipit_aborted)
|
129
|
+
task.ping
|
130
|
+
put :abort, params: { stack_id: @stack.to_param, id: task.id }
|
131
|
+
|
132
|
+
assert_response :method_not_allowed
|
133
|
+
assert_json 'message', 'This task is not currently running.'
|
134
|
+
end
|
135
|
+
|
136
|
+
test "#abort fails when user does not have deploy permission" do
|
137
|
+
@client.permissions.delete('deploy:stack')
|
138
|
+
@client.save!
|
139
|
+
task = shipit_deploys(:shipit_running)
|
140
|
+
task.ping
|
141
|
+
|
142
|
+
assert_no_difference 'Task.count' do
|
143
|
+
put :abort, params: { stack_id: @stack.to_param, id: task.id }
|
144
|
+
end
|
145
|
+
|
146
|
+
assert_response :forbidden
|
147
|
+
assert_json 'message', 'This operation requires the `deploy:stack` permission'
|
148
|
+
end
|
93
149
|
end
|
94
150
|
end
|
95
151
|
end
|
@@ -36,6 +36,17 @@ module Shipit
|
|
36
36
|
assert_redirected_to '/github/auth/github?origin=http%3A%2F%2Ftest.host%2F'
|
37
37
|
end
|
38
38
|
|
39
|
+
test "users which require a fresh login are redirected" do
|
40
|
+
user = shipit_users(:walrus)
|
41
|
+
user.update!(github_access_token: 'some_legacy_value')
|
42
|
+
assert_predicate user, :requires_fresh_login?
|
43
|
+
|
44
|
+
get :index
|
45
|
+
|
46
|
+
assert_redirected_to '/github/auth/github?origin=http%3A%2F%2Ftest.host%2F'
|
47
|
+
assert_nil session[:user_id]
|
48
|
+
end
|
49
|
+
|
39
50
|
test "current_user must be a member of at least a Shipit.github_teams" do
|
40
51
|
session[:user_id] = shipit_users(:bob).id
|
41
52
|
Shipit.stubs(:github_teams).returns([shipit_teams(:cyclimse_cooks), shipit_teams(:shopify_developers)])
|
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: 2021_11_03_154121) do
|
14
14
|
|
15
15
|
create_table "api_clients", force: :cascade do |t|
|
16
16
|
t.text "permissions", limit: 65535
|
@@ -315,7 +315,7 @@ ActiveRecord::Schema.define(version: 2021_05_04_200438) do
|
|
315
315
|
create_table "teams", force: :cascade do |t|
|
316
316
|
t.integer "github_id", limit: 4
|
317
317
|
t.string "api_url", limit: 255
|
318
|
-
t.string "slug", limit:
|
318
|
+
t.string "slug", limit: 255
|
319
319
|
t.string "name", limit: 255
|
320
320
|
t.string "organization", limit: 39
|
321
321
|
t.datetime "created_at", null: false
|
@@ -7,7 +7,7 @@ second_pending_travis:
|
|
7
7
|
conclusion: success
|
8
8
|
html_url: "http://www.example.com/run/424242"
|
9
9
|
details_url: "http://www.example.com/build/424242"
|
10
|
-
created_at: <%= 10.days.ago.
|
10
|
+
created_at: <%= 10.days.ago.to_formatted_s(:db) %>
|
11
11
|
|
12
12
|
check_runs_first_pending_coveralls:
|
13
13
|
stack: check_runs
|
@@ -15,7 +15,7 @@ check_runs_first_pending_coveralls:
|
|
15
15
|
github_id: 43
|
16
16
|
title: lets go
|
17
17
|
name: Coverage metrics
|
18
|
-
created_at: <%= 10.days.ago.
|
18
|
+
created_at: <%= 10.days.ago.to_formatted_s(:db) %>
|
19
19
|
conclusion: pending
|
20
20
|
html_url: "http://www.example.com/run/434343"
|
21
21
|
details_url: "http://www.example.com/build/434343"
|
@@ -26,7 +26,7 @@ check_runs_first_success_coveralls:
|
|
26
26
|
github_id: 434343
|
27
27
|
title: lets go
|
28
28
|
name: Coverage metrics
|
29
|
-
created_at: <%= 9.days.ago.
|
29
|
+
created_at: <%= 9.days.ago.to_formatted_s(:db) %>
|
30
30
|
conclusion: success
|
31
31
|
html_url: "http://www.example.com/run/434343"
|
32
32
|
details_url: "http://www.example.com/build/434343"
|