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

CI check which verifies that all the automatically generated files are up to date #3715

Merged
merged 7 commits into from
Sep 6, 2017
Merged
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
21 changes: 19 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ configgen: requirements .configgen
@echo
@echo "================== config gen ===================="
@echo
# Lint st2 components
echo "# Sample config which contains all the available options which the corresponding descriptions" > conf/st2.conf.sample;
echo "# Note: This file is automatically generated using tools/config_gen.py - DO NOT UPDATE MANUALLY" >> conf/st2.conf.sample
echo "" >> conf/st2.conf.sample
Expand Down Expand Up @@ -450,7 +449,7 @@ debs:
ci: ci-checks ci-unit ci-integration ci-mistral ci-packs-tests

.PHONY: ci-checks
ci-checks: compile .pylint .flake8 .bandit .st2client-dependencies-check .st2common-circular-dependencies-check circle-lint-api-spec .rst-check
ci-checks: compile .generated-files-check .pylint .flake8 .bandit .st2client-dependencies-check .st2common-circular-dependencies-check circle-lint-api-spec .rst-check

.PHONY: .rst-check
.rst-check:
Expand All @@ -459,6 +458,24 @@ ci-checks: compile .pylint .flake8 .bandit .st2client-dependencies-check .st2com
@echo
. $(VIRTUALENV_DIR)/bin/activate; rstcheck --report warning CHANGELOG.rst

.PHONY: .generated-files-check
.generated-files-check:
# Verify that all the files which are automatically generated have indeed been re-generated and
# committed
@echo "==================== generated-files-check ===================="

# 1. Sample config - conf/st2.conf.sample
cp conf/st2.conf.sample /tmp/st2.conf.sample.upstream
make .configgen
diff conf/st2.conf.sample /tmp/st2.conf.sample.upstream || (echo "conf/st2.conf.sample hasn't been re-generated and committed. Please run \"make configgen\" and include and commit the generated file." && exit 1)
# 2. OpenAPI definition file - st2common/st2common/openapi.yaml (generated from
# st2common/st2common/openapi.yaml.j2)
cp st2common/st2common/openapi.yaml /tmp/openapi.yaml.upstream
make .generate-api-spec
diff st2common/st2common/openapi.yaml /tmp/openapi.yaml.upstream || (echo "st2common/st2common/openapi.yaml hasn't been re-generated and committed. Please run \"make generate-api-spec\" and include and commit the generated file." && exit 1)

@echo "All automatically generated files are up to date."

.PHONY: ci-unit
ci-unit: .unit-tests-coverage-html

Expand Down
2 changes: 1 addition & 1 deletion conf/st2.conf.sample
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ key = /etc/apache2/ssl/mycert.key
use_ssl = False
# Port on which the service should listen on.
port = 9100
# Authentication backend to use in a standalone mode. Available backends: flat_file, ldap.
# Authentication backend to use in a standalone mode. Available backends: flat_file.
backend = flat_file

[cloudslang]
Expand Down
25 changes: 21 additions & 4 deletions tools/config_gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,18 @@
]
}

# Some of the config values change depenending on the environment where this script is ran so we
# set them to static values to ensure consistent and stable output
STATIC_OPTION_VALUES = {
'actionrunner': {
'virtualenv_binary': '/data/stanley/virtualenv/bin/virtualenv',
'python_binary': '/data/stanley/virtualenv/bin/python'
},
'webui': {
'webui_base_url': 'https://localhost'
}
}

COMMON_AUTH_OPTIONS_COMMENT = """
# Common option - options below apply in both scenarios - when auth service is running as a WSGI
# service (e.g. under Apache or Nginx) and when it's running in the standalone mode.
Expand Down Expand Up @@ -99,21 +111,21 @@ def _read_group(opt_group):
print('')
common_options = [option for option in all_options if option['opt'].name in
AUTH_OPTIONS['common']]
_print_options(options=common_options)
_print_options(opt_group=opt_group, options=common_options)

print('')
print(STANDALONE_AUTH_OPTIONS_COMMENT)
print('')
standalone_options = [option for option in all_options if option['opt'].name in
AUTH_OPTIONS['standalone']]
_print_options(options=standalone_options)
_print_options(opt_group=opt_group, options=standalone_options)

if len(common_options) + len(standalone_options) != len(all_options):
msg = ('Not all options are declared in AUTH_OPTIONS dict, please update it')
raise Exception(msg)
else:
options = all_options
_print_options(options=options)
_print_options(opt_group=opt_group, options=options)


def _read_groups(opt_groups):
Expand All @@ -124,10 +136,15 @@ def _read_groups(opt_groups):
print('')


def _print_options(options):
def _print_options(opt_group, options):
for opt in options:
opt = opt['opt']

# Special case for options which could change during this script run
static_option_value = STATIC_OPTION_VALUES.get(opt_group.name, {}).get(opt.name, None)
if static_option_value:
opt.default = static_option_value

# Special handling for list options
if isinstance(opt, cfg.ListOpt):
if opt.default:
Expand Down