Skip to content

Commit

Permalink
add workspaces
Browse files Browse the repository at this point in the history
  • Loading branch information
svenfuchs committed Apr 7, 2020
1 parent 74aa7e7 commit 256a2d6
Show file tree
Hide file tree
Showing 5 changed files with 201 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/travis/yml/schema/def/job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
require 'travis/yml/schema/def/group'
require 'travis/yml/schema/def/osx_image'
require 'travis/yml/schema/def/services'
require 'travis/yml/schema/def/workspaces'
require 'travis/yml/schema/type'

module Travis
Expand All @@ -32,6 +33,7 @@ def define
map :if, to: :condition
map :services
map :group
map :workspaces

map :before_install, to: :seq, summary: 'Scripts to run before the install stage'
map :install, to: :seq, summary: 'Scripts to run at the install stage'
Expand Down
48 changes: 48 additions & 0 deletions lib/travis/yml/schema/def/workspaces.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# frozen_string_literal: true
require 'travis/yml/schema/type'

module Travis
module Yml
module Schema
module Def
class Workspaces < Type::Seq
register :workspaces

def define
title 'Workspaces'

summary 'Shared build workspaces'

description <<~str
Workspaces allow jobs within the same build to share files. They are
useful when you want to use build artifacts from a previous job.
For example, you create a cache that can be used in multiple jobs
in the same build later.
str

see 'Workspaces': 'https://docs.travis-ci.com/user/using-workspaces'

normal
type :workspace
export
end
end

class Workspace < Type::Map
register :workspace

def define
prefix :name

map :name, to: :str
map :create, to: :bool

normal
export
end
end
end
end
end
end

50 changes: 50 additions & 0 deletions schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -860,6 +860,9 @@
"group": {
"$ref": "#/definitions/type/group"
},
"workspaces": {
"$ref": "#/definitions/type/workspaces"
},
"before_install": {
"$ref": "#/definitions/type/strs",
"summary": "Scripts to run before the install stage"
Expand Down Expand Up @@ -2119,6 +2122,53 @@
"lxd",
"vm"
]
},
"workspace": {
"$id": "workspace",
"title": "Workspace",
"anyOf": [
{
"type": "object",
"properties": {
"name": {
"type": "string"
},
"create": {
"type": "boolean"
}
},
"additionalProperties": false,
"prefix": {
"key": "name"
},
"normal": true
},
{
"type": "string"
}
],
"normal": true
},
"workspaces": {
"$id": "workspaces",
"title": "Workspaces",
"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.",
"anyOf": [
{
"type": "array",
"items": {
"$ref": "#/definitions/type/workspace"
},
"normal": true
},
{
"$ref": "#/definitions/type/workspace"
}
],
"summary": "Shared build workspaces",
"see": {
"Workspaces": "https://docs.travis-ci.com/user/using-workspaces"
}
}
},
"addon": {
Expand Down
35 changes: 35 additions & 0 deletions spec/travis/yml/accept/workspaces_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
describe Travis::Yml do
accept 'workspaces' do
describe 'given a str' do
yaml %(
workspaces: ws1
)
it { should serialize_to workspaces: [name: 'ws1'] }
end

describe 'given a map' do
yaml %(
workspaces:
name: ws1
)
it { should serialize_to workspaces: [name: 'ws1'] }
end

describe 'given a seq of strs' do
yaml %(
workspaces:
- ws1
)
it { should serialize_to workspaces: [name: 'ws1'] }
end

describe 'given a seq of maps' do
yaml %(
workspaces:
- name: ws1
create: true
)
it { should serialize_to workspaces: [name: 'ws1', create: true] }
end
end
end
66 changes: 66 additions & 0 deletions spec/travis/yml/schema/def/workspaces_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
describe Travis::Yml::Schema::Def::Workspaces do
describe 'workspaces' do
subject { Travis::Yml.schema[:definitions][:type][:workspaces] }

# it { puts JSON.pretty_generate(subject) }

it do
should include(
'$id': :workspaces,
title: 'Workspaces',
summary: kind_of(String),
description: kind_of(String),
see: {
Workspaces: kind_of(String)
},
anyOf: [
{
type: :array,
items: {
'$ref': '#/definitions/type/workspace',
},
normal: true,
},
{
'$ref': '#/definitions/type/workspace',
}
],
)
end
end

describe 'workspace' do
subject { Travis::Yml.schema[:definitions][:type][:workspace] }

# it { puts JSON.pretty_generate(subject) }

it do
should include(
'$id': :workspace,
title: 'Workspace',
anyOf: [
{
type: :object,
properties: {
name: {
type: :string
},
create: {
type: :boolean
}
},
prefix: {
key: :name
},
additionalProperties: false,
normal: true
},
{
type: :string
}
],
normal: true
)
end
end
end

0 comments on commit 256a2d6

Please sign in to comment.