Skip to content

Commit 8a91f3c

Browse files
svenfuchsvitalie
authored andcommitted
Shared build workspaces (#167)
1 parent 0d6db42 commit 8a91f3c

File tree

7 files changed

+206
-0
lines changed

7 files changed

+206
-0
lines changed

lib/travis/yml/schema/def/job.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
require 'travis/yml/schema/def/osx_image'
99
require 'travis/yml/schema/def/services'
1010
require 'travis/yml/schema/def/keys'
11+
require 'travis/yml/schema/def/workspaces'
1112
require 'travis/yml/schema/type'
1213

1314
module Travis
@@ -34,6 +35,7 @@ def define
3435
map :services
3536
map :group
3637
map :keys
38+
map :workspaces
3739

3840
map :before_install, to: :seq, summary: 'Scripts to run before the install stage'
3941
map :install, to: :seq, summary: 'Scripts to run at the install stage'
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# frozen_string_literal: true
2+
require 'travis/yml/schema/type'
3+
4+
module Travis
5+
module Yml
6+
module Schema
7+
module Def
8+
class Workspaces < Type::Seq
9+
register :workspaces
10+
11+
def define
12+
title 'Workspaces'
13+
14+
summary 'Shared build workspaces'
15+
16+
description <<~str
17+
Workspaces allow jobs within the same build to share files. They are
18+
useful when you want to use build artifacts from a previous job.
19+
For example, you create a cache that can be used in multiple jobs
20+
in the same build later.
21+
str
22+
23+
see 'Workspaces': 'https://docs.travis-ci.com/user/using-workspaces'
24+
25+
normal
26+
type :workspace
27+
export
28+
end
29+
end
30+
31+
class Workspace < Type::Map
32+
register :workspace
33+
34+
def define
35+
prefix :name
36+
37+
map :name, to: :str
38+
map :create, to: :bool
39+
40+
normal
41+
export
42+
end
43+
end
44+
end
45+
end
46+
end
47+
end
48+

schema.json

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -906,6 +906,9 @@
906906
"group": {
907907
"$ref": "#/definitions/type/group"
908908
},
909+
"workspaces": {
910+
"$ref": "#/definitions/type/workspaces"
911+
},
909912
"before_install": {
910913
"$ref": "#/definitions/type/strs",
911914
"summary": "Scripts to run before the install stage"
@@ -2214,6 +2217,53 @@
22142217
"see": {
22152218
"Customizing the Build": "https://docs.travis-ci.com/customizing-the-build/"
22162219
}
2220+
},
2221+
"workspace": {
2222+
"$id": "workspace",
2223+
"title": "Workspace",
2224+
"anyOf": [
2225+
{
2226+
"type": "object",
2227+
"properties": {
2228+
"name": {
2229+
"type": "string"
2230+
},
2231+
"create": {
2232+
"type": "boolean"
2233+
}
2234+
},
2235+
"additionalProperties": false,
2236+
"prefix": {
2237+
"key": "name"
2238+
},
2239+
"normal": true
2240+
},
2241+
{
2242+
"type": "string"
2243+
}
2244+
],
2245+
"normal": true
2246+
},
2247+
"workspaces": {
2248+
"$id": "workspaces",
2249+
"title": "Workspaces",
2250+
"description": "Workspaces allow jobs within the same build to share files. They are\nuseful when you want to use build artifacts from a previous job.\nFor example, you create a cache that can be used in multiple jobs\nin the same build later.",
2251+
"anyOf": [
2252+
{
2253+
"type": "array",
2254+
"items": {
2255+
"$ref": "#/definitions/type/workspace"
2256+
},
2257+
"normal": true
2258+
},
2259+
{
2260+
"$ref": "#/definitions/type/workspace"
2261+
}
2262+
],
2263+
"summary": "Shared build workspaces",
2264+
"see": {
2265+
"Workspaces": "https://docs.travis-ci.com/user/using-workspaces"
2266+
}
22172267
}
22182268
},
22192269
"addon": {
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
describe Travis::Yml do
2+
accept 'workspaces' do
3+
describe 'given a str' do
4+
yaml %(
5+
workspaces: ws1
6+
)
7+
it { should serialize_to workspaces: [name: 'ws1'] }
8+
end
9+
10+
describe 'given a map' do
11+
yaml %(
12+
workspaces:
13+
name: ws1
14+
)
15+
it { should serialize_to workspaces: [name: 'ws1'] }
16+
end
17+
18+
describe 'given a seq of strs' do
19+
yaml %(
20+
workspaces:
21+
- ws1
22+
)
23+
it { should serialize_to workspaces: [name: 'ws1'] }
24+
end
25+
26+
describe 'given a seq of maps' do
27+
yaml %(
28+
workspaces:
29+
- name: ws1
30+
create: true
31+
)
32+
it { should serialize_to workspaces: [name: 'ws1', create: true] }
33+
end
34+
end
35+
end

spec/travis/yml/schema/def/job_spec.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@
3838
virt: {
3939
'$ref': '#/definitions/type/virt'
4040
},
41+
workspaces: {
42+
'$ref': '#/definitions/type/workspaces'
43+
},
4144
before_install: {
4245
'$ref': '#/definitions/type/strs',
4346
summary: 'Scripts to run before the install stage'

spec/travis/yml/schema/def/root_spec.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,8 @@
137137
version
138138
virt
139139
vm
140+
workspace
141+
workspaces
140142
),
141143
addon: %i(
142144
apt
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
describe Travis::Yml::Schema::Def::Workspaces do
2+
describe 'workspaces' do
3+
subject { Travis::Yml.schema[:definitions][:type][:workspaces] }
4+
5+
# it { puts JSON.pretty_generate(subject) }
6+
7+
it do
8+
should include(
9+
'$id': :workspaces,
10+
title: 'Workspaces',
11+
summary: kind_of(String),
12+
description: kind_of(String),
13+
see: {
14+
Workspaces: kind_of(String)
15+
},
16+
anyOf: [
17+
{
18+
type: :array,
19+
items: {
20+
'$ref': '#/definitions/type/workspace',
21+
},
22+
normal: true,
23+
},
24+
{
25+
'$ref': '#/definitions/type/workspace',
26+
}
27+
],
28+
)
29+
end
30+
end
31+
32+
describe 'workspace' do
33+
subject { Travis::Yml.schema[:definitions][:type][:workspace] }
34+
35+
# it { puts JSON.pretty_generate(subject) }
36+
37+
it do
38+
should include(
39+
'$id': :workspace,
40+
title: 'Workspace',
41+
anyOf: [
42+
{
43+
type: :object,
44+
properties: {
45+
name: {
46+
type: :string
47+
},
48+
create: {
49+
type: :boolean
50+
}
51+
},
52+
prefix: {
53+
key: :name
54+
},
55+
additionalProperties: false,
56+
normal: true
57+
},
58+
{
59+
type: :string
60+
}
61+
],
62+
normal: true
63+
)
64+
end
65+
end
66+
end

0 commit comments

Comments
 (0)