Skip to content
Snippets Groups Projects
Commit 387e4c80 authored by Mireya Andres's avatar Mireya Andres :red_circle: Committed by Frédéric Caplette
Browse files

Update `cache` keyword for the JSON schema

This also removes the deprecated `cache_entry` keyword.

Changelog: fixed
parent 64adf964
No related branches found
No related tags found
1 merge request!103007Update `cache` keyword for the JSON schema
Showing
with 223 additions and 87 deletions
......@@ -103,7 +103,9 @@
"workflow": {
"type": "object",
"properties": {
"name": { "$ref": "#/definitions/workflowName" },
"name": {
"$ref": "#/definitions/workflowName"
},
"rules": {
"type": "array",
"items": {
......@@ -861,98 +863,74 @@
"markdownDescription": "Describes the conditions for when to run the job. Defaults to 'on_success'. [Learn More](https://docs.gitlab.com/ee/ci/yaml/#when).",
"default": "on_success",
"type": "string",
"enum": ["on_success", "on_failure", "always", "never", "manual", "delayed"]
"enum": [
"on_success",
"on_failure",
"always",
"never",
"manual",
"delayed"
]
},
"cache": {
"markdownDescription": "Use `cache` to specify a list of files and directories to cache between jobs. You can only use paths that are in the local working copy. [Learn More](https://docs.gitlab.com/ee/ci/yaml/#cache)",
"properties": {
"when": {
"markdownDescription": "Defines when to save the cache, based on the status of the job. [Learn More](https://docs.gitlab.com/ee/ci/yaml/#cachewhen).",
"default": "on_success",
"oneOf": [
{
"enum": [
"on_success"
],
"description": "Save the cache only when the job succeeds."
},
{
"enum": [
"on_failure"
],
"description": "Save the cache only when the job fails. "
},
{
"enum": [
"always"
],
"description": "Always save the cache. "
}
]
}
}
},
"cache_entry": {
"type": "object",
"description": "Specify files or directories to cache between jobs. Can be set globally or per job.",
"additionalProperties": false,
"properties": {
"paths": {
"type": "array",
"description": "List of files or paths to cache.",
"items": {
"type": "string"
}
},
"key": {
"markdownDescription": "Use the `cache:key` keyword to give each cache a unique identifying key. All jobs that use the same cache key use the same cache, including in different pipelines. Must be used with `cache:path`, or nothing is cached. [Learn More](https://docs.gitlab.com/ee/ci/yaml/#cachekey).",
"oneOf": [
{
"type": "string",
"description": "Unique cache ID, to allow e.g. specific branch or job cache. Environment variables can be used to set up unique keys (e.g. \"$CI_COMMIT_REF_SLUG\" for per branch cache)."
"pattern": "^(?!.*\\/)^(.*[^.]+.*)$"
},
{
"type": "object",
"description": "When you include cache:key:files, you must also list the project files that will be used to generate the key, up to a maximum of two files. The cache key will be a SHA checksum computed from the most recent commits (up to two, if two files are listed) that changed the given files.",
"properties": {
"files": {
"markdownDescription": "Use the `cache:key:files` keyword to generate a new key when one or two specific files change. [Learn More](https://docs.gitlab.com/ee/ci/yaml/#cachekeyfiles)",
"type": "array",
"items": {
"type": "string"
},
"minItems": 1,
"maxItems": 2
},
"prefix": {
"markdownDescription": "Use `cache:key:prefix` to combine a prefix with the SHA computed for `cache:key:files`. [Learn More](https://docs.gitlab.com/ee/ci/yaml/#cachekeyprefix)",
"type": "string"
}
}
}
]
},
"untracked": {
"type": "boolean",
"description": "Set to `true` to cache untracked files.",
"default": false
"paths": {
"type": "array",
"markdownDescription": "Use the `cache:paths` keyword to choose which files or directories to cache. [Learn More](https://docs.gitlab.com/ee/ci/yaml/#cachepaths)",
"items": {
"type": "string"
}
},
"policy": {
"type": "string",
"description": "Determines the strategy for downloading and updating the cache.",
"markdownDescription": "Determines the strategy for downloading and updating the cache. [Learn More](https://docs.gitlab.com/ee/ci/yaml/#cachepolicy)",
"default": "pull-push",
"oneOf": [
{
"enum": [
"pull"
],
"description": "Pull will download cache but skip uploading after job completes."
},
{
"enum": [
"push"
],
"description": "Push will skip downloading cache and always recreate cache after job completes."
},
{
"enum": [
"pull-push"
],
"description": "Pull-push will both download cache at job start and upload cache on job success."
}
"enum": [
"pull",
"push",
"pull-push"
]
},
"untracked": {
"type": "boolean",
"markdownDescription": "Use `untracked: true` to cache all files that are untracked in your Git repository. [Learn More](https://docs.gitlab.com/ee/ci/yaml/#cacheuntracked)",
"default": false
},
"when": {
"markdownDescription": "Defines when to save the cache, based on the status of the job. [Learn More](https://docs.gitlab.com/ee/ci/yaml/#cachewhen).",
"default": "on_success",
"enum": [
"on_success",
"on_failure",
"always"
]
}
}
......
......@@ -35,7 +35,6 @@ import JobWhenYaml from './yaml_tests/positive_tests/job_when.yml';
// YAML NEGATIVE TEST
import ArtifactsNegativeYaml from './yaml_tests/negative_tests/artifacts.yml';
import CacheNegativeYaml from './yaml_tests/negative_tests/cache.yml';
import IncludeNegativeYaml from './yaml_tests/negative_tests/include.yml';
import RulesNegativeYaml from './yaml_tests/negative_tests/rules.yml';
import VariablesNegativeYaml from './yaml_tests/negative_tests/variables.yml';
......@@ -62,6 +61,16 @@ import ProjectPathTriggerProjectLeadSlashYaml from './yaml_tests/negative_tests/
import ProjectPathTriggerProjectNoSlashYaml from './yaml_tests/negative_tests/project_path/trigger/project/no_slash.yml';
import ProjectPathTriggerProjectTailSlashYaml from './yaml_tests/negative_tests/project_path/trigger/project/tailing_slash.yml';
import CacheKeyFilesNotArray from './yaml_tests/negative_tests/cache/key_files_not_an_array.yml';
import CacheKeyPrefixArray from './yaml_tests/negative_tests/cache/key_prefix_array.yml';
import CacheKeyWithDot from './yaml_tests/negative_tests/cache/key_with_dot.yml';
import CacheKeyWithMultipleDots from './yaml_tests/negative_tests/cache/key_with_multiple_dots.yml';
import CacheKeyWithSlash from './yaml_tests/negative_tests/cache/key_with_slash.yml';
import CachePathsNotAnArray from './yaml_tests/negative_tests/cache/paths_not_an_array.yml';
import CacheUntrackedString from './yaml_tests/negative_tests/cache/untracked_string.yml';
import CacheWhenInteger from './yaml_tests/negative_tests/cache/when_integer.yml';
import CacheWhenNotReservedKeyword from './yaml_tests/negative_tests/cache/when_not_reserved_keyword.yml';
const ajv = new Ajv({
strictTypes: false,
strictTuples: false,
......@@ -116,7 +125,15 @@ describe('negative tests', () => {
// YAML
ArtifactsNegativeYaml,
CacheNegativeYaml,
CacheKeyFilesNotArray,
CacheKeyPrefixArray,
CacheKeyWithDot,
CacheKeyWithMultipleDots,
CacheKeyWithSlash,
CachePathsNotAnArray,
CacheUntrackedString,
CacheWhenInteger,
CacheWhenNotReservedKeyword,
IncludeNegativeYaml,
JobWhenNegativeYaml,
RulesNegativeYaml,
......
stages:
- prepare
# invalid cache:when values
when no integer:
stage: prepare
cache:
when: 0
when must be a reserved word:
stage: prepare
cache:
when: 'never'
cache-key-files-not-an-array:
script: echo "This job uses a cache."
cache:
key:
files: package.json
paths:
- vendor/ruby
- node_modules
cache-key-prefix-array:
script: echo "This job uses a cache."
cache:
key:
files:
- Gemfile.lock
prefix:
- binaries-cache-$CI_JOB_NAME
paths:
- binaries/
cache-key-with-.:
script: echo "This job uses a cache."
cache:
key: .
paths:
- binaries/
cache-key-with-multiple-.:
stage: test
script: echo "This job uses a cache."
cache:
key: ..
paths:
- binaries/
cache-key-with-/:
script: echo "This job uses a cache."
cache:
key: binaries-ca/che
paths:
- binaries/
cache-path-not-an-array:
script: echo "This job uses a cache."
cache:
key: binaries-cache
paths: binaries/*.apk
cache-untracked-string:
script: echo "This job uses a cache."
cache:
untracked: 'true'
when_integer:
script: echo "This job uses a cache."
cache:
when: 0
when_not_reserved_keyword:
script: echo "This job uses a cache."
cache:
when: 'never'
stages:
- prepare
# valid cache:when values
job1:
stage: prepare
script:
- echo 'running job'
cache:
when: 'on_success'
job2:
stage: prepare
script:
- echo 'running job'
cache:
when: 'on_failure'
job3:
stage: prepare
script:
- echo 'running job'
cache:
when: 'always'
# valid cache:paths
cache-paths:
script: echo "This job uses a cache."
cache:
key: binaries-cache
paths:
- binaries/*.apk
- .config
# valid cache:key
cache-key-string:
script: echo "This job uses a cache."
cache:
key: random-string
paths:
- binaries/
cache-key-string-with-dots:
script: echo "This job uses a cache."
cache:
key: random-..string
paths:
- binaries/
cache-key-string-beginning-with-dot:
script: echo "This job uses a cache."
cache:
key: .random-string
paths:
- binaries/
cache-key-string-ending-with-dot:
script: echo "This job uses a cache."
cache:
key: random-string.
paths:
- binaries/
cache-key-predefined-variable:
script: echo "This job uses a cache."
cache:
key: $CI_COMMIT_REF_SLUG
paths:
- binaries/
cache-key-combination:
script: echo "This job uses a cache."
cache:
key: binaries-cache-$CI_COMMIT_REF_SLUG
paths:
- binaries/
# valid cache:key:files
cache-key-files:
script: echo "This job uses a cache."
cache:
key:
files:
- Gemfile.lock
- package.json
paths:
- vendor/ruby
- node_modules
# valide cache:key:prefix
cache-key-prefix-string:
script: echo "This job uses a cache."
cache:
key:
files:
- Gemfile.lock
prefix: random-string
paths:
- binaries/
cache-key-prefix-predefined-variable:
script: echo "This job uses a cache."
cache:
key:
files:
- Gemfile.lock
prefix: $CI_JOB_NAME
paths:
- binaries/
cache-key-prefix-combination:
script: echo "This job uses a cache."
cache:
key:
files:
- Gemfile.lock
prefix: binaries-cache-$CI_JOB_NAME
paths:
- binaries/
# valid cache:untracked
cache-untracked-true:
script: test
cache:
untracked: true
cache-untracked-false:
script: test
cache:
untracked: false
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment