-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
706 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
repos: | ||
- repo: https://github.com/pre-commit/mirrors-isort | ||
rev: v4.3.21 | ||
hooks: | ||
- id: isort | ||
language_version: python3.7 | ||
entry: isort | ||
- repo: https://github.com/psf/black | ||
rev: 19.10b0 | ||
hooks: | ||
- id: black | ||
name: black | ||
language_version: python3.7 | ||
entry: black | ||
- repo: https://gitlab.com/pycqa/flake8 | ||
rev: 3.7.9 | ||
hooks: | ||
- id: flake8 | ||
language_version: python3.7 | ||
name: flake8 | ||
entry: flake8 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
Changelog | ||
--------- | ||
|
||
0.1.0 (2020-03-30) | ||
.................. | ||
* Move internal ANNA project to open source (#1) by @pilosus |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
include version.py | ||
include README.rst | ||
include LICENSE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
.DEFAULT_GOAL := lint | ||
|
||
# Get variables from ENV | ||
TWINE_USERNAME := ${TWINE_USERNAME} | ||
TWINE_PASSWORD := ${TWINE_PASSWORD} | ||
TWINE_REPOSITORY_URL := ${TWINE_REPOSITORY_URL} | ||
|
||
# If .env file is found, assign variables from this source (overriding existing) | ||
ifneq (,$(wildcard .env)) | ||
$(info FOUND .env File.) | ||
include .env | ||
endif | ||
|
||
|
||
REQUIREMENTS="requirements-dev.txt" | ||
REQUIREMENTS27="requirements-dev-py27.txt" | ||
PROJECT="workflow_tools" | ||
|
||
isort = isort --recursive --check-only ${PROJECT} | ||
black = black --check ${PROJECT} | ||
flake8 = flake8 ${PROJECT} | ||
pytest = pytest tests -vvs --cov=${PROJECT} | ||
|
||
ifeq ($(PYTHON_VERSION),2.7) | ||
install_deps = pip install -U -r ${REQUIREMENTS27} | ||
black = @echo "Skip black for Python 2.7" | ||
else | ||
install_deps = pip install -U -r ${REQUIREMENTS} | ||
black = black --check ${PROJECT} | ||
endif | ||
|
||
install: | ||
@echo "Install package and its dependencies" | ||
$(install_deps) | ||
pip install -e . | ||
@echo "Done" | ||
|
||
uninstall: | ||
@echo "Unintsll package" | ||
@pip uninstall ${PROJECT} -y | ||
@echo "Done" | ||
|
||
lint: | ||
@echo "Run linters" | ||
$(isort) | ||
$(black) | ||
$(flake8) | ||
@echo "Done" | ||
|
||
test: | ||
@echo "Run tests" | ||
$(pytest) | ||
@echo "Done" | ||
|
||
|
||
build: | ||
@echo "Build Python package" | ||
python setup.py sdist bdist_wheel | ||
twine upload dist/* | ||
@echo "Done" | ||
|
||
|
||
clean: | ||
@echo "Clean up files" | ||
rm -rf `find . -name __pycache__` | ||
rm -f `find . -type f -name '*.py[co]' ` | ||
rm -f `find . -type f -name '*~' ` | ||
rm -f `find . -type f -name '.*~' ` | ||
rm -rf .cache | ||
rm -rf .pytest_cache | ||
rm -rf .mypy_cache | ||
rm -rf htmlcov | ||
rm -rf *.egg-info | ||
rm -f .coverage | ||
rm -f .coverage.* | ||
rm -rf build | ||
rm -rf dist | ||
python setup.py clean | ||
@echo "Done" | ||
|
||
.PHONY: install uninstall lint test build clean |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,33 @@ | ||
workflow-tools | ||
============== | ||
|
||
CLI tools for GitHub Actions. | ||
|
||
Use to automate your GitHub-based microservices. | ||
Generate your workflows and set secrets to GitHub repositories using command line tools. | ||
|
||
The tools include: | ||
|
||
- ``workflow_secret`` for GitHub secrets | ||
- ``workflow_generator`` for GitHub workflow generation | ||
|
||
|
||
Installation | ||
------------ | ||
|
||
Just run: | ||
|
||
.. code-block:: bash | ||
pip install -U workflow-tools | ||
Help | ||
---- | ||
|
||
Each tool provides help: | ||
|
||
.. code-block:: bash | ||
$ workflow_secret --help | ||
$ workflow_generator --help |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[tool.black] | ||
line-length = 120 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
pytest==4.6.9 | ||
pytest-cov==2.5.1 | ||
flake8==3.7.9 | ||
isort==4.3.21 | ||
mock==3.0.5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
pre-commit==1.21.0 | ||
pytest==5.0.1 | ||
pytest-cov==2.5.1 | ||
flake8==3.7.9 | ||
black==19.10b0 | ||
isort==4.3.21 | ||
twine==3.1.1 | ||
wheel==0.34.2 | ||
setuptools |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
[flake8] | ||
exclude = .git,__pycache__,old,build,dist,env/ | ||
max-line-length = 120 | ||
max-complexity = 15 | ||
ignore = C901,C812,E203 | ||
extend-ignore = W503 | ||
|
||
[mypy] | ||
python_version = 3.8 | ||
ignore_missing_imports = True | ||
disallow_incomplete_defs = True | ||
no_implicit_optional = True | ||
disallow_untyped_calls = True | ||
warn_redundant_casts = True | ||
warn_unused_ignores = True | ||
disallow_untyped_defs = True | ||
check_untyped_defs = True | ||
|
||
[isort] | ||
combine_as_imports = true | ||
default_section = THIRDPARTY | ||
include_trailing_comma = true | ||
known_first_party = workflow_tools | ||
line_length = 120 | ||
multi_line_output = 3 | ||
not_skip = __init__.py | ||
|
||
[tool:pytest] | ||
norecursedirs = .git .venv | ||
python_files = tests.py test_*.py *_tests.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import os | ||
|
||
from setuptools import find_packages, setup | ||
|
||
BASE_DIR = os.path.dirname(os.path.realpath(__file__)) | ||
|
||
|
||
def readme(): | ||
long_description = "" | ||
with open(os.path.join(BASE_DIR, "README.rst")) as f: | ||
long_description += f.read() | ||
|
||
long_description += "\n\n" | ||
with open(os.path.join(BASE_DIR, "CHANGELOG.rst")) as f: | ||
long_description += f.read() | ||
|
||
return long_description | ||
|
||
|
||
def get_version(): | ||
version = {} | ||
with open("version.py") as fp: | ||
exec(fp.read(), version) | ||
return version["__version__"] | ||
|
||
|
||
setup( | ||
name="workflow_tools", | ||
description="CLI tools for GitHub Actions", | ||
long_description=readme(), | ||
long_description_content_type="text/x-rst", | ||
classifiers=[ | ||
"Development Status :: 4 - Beta", | ||
"Programming Language :: Python", | ||
"Intended Audience :: Developers", | ||
"Intended Audience :: Information Technology", | ||
"Intended Audience :: System Administrators", | ||
"License :: OSI Approved :: Apache Software License", | ||
"Operating System :: Unix", | ||
"Operating System :: POSIX :: Linux", | ||
"Environment :: Console", | ||
"Environment :: MacOS X", | ||
"Topic :: Internet", | ||
], | ||
author="Absolutely No Nonsense Admin Ltd.", | ||
author_email="hello@anna.money", | ||
url="https://github.com/anna-money/workflow-tools", | ||
license="Apache License 2.0", | ||
version=get_version(), | ||
python_requires=">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, <4", | ||
zip_safe=True, | ||
include_package_data=True, | ||
packages=find_packages(exclude=["tests"]), | ||
install_requires=["Jinja2>=2.11.1", "Click>=7.0,<8.0", "PyNaCl>=1.3.0,<2.0", "requests>=2.22.0,<3.0"], | ||
entry_points={ | ||
"console_scripts": [ | ||
"workflow_generator = workflow_tools.cli:generator", | ||
"workflow_secret = workflow_tools.cli:secret", | ||
] | ||
}, | ||
) |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import sys | ||
|
||
import pytest | ||
|
||
from workflow_tools.template import ( | ||
_string_to_dict, | ||
env_to_namespace, | ||
get_secrets_from_template, | ||
get_user_variables_from_template, | ||
) | ||
|
||
if sys.version_info < (3, 3): | ||
from mock import patch | ||
else: | ||
from unittest.mock import patch | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"input_string, expected_result", | ||
[("hello=world\ntest=me", {"hello": "world", "test": "me"}), ("test me", {}), ("", {})], | ||
) | ||
def test_string_to_dict(input_string, expected_result): | ||
actual_result = _string_to_dict(input_string) | ||
assert actual_result == expected_result | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"rendered_template, prefix, expected_result", | ||
[ | ||
("something: [[ test.whatever ]]", "TEST", {"TEST_WHATEVER"}), | ||
("something: [[ test.whatever ]]", "TEST___", {"TEST_WHATEVER"}), | ||
("something: [[ test.whatever ]]", "WORKFLOW", set()), | ||
], | ||
) | ||
def test_get_user_variables_from_template(rendered_template, prefix, expected_result): | ||
actual_result = get_user_variables_from_template(rendered_template, prefix) | ||
assert actual_result == expected_result | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"rendered_template, expected_result", | ||
[ | ||
("something: ${{ secrets.whatever }}", {"whatever"}), | ||
("something: {{ secrets.whatever }}", set()), | ||
("something: [[ test.whatever ]]", set()), | ||
], | ||
) | ||
def test_get_secrets_from_template(rendered_template, expected_result): | ||
actual_result = get_secrets_from_template(rendered_template) | ||
assert actual_result == expected_result | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"prefix, environ, expected_result", | ||
[ | ||
("WORKFLOW_TEST", {"WORKFLOW_TEST_SOMETHING": "me"}, {"something": "me"}), | ||
("ANOTHER_PREFIX", {"WORKFLOW_TEST_SOMETHING": "me"}, {}), | ||
("ANOTHER_PREFIX", {}, {}), | ||
], | ||
) | ||
def test_env_to_namespace(prefix, environ, expected_result): | ||
with patch.dict("workflow_tools.template.os.environ", values=environ): | ||
actual_result = env_to_namespace(prefix=prefix) | ||
assert actual_result == expected_result |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# This file will be re-generated by CI/CD | ||
__version__ = "0.1.0" |
Empty file.
Oops, something went wrong.