From 421b9a2a3f2b89b6141421daee1939428c056210 Mon Sep 17 00:00:00 2001 From: Sven Fuchs Date: Fri, 26 May 2023 15:06:32 +0200 Subject: [PATCH] Shared build workspaces --- lib/travis/yml/schema/def/job.rb | 2 + lib/travis/yml/schema/def/workspaces.rb | 48 ++++++++++++++ schema.json | 50 ++++++++++++++ spec/travis/yml/accept/workspaces_spec.rb | 35 ++++++++++ spec/travis/yml/schema/def/job_spec.rb | 3 + spec/travis/yml/schema/def/root_spec.rb | 2 + spec/travis/yml/schema/def/workspaces_spec.rb | 66 +++++++++++++++++++ 7 files changed, 206 insertions(+) create mode 100644 lib/travis/yml/schema/def/workspaces.rb create mode 100644 spec/travis/yml/accept/workspaces_spec.rb create mode 100644 spec/travis/yml/schema/def/workspaces_spec.rb diff --git a/lib/travis/yml/schema/def/job.rb b/lib/travis/yml/schema/def/job.rb index a4529bdf0..8169048b9 100644 --- a/lib/travis/yml/schema/def/job.rb +++ b/lib/travis/yml/schema/def/job.rb @@ -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 @@ -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' diff --git a/lib/travis/yml/schema/def/workspaces.rb b/lib/travis/yml/schema/def/workspaces.rb new file mode 100644 index 000000000..0773b216e --- /dev/null +++ b/lib/travis/yml/schema/def/workspaces.rb @@ -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 + diff --git a/schema.json b/schema.json index 39ea4c7d8..a7c8ff860 100644 --- a/schema.json +++ b/schema.json @@ -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" @@ -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": { diff --git a/spec/travis/yml/accept/workspaces_spec.rb b/spec/travis/yml/accept/workspaces_spec.rb new file mode 100644 index 000000000..0619222da --- /dev/null +++ b/spec/travis/yml/accept/workspaces_spec.rb @@ -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 diff --git a/spec/travis/yml/schema/def/job_spec.rb b/spec/travis/yml/schema/def/job_spec.rb index 9ed4ad0eb..ab0d9fc75 100644 --- a/spec/travis/yml/schema/def/job_spec.rb +++ b/spec/travis/yml/schema/def/job_spec.rb @@ -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' diff --git a/spec/travis/yml/schema/def/root_spec.rb b/spec/travis/yml/schema/def/root_spec.rb index 0e770a8a9..44fff981a 100644 --- a/spec/travis/yml/schema/def/root_spec.rb +++ b/spec/travis/yml/schema/def/root_spec.rb @@ -137,6 +137,8 @@ version virt vm + workspace + workspaces ), addon: %i( apt diff --git a/spec/travis/yml/schema/def/workspaces_spec.rb b/spec/travis/yml/schema/def/workspaces_spec.rb new file mode 100644 index 000000000..931805700 --- /dev/null +++ b/spec/travis/yml/schema/def/workspaces_spec.rb @@ -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