Skip to content

Commit

Permalink
Shared build workspaces (#167) ship:docker
Browse files Browse the repository at this point in the history
  • Loading branch information
svenfuchs authored and vitalie committed May 26, 2023
1 parent ddf612b commit e37e384
Show file tree
Hide file tree
Showing 7 changed files with 206 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 @@ -8,6 +8,7 @@
require 'travis/yml/schema/def/osx_image'
require 'travis/yml/schema/def/services'
require 'travis/yml/schema/def/keys'
require 'travis/yml/schema/def/workspaces'
require 'travis/yml/schema/type'

module Travis
Expand All @@ -34,6 +35,7 @@ def define
map :services
map :group
map :keys
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 @@ -906,6 +906,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 @@ -2214,6 +2217,53 @@
"see": {
"Customizing the Build": "https://docs.travis-ci.com/customizing-the-build/"
}
},
"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
3 changes: 3 additions & 0 deletions spec/travis/yml/schema/def/job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@
virt: {
'$ref': '#/definitions/type/virt'
},
workspaces: {
'$ref': '#/definitions/type/workspaces'
},
before_install: {
'$ref': '#/definitions/type/strs',
summary: 'Scripts to run before the install stage'
Expand Down
2 changes: 2 additions & 0 deletions spec/travis/yml/schema/def/root_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@
version
virt
vm
workspace
workspaces
),
addon: %i(
apt
Expand Down
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 e37e384

Please sign in to comment.