Skip to content

Commit

Permalink
v0.10.0 - overhaul stages and add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Justintime50 committed Mar 10, 2021
1 parent 8f6dab3 commit 2929b90
Show file tree
Hide file tree
Showing 10 changed files with 322 additions and 110 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
# CHANGELOG

## v0.10.0 (2021-03-10)

* Overhaul the `stages` modules, improved code readability and documentation
* Added unit tests for the `stages` module
* Various bug fixes

## v0.9.0 (2021-03-09)

* Overhauled the Pipeline/Webhook modules and removed lots of duplicate code
* Fixed a bug where the pipeline timer wouldn't account for startup time (closes #35)
* Added unit tests for the `pipelines` modules
* Added unit tests for the `pipelines` module
* Various other bug fixes

## v0.8.2 (2021-03-06)
Expand Down
3 changes: 2 additions & 1 deletion harvey/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from harvey.images import Image
from harvey.messages import Message
from harvey.pipelines import Pipeline
from harvey.stages import Stage
from harvey.stages import (BuildStage, DeployComposeStage, DeployStage,
TestStage)
from harvey.utils import Logs, Utils
from harvey.webhooks import Webhook
2 changes: 1 addition & 1 deletion harvey/globals.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class Global():
"""
DOCKER_VERSION = 'v1.41' # Docker API version
# TODO: Figure out how to sync this version number with the one in `setup.py`
HARVEY_VERSION = '0.9.0' # Harvey release
HARVEY_VERSION = '0.10.0' # Harvey release
PROJECTS_PATH = 'projects'
PROJECTS_LOG_PATH = 'logs/projects'
HARVEY_LOG_PATH = 'logs/harvey'
Expand Down
67 changes: 51 additions & 16 deletions harvey/pipelines.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
from harvey.git import Git
from harvey.globals import Global
from harvey.messages import Message
from harvey.stages import Stage
from harvey.stages import (BuildStage, DeployComposeStage, DeployStage,
TestStage)
from harvey.utils import Utils

SLACK = os.getenv('SLACK')
Expand All @@ -25,17 +26,28 @@ def initialize_pipeline(cls, webhook):
f'Harvey has started a `{config["pipeline"]}` pipeline for `{Global.repo_full_name(webhook)}`.'
)

preamble = f'Running Harvey v{Global.HARVEY_VERSION}\n{config["pipeline"].title()} Pipeline Started: {start_time}' # noqa
pipeline_id = f'Pipeline ID: {Global.repo_commit_id(webhook)}\n'
preamble = (
f'Running Harvey v{Global.HARVEY_VERSION}'
f'\n{config["pipeline"].title()} Pipeline Started: {start_time}'
)
pipeline_id = f'Pipeline ID: {Global.repo_commit_id(webhook)}'
print(preamble)
git_message = (f'New commit by: {Global.repo_commit_author(webhook)}.'
f'\nCommit made on repo: {Global.repo_full_name(webhook)}.')
git_message = (
f'New commit by: {Global.repo_commit_author(webhook)}.'
f'\nCommit made on repo: {Global.repo_full_name(webhook)}.'
)

git = Git.update_git_repo(webhook)

execution_time = f'Startup execution time: {datetime.now() - start_time}\n'
output = (f'{preamble}\n{pipeline_id}Configuration:\n{json.dumps(config, indent=4)}'
f'\n\n{git_message}\n{git}\n{execution_time}')
output = (
f'{preamble}'
f'\n{pipeline_id}'
f'\nConfiguration:\n{json.dumps(config, indent=4)}'
f'\n\n{git_message}'
f'\n{git}'
f'\n{execution_time}'
)
print(execution_time)

return config, output, start_time
Expand All @@ -58,7 +70,12 @@ def start_pipeline(cls, webhook, use_compose=False):
execution_time = f'Pipeline execution time: {end_time - start_time}'
pipeline_status = 'Pipeline succeeded!'

final_output = f'{webhook_output}\n{test}\n{execution_time}\n{pipeline_status}'
final_output = (
f'{webhook_output}'
f'\n{test}'
f'\n{execution_time}'
f'\n{pipeline_status}'
)
if pipeline in ['deploy', 'full']:
build, deploy, healthcheck = cls.deploy(webhook_config, webhook, webhook_output, start_time, use_compose) # noqa

Expand All @@ -68,7 +85,13 @@ def start_pipeline(cls, webhook, use_compose=False):
execution_time = f'Pipeline execution time: {end_time - start_time}'
pipeline_status = 'Pipeline succeeded!'

final_output = f'{webhook_output}\n{stage_output}\n{execution_time}\n{healthcheck_message}\n{pipeline_status}' # noqa
final_output = (
f'{webhook_output}'
f'\n{stage_output}'
f'\n{execution_time}'
f'\n{healthcheck_message}'
f'\n{pipeline_status}'
)

Utils.success(final_output, webhook)
else:
Expand Down Expand Up @@ -108,13 +131,18 @@ def open_project_config(cls, webhook):
def test(cls, config, webhook, output, start_time):
"""Run the test stage in a pipeline
"""
test = Stage.test(config, webhook, output)
test = TestStage.run(config, webhook, output)
if 'Error: the above command exited with code' in test:
# TODO: Ensure this works, it may be broken
end_time = datetime.now()
pipeline_status = 'Pipeline failed!'
execution_time = f'Pipeline execution time: {end_time - start_time}'
final_output = f'{output}\n{test}\n{execution_time}\n{pipeline_status}'
final_output = (
f'{output}'
f'\n{test}'
f'\n{execution_time}'
f'\n{pipeline_status}'
)
Utils.kill(final_output, webhook)

return test
Expand All @@ -125,20 +153,27 @@ def deploy(cls, config, webhook, output, start_time, use_compose):
"""
if use_compose:
build = '' # When using compose, there is no build step
deploy = Stage.build_deploy_compose(config, webhook, output)
deploy = DeployComposeStage.run(config, webhook, output)
# healthcheck = Stage.run_container_healthcheck(webhook) # TODO: Correct healthchecks for compose
healthcheck = True
else:
build = Stage.build(config, webhook, output)
deploy = Stage.deploy(webhook, output)
healthcheck = Stage.run_container_healthcheck(webhook)
build = BuildStage.run(config, webhook, output)
deploy = DeployStage.run(webhook, output)
healthcheck = DeployStage.run_container_healthcheck(webhook)

if healthcheck is False:
end_time = datetime.now()
pipeline_status = 'Pipeline failed due to a bad healthcheck.'
execution_time = f'Pipeline execution time: {end_time - start_time}'
healthcheck_message = f'Project passed healthcheck: {healthcheck}'
final_output = f'{output}\n{build}\n{deploy}\n{execution_time}\n{healthcheck_message}\n{pipeline_status}'
final_output = (
f'{output}'
f'\n{build}'
f'\n{deploy}'
f'\n{execution_time}'
f'\n{healthcheck_message}'
f'\n{pipeline_status}'
)
Utils.kill(final_output, webhook)

return build, deploy, healthcheck
Loading

0 comments on commit 2929b90

Please sign in to comment.