Skip to content

Commit 5d646db

Browse files
authored
Merge pull request #427 from DannyBen/add/arbitrary-config-values
Allow arbitrary (`x-anything`) keys in bashly.yml
2 parents 13643ae + 4628b2c commit 5d646db

File tree

5 files changed

+101
-33
lines changed

5 files changed

+101
-33
lines changed

.github/workflows/test.yml

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,5 @@ jobs:
116116
- name: Generate all subjects
117117
run: bundle exec run examples regen
118118

119-
- name: Run bashly schema tests
120-
run: bundle exec run schema examples
121-
122-
- name: Run settings schema tests
123-
run: bundle exec run schema settings
124-
125-
- name: Run strings schema tests
126-
run: bundle exec run schema strings
119+
- name: Run schema tests
120+
run: bundle exec run schema all

lib/bashly/concerns/validation_helpers.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ def assert_hash(key, value, keys: nil)
4141
return unless keys
4242

4343
invalid_keys = value.keys.map(&:to_sym) - keys
44+
invalid_keys.reject! { |key| key.start_with? 'x-' }
4445
assert invalid_keys.empty?, "#{key} contains invalid options: #{invalid_keys.join ', '}"
4546
end
4647

schemas/bashly.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
11
{
22
"$schema": "http://json-schema.org/draft-07/schema",
33
"definitions": {
4+
"custom-properties": {
5+
"patternProperties": {
6+
"^x-.": {
7+
"title": "custom property",
8+
"description": "A custom property of any type",
9+
"examples": [
10+
"This command shows the status of all `images`, `containers` and `volumes`. Use with `--verbose` to see deleted containers."
11+
]
12+
}
13+
}
14+
},
415
"argument": {
516
"title": "argument",
617
"description": "A positional argument of the current script or sub-command\nhttps://bashly.dannyb.co/configuration/argument/",
@@ -74,6 +85,7 @@
7485
]
7586
}
7687
},
88+
"$ref": "#/definitions/custom-properties",
7789
"additionalProperties": false
7890
},
7991
"flag": {
@@ -209,6 +221,7 @@
209221
]
210222
}
211223
},
224+
"$ref": "#/definitions/custom-properties",
212225
"additionalProperties": false
213226
},
214227
"name-property": {
@@ -405,6 +418,7 @@
405418
"$ref": "#/definitions/environment-variables-required-property"
406419
}
407420
},
421+
"$ref": "#/definitions/custom-properties",
408422
"additionalProperties": false
409423
},
410424
"else": {
@@ -422,6 +436,7 @@
422436
"$ref": "#/definitions/environment-variables-required-property"
423437
}
424438
},
439+
"$ref": "#/definitions/custom-properties",
425440
"additionalProperties": false
426441
}
427442
}
@@ -779,6 +794,7 @@
779794
"$ref": "#/definitions/sub-command-import-property"
780795
}
781796
},
797+
"$ref": "#/definitions/custom-properties",
782798
"additionalProperties": false
783799
}
784800
},
@@ -835,5 +851,6 @@
835851
"$ref": "#/definitions/function-property"
836852
}
837853
},
854+
"$ref": "#/definitions/custom-properties",
838855
"additionalProperties": false
839856
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: docker
2+
x-string: hello
3+
x-hash: { key: value }
4+
x-array: [1, 2]
5+
x-int: 1
6+
x-float: 1.2
7+
x-boolean: yes
8+
x-nil: ~
9+
10+
environment_variables:
11+
- name: rush_config
12+
x-any: hello
13+
14+
commands:
15+
- name: status
16+
x-any: hello
17+
18+
args:
19+
- name: repo
20+
x-any: hello
21+
22+
flags:
23+
- long: --purge
24+
x-any: hello
25+
26+
- name: images
27+
commands:
28+
- name: ls
29+
x-any: hello

support/runfile/schema.runfile

Lines changed: 52 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,57 @@
11
summary 'Run json-schema checks on all examples'
22

3-
help 'Test the bashly schema against all examples'
4-
action :examples do
5-
Example.all.each do |example|
6-
file = example.yaml_path
7-
command = "check-jsonschema --schemafile schemas/bashly.json #{file}"
8-
say "\n$ check-jsonschema bb`#{example.dir}`"
9-
success = system command
10-
abort 'Failed' unless success
11-
end
3+
help 'Run all the actions in this runfile'
4+
action :all do
5+
check_examples
6+
check_settings
7+
check_strings
8+
check_arbitrary
129
end
1310

14-
help 'Test the settings schema against the default settings template'
15-
action :settings do
16-
file = 'lib/bashly/libraries/settings/settings.yml'
17-
command = "check-jsonschema --schemafile schemas/settings.json #{file}"
18-
say "\n$ check-jsonschema bb`#{file}`"
19-
success = system command
20-
abort 'Failed' unless success
21-
end
11+
help 'Test the bashly schema against all examples'
12+
action(:examples) { check_examples }
2213

23-
help 'Test the strings schema against the default strings template'
24-
action :strings do
25-
file = 'lib/bashly/libraries/strings/strings.yml'
26-
command = "check-jsonschema --schemafile schemas/strings.json #{file}"
27-
say "\n$ check-jsonschema bb`#{file}`"
28-
success = system command
29-
abort 'Failed' unless success
30-
end
14+
help 'Test the settings schema against the default settings template'
15+
action(:settings) { check_settings }
16+
17+
help 'Test the strings schema against the default strings template'
18+
action(:strings) { check_strings }
19+
20+
help 'Test the bashly schema against a bashly configuration that includes arbitrary (x-) keys'
21+
action(:arbitrary) { check_arbitrary }
22+
23+
helpers do
24+
def check_examples
25+
say "\ngub`Examples`"
26+
Example.all.each do |example|
27+
file = example.yaml_path
28+
schema_check file
29+
end
30+
end
31+
32+
def check_settings
33+
say "\ngub`Settings`"
34+
file = 'lib/bashly/libraries/settings/settings.yml'
35+
schema_check file, :settings
36+
end
37+
38+
def check_strings
39+
say "\ngub`Strings`"
40+
file = 'lib/bashly/libraries/strings/strings.yml'
41+
schema_check file, :strings
42+
end
43+
44+
def check_arbitrary
45+
say "\ngub`Arbitrary`"
46+
file = 'spec/fixtures/script/x-arbitrary.yml'
47+
schema_check file
48+
end
49+
50+
def schema_check(file, schema = 'bashly')
51+
command = "check-jsonschema --schemafile schemas/#{schema}.json #{file}"
52+
say "\nnb`$ check-jsonschema` [m`#{schema}`] bb`#{file}`"
53+
success = system command
54+
55+
abort 'Failed' unless success
56+
end
57+
end

0 commit comments

Comments
 (0)