Commit 55445696 authored by constrict0r's avatar constrict0r 💬

Udpates docthis, testme and parts components

parent 1c37457d
Pipeline #115046180 passed with stage
in 37 minutes and 11 seconds
......@@ -110,7 +110,7 @@ when writing configuration files, be sure to use the **item_path** and
<https://github.com/constrict0r/constructor#item_expand>`_).
For more information see: `constructor role
<https://github.com/constrict0r/constructor>`_.
<https://gitlab.com/constrict0r/constructor>`_.
Usage
......@@ -146,8 +146,8 @@ The following parameters are supported:
configuration
=============
* **-c** (configuration path): Absolute path to a .yml file
containing some or all of the following configuration:
* *-c* (configuration path): Absolute path to a .yml file containing
some or all of the following configuration:
..
......@@ -160,7 +160,7 @@ configuration
* A list of packages to install via Apt (see
*constrict0r.aptitude* role).
* A list of packages to install via npm (see *constrict0r.jsnode*
* A list of packages to install via yarn (see *constrict0r.jsnode*
role).
* A list of packages to install via pip (see *constrict0r.pyp*
......@@ -198,7 +198,7 @@ configuration
desktop
=======
* **-d** (desktop): If present, install and execute the
* *-d* (desktop): If present, install and execute the
*constrict0r.desktop* ansible role which fully setups Debian (or a
Debian-like system).
......@@ -244,8 +244,8 @@ If this variable is not specified, the current username will be used.
extra-role-variables
====================
* **-v** (extra-role variables): The variable keys and values stored
on this variable are passed to the extra role (**-x**) if it is
* *-v* (extra-role variables): The variable keys and values stored on
this variable are passed to the extra role (**-x**) if it is
defined.
..
......@@ -271,7 +271,7 @@ password
extra-role
==========
* **-x** (extra-role): If present, install and execute the specified
* *-x* (extra-role): If present, install and execute the specified
ansible role after the main setup process has finished.
..
......@@ -388,7 +388,7 @@ Author
.. image:: https://gitlab.com/constrict0r/img/raw/master/kick/author.png
:alt: author
The travelling vaudeville villain.
The Travelling Vaudeville Villain.
Enjoy!!!
......@@ -473,7 +473,7 @@ Globals
* A list of packages to install via apt.
* A list of packages to install via npm.
* A list of packages to install via yarn.
* A list of packages to install via pip.
......
......@@ -44,7 +44,7 @@ Globals
Absolute file path to a yml file containing:
- A list of apt repositories to add.
- A list of packages to install via apt.
- A list of packages to install via npm.
- A list of packages to install via yarn.
- A list of packages to install via pip.
- An URL to a skeleton git repository to copy to /.
- A list of services to enable and restart.
......
......@@ -32,7 +32,7 @@ img_base_url = "https://gitlab.com/" + author + "/img/raw/master/"
img_url = img_base_url + project + "/"
author_img = ".. image:: " + img_url + "author.png\n :alt: author"
author_slogan = "The travelling vaudeville villain."
author_slogan = "The Travelling Vaudeville Villain."
github_base_url = "https://github.com/"
github_url = github_base_url + author + "/" + project
......
......@@ -40,4 +40,4 @@ writing configuration files, be sure to use the **item_path** and
`expand attribute <https://github.com/constrict0r/constructor#item_expand>`_).
For more information see:
`constructor role <https://github.com/constrict0r/constructor>`_.
`constructor role <https://gitlab.com/constrict0r/constructor>`_.
- **-c** (configuration path): Absolute path to a .yml file containing some or
- *-c* (configuration path): Absolute path to a .yml file containing some or
all of the following configuration:
- A list of apt repositories to add (see *constrict0r.sourcez* role).
......@@ -7,7 +7,7 @@
- A list of packages to install via Apt (see *constrict0r.aptitude* role).
- A list of packages to install via npm (see *constrict0r.jsnode* role).
- A list of packages to install via yarn (see *constrict0r.jsnode* role).
- A list of packages to install via pip (see *constrict0r.pyp* role).
......
- **-d** (desktop): If present, install and execute the *constrict0r.desktop*
- *-d* (desktop): If present, install and execute the *constrict0r.desktop*
ansible role which fully setups Debian (or a Debian-like system).
If the **-c** parameter is present this parameter is ignored.
......
- **-v** (extra-role variables): The variable keys and values stored on this
- *-v* (extra-role variables): The variable keys and values stored on this
variable are passed to the extra role (**-x**) if it is defined.
.. substitution-code-block:: bash
......
- **-x** (extra-role): If present, install and execute the specified ansible
- *-x* (extra-role): If present, install and execute the specified ansible
role after the main setup process has finished.
.. substitution-code-block:: bash
......
Subproject commit 6bfc073ce4360f14c4672f99893aada4aa8ab3c1
Subproject commit 310525cdc9eb0837017e756cab37cf09d8061707
......@@ -7,6 +7,9 @@
# specified the current path will be used.
PROJECT_PATH=$(pwd)
# Force to install the requirements or not.
INSTALL_REQUIREMENTS=false
# requirements.txt file contents.
REQUIREMENTS_PIP='sphinxcontrib-restbuilder
sphinxcontrib-globalsubs
......@@ -50,7 +53,7 @@ img_base_url = "https://raw.githubusercontent.com/"
img_url = img_base_url + author + "/" + project + "/master/img/"
author_img = ".. image:: " + img_url + "/author.png\\n :alt: author"
author_slogan = "The travelling vaudeville villain."
author_slogan = "The Travelling Vaudeville Villain."
github_base_url = "https://github.com/"
github_url = github_base_url + author + "/" + project
......@@ -71,7 +74,7 @@ travis_link = "`Travis CI <" + travis_url + ">`_."
readthedocs_url = "https://" + project + ".readthedocs.io"
readthedocs_badge = "/projects/" + project + "/badge\\n :alt: readthedocs"
readthedocs_link = "`readthedocs <" + readthedocs_url + ">`_."
readthedocs_link = "`Readthedocs <" + readthedocs_url + ">`_."
gh_cover_base_url = "https://coveralls.io/repos/github/"
gh_cover_url = gh_cover_base_url + author + "/" + project + "/badge.svg"
......@@ -94,7 +97,7 @@ global_substitutions = {
"READTHEDOCS_BADGE": ".. image:: https://rtfd.io" + readthedocs_badge,
"READTHEDOCS_LINK": readthedocs_link,
"TRAVIS_BADGE": travis_badge,
"TRAVIS_LINK": travis_link,
"TRAVIS_LINK": travis_link
}
substitutions = [
......@@ -121,7 +124,7 @@ submodules:
# index.rst file contents.
INDEX_CONTENTS="|PROJECT_GENERATED_NAME|
=============================================================================
============================================================================
|GITLAB_BADGE|
......@@ -144,7 +147,7 @@ Source code on:
|GITLAB_LINK|
Contents
=============================================================================
============================================================================
.. toctree::
......@@ -168,13 +171,13 @@ Contents
# description.rst file contents.
DESCRIPTION_CONTENTS='Description
-----------------------------------------------------------------------------
----------------------------------------------------------------------------
Describe me.'
# usage.rst file contents
USAGE_CONTENTS="Usage
-----------------------------------------------------------------------------
----------------------------------------------------------------------------
Download the script, give it execution permissions and execute it:
......@@ -186,7 +189,7 @@ Download the script, give it execution permissions and execute it:
# variables.rst file contents.
VARIABLES_CONTENTS="Variables
-----------------------------------------------------------------------------
----------------------------------------------------------------------------
The following variables are supported:
......@@ -204,13 +207,13 @@ The following variables are supported:
# requirements.rst file contents.
REQUIREMENTS_CONTENTS='Requirements
-----------------------------------------------------------------------------
----------------------------------------------------------------------------
- Python 3.'
# compatibility.rst file contents.
COMPATIBILITY_CONTENTS='Compatibility
-----------------------------------------------------------------------------
----------------------------------------------------------------------------
- Debian buster.
......@@ -226,7 +229,7 @@ MIT. See the LICENSE file for more details.'
# links.rst file contents.
LINKS_CONTENTS='Links
-----------------------------------------------------------------------------
----------------------------------------------------------------------------
- |GITHUB_LINK|
......@@ -238,7 +241,7 @@ LINKS_CONTENTS='Links
# author.rst file contents.
AUTHOR_CONTENTS='Author
-----------------------------------------------------------------------------
----------------------------------------------------------------------------
|AUTHOR_IMG|
......@@ -272,7 +275,8 @@ function escape() {
}
# @description Setup sphinx and generate html and rst documentation,
# generates a single README-single file that can be used on github or gitlab.
# generates a single README-single file that can be used on github
# or gitlab.
#
# @arg $1 string Optional project path. Default to current path.
# @arg $2 string Optional CI service to use for generating a coverage badge.
......@@ -349,20 +353,12 @@ function generate() {
sed -i -E "s/\|YEAR_GENERATED_VALUE\|/$project_year/g" $project_path/docs/source/*.*
fi
# Install requirements if not already installed.
local sphinx_requirements=$(python3 -m pip list --format=columns)
sphinx_requirements="${sphinx_requirements,,}"
sphinx_requirements="${sphinx_requirements//-/_}"
local current_line=''
install_requirements
while read LINE
do
current_line=$LINE
current_line="${current_line,,}"
current_line="${current_line//-/_}"
! [[ $sphinx_requirements == *"$current_line"* ]] && python3 -m pip install $LINE
done < $project_path/docs/requirements.txt
elif [[ "$INSTALL_REQUIREMENTS" == 'true' ]]; then
install_requirements
fi # New project?.
# Generate documentation.
......@@ -374,8 +370,9 @@ function generate() {
# @description Generate rst documentation using sphinx.
#
# This function will extract each filename to include from the index.rst file
# and concatenate all files into a single README-single.rst file.
# This function will extract each filename to include from the
# index.rst file and concatenate all files into a single
# README-single.rst file.
#
# This function assumes:
# - The project has a file structure as created by generate().
......@@ -408,8 +405,7 @@ function generate_rst() {
# When a line readed from the index.rst file is a menu item,
# this variable will be setted to true.
# This is a flag to indicate if we found the items to
# include on the resulting README file when reading the source index file.
# This is a flag to indicate if items to include were found.
local items_found=false
# Clean files first.
......@@ -619,6 +615,7 @@ function get_img_url() {
# Accepts:
#
# - *h* (help).
# - *i* (install requirements).
# - *p* <path> (project_path).
#
# @arg '[email protected]' string Bash arguments.
......@@ -628,10 +625,11 @@ function get_img_url() {
function get_parameters() {
# Obtain parameters.
while getopts 'h;p:' opt; do
while getopts 'h;i;p:' opt; do
OPTARG=$(sanitize "$OPTARG")
case "$opt" in
h) help && exit 0;;
i) INSTALL_REQUIREMENTS=true;;
p) PROJECT_PATH="${OPTARG}";;
esac
done
......@@ -822,15 +820,47 @@ function help() {
echo 'Uses Sphinx to generate html and rst documentation.'
echo 'Parameters:'
echo '-h (help): Show this help message.'
echo '-i (install requirements): Force install requirements.txt.'
echo '-p <file_path> (project path): Optional absolute file path to the
root directory of the project to generate documentation. If this
parameter is not espeficied, the current path will be used.'
root directory of the project to generate documentation. If
this parameter is not espeficied, the current path will be
used.'
echo 'Example:'
echo "./docthis.sh -p /home/username/my_project"
return 0
}
# @description Installs all the requirements.txt files.
#
# @arg $1 string Optional project path. Default to current path.
#
# @exitcode 0 If successful.
# @exitcode 1 On failure.
function install_requirements() {
local project_path=$(pwd)
[[ -d $1 ]] && project_path="$( cd "$1" ; pwd -P )"
# Install requirements if not already installed.
local sphinx_requirements=$(python3 -m pip list --format=columns)
sphinx_requirements="${sphinx_requirements,,}"
sphinx_requirements="${sphinx_requirements//-/_}"
local current_line=''
while read LINE
do
current_line=$LINE
current_line="${current_line,,}"
current_line="${current_line//-/_}"
if ! [[ $sphinx_requirements == *"$current_line"* ]]; then
python3 -m pip install $LINE
fi
done < $project_path/docs/requirements.txt
return 0
}
# @description Generate documentation using sphinx.
#
# @arg [email protected] string Bash arguments.
......
......@@ -33,7 +33,7 @@ PASSWORD='1234'
# Absolute file path to a yml file containing:
# - A list of apt repositories to add.
# - A list of packages to install via apt.
# - A list of packages to install via npm.
# - A list of packages to install via yarn.
# - A list of packages to install via pip.
# - An URL to a skeleton git repository to copy to /.
# - A list of services to enable and restart.
......@@ -202,7 +202,7 @@ function help() {
echo 'Parameters: '
echo '-c <file path> (configuration file path): Absolute path to a yml
file containing some of the following informations: list of apt
repos, list of apt packages, list of npm packages, list of pip
repos, list of apt packages, list of yarn packages, list of pip
packages, list of services, git urls, list of users, paths or
URLs Ansible taks files.'
echo '-d (desktop): Install and configure a desktop enviroment. If used -c
......
......@@ -4,6 +4,9 @@
# @brief Setup requirements and run tests, from root folder run: ./testme.sh.
# Default values.
# Become root password to pass to Ansible roles.
BECOME_PASS=''
# Wheter to generate or not a coverage report.
COVERAGE_REPORT=false
......@@ -149,6 +152,7 @@ function error_message() {
# - *c* (coverage report).
# - *h* (help).
# - *i* (install requirements).
# - *K* (become password for Ansible roles).
# - *o* <types> (only tests of type).
# - *p* <path> (project_path).
# - *r* (recursive).
......@@ -162,12 +166,13 @@ function error_message() {
function get_parameters() {
# Obtain parameters.
while getopts 'c;h;i;o:p:r;t;x:' opt; do
while getopts 'c;h;i;K:o:p:r;t;x:' opt; do
OPTARG=$(sanitize "$OPTARG")
case "$opt" in
c) COVERAGE_REPORT=true;;
h) help && exit 0;;
i) REQUIREMENTS_INSTALL=true;;
K) BECOME_PASS="${OPTARG}";;
o) ONLY_TYPE="${OPTARG}";;
p) PROJECT_PATH="${OPTARG}";;
r) RECURSIVE=true;;
......@@ -193,6 +198,7 @@ function help() {
echo '-h (help): Show this help message.'
echo '-i (install requirements): When present all found requirements.txt
files are installed.'
echo '-K (become pass): Plain text sudo password (for Ansible roles).'
echo '-o <only type> (type string): Optional string containing any of the
following characters: a, b, m, p. Each one indicating to only
execute a specific type of tests, being a = ansible, b = bats,
......@@ -222,10 +228,10 @@ function help() {
#
# @stdout Prints the created parameters string.
function create_recursive_parameters_string() {
local become_pass_regex='-K (.*)'
local python_exec_regex='-x (python[0-9]*)'
local only_type_regex='-o ([abmp])+'
local parameters_string=''
local parameters_string=''
[[ "[email protected]" == *'-c'* ]] && parameters_string+='-c '
[[ "[email protected]" == *'-i'* ]] && parameters_string+='-i '
......@@ -235,10 +241,15 @@ function create_recursive_parameters_string() {
fi
[[ "[email protected]" == *'-t'* ]] && parameters_string+='-t '
if [[ [email protected] =~ $python_exec_regex ]]; then
parameters_string+="-x ${BASH_REMATCH[1]} "
fi
if [[ [email protected] =~ $become_pass_regex ]]; then
parameters_string+="-K $(sanitize ${BASH_REMATCH[1]})"
fi
echo "${parameters_string}"
return 0
......@@ -311,7 +322,7 @@ function main() {
# Run ansible tests.
if [[ -z $ONLY_TYPE ]] || [[ $ONLY_TYPE == *'a'* ]]; then
tests_ansible "$PROJECT_PATH"
tests_ansible "$PROJECT_PATH" "$BECOME_PASS"
[ $? -eq 1 ] && error_message 'ansible'
fi
......@@ -359,7 +370,7 @@ function molecule_tests_exists() {
[[ -d $1 ]] && project_path="$( cd "$1" ; pwd -P )"
# Search for molecule tests.
! [[ -d $project_path/molecule ]] && echo false && return 0
! [[ -d "$project_path/molecule" ]] && echo false && return 0
local pip_list=$($python_exec -m pip list)
......@@ -608,6 +619,7 @@ _\\;_\\//__________________| |________| |_| |_________| |_| -------|
# @description Execute ansible tests.
#
# @arg $1 string Optional project path. Default to current path.
# @arg $2 string Optional become password.
#
# @exitcode 0 if successful.
# @exitcode 1 on failure.
......@@ -623,6 +635,9 @@ function tests_ansible() {
! [[ -d $project_path/tests ]] && return 0
local become_parameter=''
! [[ -z $2 ]] && become_parameter="ansible_become_pass: '$2', "
if [[ $(ansible_tests_exists "$PROJECT_PATH") == true ]]; then
[[ $(validate 'ansible') == false ]] && return 1
fi
......@@ -643,8 +658,11 @@ function tests_ansible() {
echo 'localhost' > $project_path/tests/inventory
fi
ansible-playbook -i $project_path/tests/inventory $playbook \
-e "ansible_python_interpreter=/usr/bin/$python_exec"
ansible-playbook -i $project_path/tests/inventory $playbook -e \
"{${ansible_become_pass}ansible_python_interpreter: '/usr/bin/$python_exec'}"
# Clear history for security.
history -c
done
return 0
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment