diff --git a/action.py b/action.py index 7ae26dd..0314be0 100755 --- a/action.py +++ b/action.py @@ -117,15 +117,18 @@ def create_zip() -> bytes: archive.writestr( "docker-compose.yml", docker_compose_path.read_text().replace( - "${IMAGE_TAG}", version_label, + "${IMAGE_TAG}", + version_label, ), ) if platform_hooks_path is not None: for file in filter( - lambda path: path.is_file(), platform_hooks_path.glob("**/*"), + lambda path: path.is_file(), + platform_hooks_path.glob("**/*"), ): archive.write( - file, arcname=file.relative_to(platform_hooks_path), + file, + arcname=file.relative_to(platform_hooks_path), ) logging.info("Deployment archive created") @@ -134,7 +137,9 @@ def create_zip() -> bytes: def upload_zip(content: bytes) -> DeploymentArchive: boto3.client("s3").put_object( - Bucket=bucket_name, Body=content, Key=bucket_key, + Bucket=bucket_name, + Body=content, + Key=bucket_key, ) logging.info( f"Deployment archive uploaded to s3://{bucket_name}/{bucket_key}", @@ -156,7 +161,9 @@ class ApplicationVersion: @classmethod def get( - cls, application: BeanstalkApplication, version_label: str, + cls, + application: BeanstalkApplication, + version_label: str, ) -> Optional[Self]: versions = boto3.client("elasticbeanstalk").describe_application_versions( ApplicationName=application.name, @@ -202,11 +209,7 @@ def wait_until_created(): step = 0 while step < polling_max_steps: application_version = cls.get(application, version_label) - status = ( - "UNAVAILABLE" - if application_version is None - else application_version.status - ) + status = "UNAVAILABLE" if application_version is None else application_version.status logging.info( f"Step {step + 1} of {polling_max_steps}. Status is {status}", @@ -319,9 +322,7 @@ def main(): description=os.environ["VERSION_DESCRIPTION"], docker_compose_path=Path(os.environ["DOCKER_COMPOSE_PATH"]), environment_name=os.environ["ENVIRONMENT_NAME"], - platform_hooks_path=Path(os.environ["PLATFORM_HOOKS_PATH"]) - if os.environ["PLATFORM_HOOKS_PATH"] - else None, + platform_hooks_path=Path(os.environ["PLATFORM_HOOKS_PATH"]) if os.environ["PLATFORM_HOOKS_PATH"] else None, region=get_region(), version_label=os.environ["VERSION_LABEL"], ) @@ -330,7 +331,8 @@ def main(): environment = BeanstalkEnvironment(application, config.environment_name) application_version = get_or_create_beanstalk_application_version( - application, config, + application, + config, ) application_version.deploy_to_environment(environment) diff --git a/test_action.py b/test_action.py index 13d3040..0ba8423 100644 --- a/test_action.py +++ b/test_action.py @@ -20,10 +20,13 @@ ) MOCK_APPLICATION = action.BeanstalkApplication(MOCK_CONFIG.application_name) MOCK_ENVIRONMENT = action.BeanstalkEnvironment( - MOCK_APPLICATION, MOCK_CONFIG.environment_name, + MOCK_APPLICATION, + MOCK_CONFIG.environment_name, ) MOCK_APPLICATION_VERSION = action.ApplicationVersion( - MOCK_APPLICATION, "version-0", "PROCESSED", + MOCK_APPLICATION, + "version-0", + "PROCESSED", ) MOCK_TIME = datetime.now(tz=UTC) @@ -31,7 +34,8 @@ class TestUtils(TestCase): def test_check_aws_credentials(self): with patch.dict( - os.environ, {"AWS_ACCESS_KEY_ID": "fake", "AWS_SECRET_ACCESS_KEY": "fake"}, + os.environ, + {"AWS_ACCESS_KEY_ID": "fake", "AWS_SECRET_ACCESS_KEY": "fake"}, ): action.check_aws_credentials() @@ -49,10 +53,12 @@ def test_get_region(self): class TestApplicationVersion(TestCase): def _get_or_create_application_version( - self, polling_results: Sequence[Optional[action.ApplicationVersion]], + self, + polling_results: Sequence[Optional[action.ApplicationVersion]], ): with NamedTemporaryFile() as docker_compose_file, patch.object( - action, "boto3", + action, + "boto3", ), patch.object( action.ApplicationVersion, "get", @@ -68,7 +74,8 @@ def _get_or_create_application_version( polling_max_steps=len(polling_results) - 1, ) self.assertEqual( - mock_get_application_version.call_count, len(polling_results), + mock_get_application_version.call_count, + len(polling_results), ) return result @@ -133,7 +140,8 @@ def _deploy( self.assertEqual(mock_get_events.call_count, iterations) mock_is_active_in_environment.assert_called_with(MOCK_ENVIRONMENT) self.assertEqual( - mock_is_active_in_environment.call_count, len(is_active_in_environment), + mock_is_active_in_environment.call_count, + len(is_active_in_environment), ) def test_successful_deployment(self): @@ -148,7 +156,8 @@ def test_successful_deployment(self): def test_environment_timeout_error(self, *_): with self.assertRaises(TimeoutError): self._deploy( - ({"Status": "InProgress", "Color": "Grey"},) * 5, (False, True), + ({"Status": "InProgress", "Color": "Grey"},) * 5, + (False, True), ) def test_health_failed(self):