Skip to content

Commit 4ede613

Browse files
committed
add workspaces
1 parent 74aa7e7 commit 4ede613

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
@@ -7,6 +7,7 @@
77
require 'travis/yml/schema/def/group'
88
require 'travis/yml/schema/def/osx_image'
99
require 'travis/yml/schema/def/services'
10+
require 'travis/yml/schema/def/workspaces'
1011
require 'travis/yml/schema/type'
1112

1213
module Travis
@@ -32,6 +33,7 @@ def define
3233
map :if, to: :condition
3334
map :services
3435
map :group
36+
map :workspaces
3537

3638
map :before_install, to: :seq, summary: 'Scripts to run before the install stage'
3739
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
@@ -860,6 +860,9 @@
860860
"group": {
861861
"$ref": "#/definitions/type/group"
862862
},
863+
"workspaces": {
864+
"$ref": "#/definitions/type/workspaces"
865+
},
863866
"before_install": {
864867
"$ref": "#/definitions/type/strs",
865868
"summary": "Scripts to run before the install stage"
@@ -2119,6 +2122,53 @@
21192122
"lxd",
21202123
"vm"
21212124
]
2125+
},
2126+
"workspace": {
2127+
"$id": "workspace",
2128+
"title": "Workspace",
2129+
"anyOf": [
2130+
{
2131+
"type": "object",
2132+
"properties": {
2133+
"name": {
2134+
"type": "string"
2135+
},
2136+
"create": {
2137+
"type": "boolean"
2138+
}
2139+
},
2140+
"additionalProperties": false,
2141+
"prefix": {
2142+
"key": "name"
2143+
},
2144+
"normal": true
2145+
},
2146+
{
2147+
"type": "string"
2148+
}
2149+
],
2150+
"normal": true
2151+
},
2152+
"workspaces": {
2153+
"$id": "workspaces",
2154+
"title": "Workspaces",
2155+
"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.",
2156+
"anyOf": [
2157+
{
2158+
"type": "array",
2159+
"items": {
2160+
"$ref": "#/definitions/type/workspace"
2161+
},
2162+
"normal": true
2163+
},
2164+
{
2165+
"$ref": "#/definitions/type/workspace"
2166+
}
2167+
],
2168+
"summary": "Shared build workspaces",
2169+
"see": {
2170+
"Workspaces": "https://docs.travis-ci.com/user/using-workspaces"
2171+
}
21222172
}
21232173
},
21242174
"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
@@ -133,6 +133,8 @@
133133
support
134134
version
135135
virt
136+
workspace
137+
workspaces
136138
),
137139
addon: %i(
138140
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)