2020-11-07 00:12:41 -08:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
2021-02-15 00:38:10 -08:00
|
|
|
# Copyright 2021 Google LLC
|
2020-11-07 00:12:41 -08:00
|
|
|
#
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
# you may not use this file except in compliance with the License.
|
|
|
|
# You may obtain a copy of the License at
|
|
|
|
#
|
|
|
|
# https://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
#
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
# See the License for the specific language governing permissions and
|
|
|
|
# limitations under the License.
|
|
|
|
|
|
|
|
import enum
|
|
|
|
import pathlib
|
|
|
|
|
|
|
|
import click
|
|
|
|
import tfdoc
|
|
|
|
|
|
|
|
|
2021-12-20 23:51:51 -08:00
|
|
|
BASEDIR = pathlib.Path(__file__).resolve().parents[1]
|
2020-11-07 00:12:41 -08:00
|
|
|
|
2021-10-08 09:26:04 -07:00
|
|
|
|
2021-12-20 23:51:51 -08:00
|
|
|
State = enum.Enum('State', 'OK FAIL SKIP')
|
2021-10-08 09:26:04 -07:00
|
|
|
|
|
|
|
|
2021-12-22 06:35:12 -08:00
|
|
|
def _check_dir(dir_name, files=False, show_extra=False):
|
2021-12-20 23:51:51 -08:00
|
|
|
dir_path = BASEDIR / dir_name
|
|
|
|
for readme_path in dir_path.glob('**/README.md'):
|
2021-12-22 06:35:12 -08:00
|
|
|
if '.terraform' in str(readme_path):
|
|
|
|
continue
|
2021-12-20 23:51:51 -08:00
|
|
|
readme = readme_path.read_text()
|
|
|
|
mod_name = str(readme_path.relative_to(dir_path).parent)
|
|
|
|
result = tfdoc.get_doc(readme)
|
|
|
|
if not result:
|
|
|
|
state = State.SKIP
|
2020-11-07 00:12:41 -08:00
|
|
|
else:
|
2021-12-20 23:51:51 -08:00
|
|
|
try:
|
2021-12-22 06:35:12 -08:00
|
|
|
new_doc = tfdoc.create_doc(
|
|
|
|
readme_path.parent, files=files, show_extra=show_extra)
|
2021-12-20 23:51:51 -08:00
|
|
|
except SystemExit:
|
|
|
|
state = state.SKIP
|
|
|
|
else:
|
|
|
|
state = State.OK if new_doc == result['doc'] else State.FAIL
|
|
|
|
yield mod_name, state
|
2020-11-07 00:12:41 -08:00
|
|
|
|
|
|
|
|
|
|
|
@click.command()
|
2021-12-20 23:51:51 -08:00
|
|
|
@click.argument('dirs', type=str, nargs=-1)
|
2021-12-22 06:35:12 -08:00
|
|
|
@ click.option('--show-extra/--no-show-extra', default=False)
|
|
|
|
@ click.option('--files/--no-files', default=False)
|
|
|
|
def main(dirs, files=False, show_extra=False):
|
2021-12-20 23:51:51 -08:00
|
|
|
'Cycle through modules and ensure READMEs are up-to-date.'
|
2021-12-22 06:35:12 -08:00
|
|
|
errors = 0
|
2021-12-20 23:51:51 -08:00
|
|
|
state_labels = {State.FAIL: '✗', State.OK: '✓', State.SKIP: '?'}
|
|
|
|
for dir_name in dirs:
|
|
|
|
print(f'----- {dir_name} -----')
|
2021-12-22 06:44:43 -08:00
|
|
|
for mod_name, state in _check_dir(dir_name, files, show_extra):
|
2021-12-22 06:35:12 -08:00
|
|
|
errors += 1 if state == State.FAIL else 0
|
2021-12-20 23:51:51 -08:00
|
|
|
print(f'[{state_labels[state]}] {mod_name}')
|
2021-12-22 06:35:12 -08:00
|
|
|
if errors:
|
|
|
|
raise SystemExit('Errors found.')
|
2020-11-07 00:12:41 -08:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|