Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(validation): use cuelang for schema constraints #233

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,15 @@
only_branch_master_parent_repo: &only_branch_master_parent_repo
- 'master@saltstack-formulas/template-formula'
# `stage`
stage_schema: &stage_schema 'schema'
stage_lint: &stage_lint 'lint'
stage_release: &stage_release 'release'
stage_test: &stage_test 'test'
# `image`
image_commitlint: &image_commitlint 'myii/ssf-commitlint:11'
image_cuelang: &image_cuelang
name: 'myii/ssf-cue:0.3.2' # instead of cuelang/cue
entrypoint: ['/bin/ash', '-c']
image_dindruby: &image_dindruby 'myii/ssf-dind-ruby:2.7.1-r3'
image_dindrubybionic: &image_dindrubybionic 'myii/ssf-dind-ruby-bionic:1_2.5.1'
image_precommit: &image_precommit
Expand Down Expand Up @@ -41,6 +45,7 @@
###############################################################################
stages:
- *stage_lint
- *stage_schema
- *stage_test
- *stage_release
variables:
Expand Down Expand Up @@ -100,6 +105,16 @@ rubocop:
script:
- 'rubocop -d -P -S --enable-pending-cops'

cue:
allow_failure: true
stage: *stage_schema
image: *image_cuelang
variables:
DIR: 'TEMPLATE/parameters'
RULES: 'schema.cue'
script:
- 'cue vet -v $(find ${DIR} -name "*.yaml") ${DIR}/${RULES} --schema "#Values"'

###############################################################################
# Define `test` template
###############################################################################
Expand Down
2 changes: 2 additions & 0 deletions .yamllint
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@ extends: 'default'
# 3. All YAML files under directory `node_modules/`, introduced during the Travis run
# 4. Any SLS files under directory `test/`, which are actually state files
# 5. Any YAML files under directory `.kitchen/`, introduced during local testing
# 6. `kitchen.vagrant.yml`, which contains Embedded Ruby (ERB) template syntax
ignore: |
.cache/
.git/
node_modules/
test/**/states/**/*.sls
.kitchen/
kitchen.vagrant.yml

yaml-files:
# Default settings
Expand Down
2 changes: 2 additions & 0 deletions CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
/Gemfile @saltstack-formulas/ssf
/Gemfile.lock @saltstack-formulas/ssf
/kitchen.yml @saltstack-formulas/ssf
/kitchen.vagrant.yml @saltstack-formulas/ssf
/kitchen.windows.yml @saltstack-formulas/ssf
/pre-commit_semantic-release.sh @saltstack-formulas/ssf
/release-rules.js @saltstack-formulas/ssf
/release.config.js @saltstack-formulas/ssf
Expand Down
61 changes: 61 additions & 0 deletions TEMPLATE/parameters/schema.cue
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// -*- coding: utf-8 -*-
// vim: ft=yaml

//
// Data Constaints - Example from Saltstack-formulas
//

#Schema: #Values

//
// Rule
//
#Optional: {
pkg?:
name?: string
rootgroup?: string
hide_output?: bool
dir_mode?: =~"^0?[124567]{3}$" // any mode of length 3, with 0 prefix optional
mode?: =~"^0?[124567]{3}$" // any mode of length 3, with 0 prefix optional
config?: string
service?: name?: string
subcomponent?: config?: string

// legacy
pip_pkg?: string
pkgs_add?: [...]
pips?: [...]

// Just here for testing
added_in_defaults?: string
winner?: string
...
}

//
// Schema Name
//
#Values: {
values?: {...#Optional}
}
values?: {...#Values} // Namespace


//
// Older schema
//
#TEMPLATE: {
TEMPLATE?: {...#Optional}
}
TEMPLATE?: {...#Optional}

Debian?: #Optional
Suse?: #Optional
Gentoo?: #Optional
Arch?: #Optional
Alpine?: #Optional
FreeBSD?: #Optional
OpenBSD?: #Optional
Solaris?: #Optional
Windows?: #Optional
MacOS?: #Optional