Skip to content

Commit

Permalink
formating
Browse files Browse the repository at this point in the history
  • Loading branch information
Jannis-Mittenzwei committed Sep 18, 2024
1 parent f29db69 commit 01ebd6a
Show file tree
Hide file tree
Showing 44 changed files with 1,074 additions and 706 deletions.
6 changes: 1 addition & 5 deletions exasol_script_languages_container_ci/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@

from exasol_script_languages_container_ci.cli.commands import (
run_ci,
run_release
)
from exasol_script_languages_container_ci.cli.commands import run_ci, run_release
76 changes: 42 additions & 34 deletions exasol_script_languages_container_ci/cli/commands/run_ci.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,40 +9,48 @@


@cli.command()
@click.option('--flavor', required=True, type=str,
help="Flavor name.")
@click.option('--branch-name', required=True, type=str,
help="Branch name.")
@click.option('--docker-user', required=True, type=str,
help="Docker user name")
@click.option('--docker-password', required=True, type=str,
help="Docker password")
@click.option('--docker-build-repository', required=True, type=str,
help="Docker build repository")
@click.option('--docker-release-repository', required=True, type=str,
help="Docker release repository")
@click.option('--commit-sha', required=True, type=str,
help="Commit SHA")
@click.option('--config-file', required=True, type=click.Path(exists=True, file_okay=True, dir_okay=False),
help="The build config file (project specific)")
@click.option("--flavor", required=True, type=str, help="Flavor name.")
@click.option("--branch-name", required=True, type=str, help="Branch name.")
@click.option("--docker-user", required=True, type=str, help="Docker user name")
@click.option("--docker-password", required=True, type=str, help="Docker password")
@click.option(
"--docker-build-repository", required=True, type=str, help="Docker build repository"
)
@click.option(
"--docker-release-repository",
required=True,
type=str,
help="Docker release repository",
)
@click.option("--commit-sha", required=True, type=str, help="Commit SHA")
@click.option(
"--config-file",
required=True,
type=click.Path(exists=True, file_okay=True, dir_okay=False),
help="The build config file (project specific)",
)
@click.pass_context
def run_ci(ctx: click.Context,
flavor: str,
branch_name: str,
docker_user: str,
docker_password: str,
docker_build_repository: str,
docker_release_repository: str,
commit_sha: str,
config_file: str):
def run_ci(
ctx: click.Context,
flavor: str,
branch_name: str,
docker_user: str,
docker_password: str,
docker_build_repository: str,
docker_release_repository: str,
commit_sha: str,
config_file: str,
):
logging.basicConfig(level=logging.INFO)
build_config = Config.parse_file(config_file)
ci(flavor=flavor,
branch_name=branch_name,
docker_user=docker_user,
docker_password=docker_password,
docker_build_repository=docker_build_repository,
docker_release_repository=docker_release_repository,
commit_sha=commit_sha,
build_config=build_config,
git_access=GitAccess())
ci(
flavor=flavor,
branch_name=branch_name,
docker_user=docker_user,
docker_password=docker_password,
docker_build_repository=docker_build_repository,
docker_release_repository=docker_release_repository,
commit_sha=commit_sha,
build_config=build_config,
git_access=GitAccess(),
)
93 changes: 56 additions & 37 deletions exasol_script_languages_container_ci/cli/commands/run_release.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,50 +6,69 @@
from exasol_script_languages_container_ci.cli.cli import cli
from exasol_script_languages_container_ci.lib.asset_uploader import AssetUploader
from exasol_script_languages_container_ci.lib.config.config_data_model import Config
from exasol_script_languages_container_ci.lib.github_release_asset_uploader import GithubReleaseAssetUploader
from exasol_script_languages_container_ci.lib.github_release_asset_uploader import (
GithubReleaseAssetUploader,
)
from exasol_script_languages_container_ci.lib.release import release
from exasol_script_languages_container_ci.lib.release_uploader import ReleaseUploader


@cli.command()
@click.option('--flavor', required=True, type=str,
help="Flavor name.")
@click.option('--docker-user', required=True, type=str,
help="Docker user name")
@click.option('--docker-password', required=True, type=str,
help="Docker password")
@click.option('--docker-release-repository', required=True, type=str,
help="Docker release repository")
@click.option('--config-file', required=True, type=click.Path(exists=True, file_okay=True, dir_okay=False),
help="The build config file (project specific)")
@click.option('--source-repo-url', required=True, type=str,
help="The url of the repository. Usually set by AWS under env variable CODEBUILD_SOURCE_REPO_URL.")
@click.option('--release-id', required=True, type=int,
help="The id of the release.")
@click.option('--dry-run/--no-dry-run', default=False,
help="If true, runs release without pushing the container to the docker release repository."
"If false, also pushes the container to the docker release repository.")
@click.option("--flavor", required=True, type=str, help="Flavor name.")
@click.option("--docker-user", required=True, type=str, help="Docker user name")
@click.option("--docker-password", required=True, type=str, help="Docker password")
@click.option(
"--docker-release-repository",
required=True,
type=str,
help="Docker release repository",
)
@click.option(
"--config-file",
required=True,
type=click.Path(exists=True, file_okay=True, dir_okay=False),
help="The build config file (project specific)",
)
@click.option(
"--source-repo-url",
required=True,
type=str,
help="The url of the repository. Usually set by AWS under env variable CODEBUILD_SOURCE_REPO_URL.",
)
@click.option("--release-id", required=True, type=int, help="The id of the release.")
@click.option(
"--dry-run/--no-dry-run",
default=False,
help="If true, runs release without pushing the container to the docker release repository."
"If false, also pushes the container to the docker release repository.",
)
@click.pass_context
def run_release(ctx: click.Context,
flavor: str,
docker_user: str,
docker_password: str,
docker_release_repository: str,
config_file: str,
source_repo_url: str,
release_id: int,
dry_run: bool):
def run_release(
ctx: click.Context,
flavor: str,
docker_user: str,
docker_password: str,
docker_release_repository: str,
config_file: str,
source_repo_url: str,
release_id: int,
dry_run: bool,
):
logging.basicConfig(level=logging.INFO)
github_release_asset_uploader = GithubReleaseAssetUploader(os.getenv("GITHUB_TOKEN"))
github_release_asset_uploader = GithubReleaseAssetUploader(
os.getenv("GITHUB_TOKEN")
)
asset_uploader = AssetUploader(release_asset_uploader=github_release_asset_uploader)
release_uploader = ReleaseUploader(asset_uploader=asset_uploader)
build_config = Config.parse_file(config_file)
release(flavor=flavor,
docker_user=docker_user,
docker_password=docker_password,
docker_release_repository=docker_release_repository,
build_config=build_config,
source_repo_url=source_repo_url,
release_id=release_id,
release_uploader=release_uploader,
is_dry_run=dry_run)
release(
flavor=flavor,
docker_user=docker_user,
docker_password=docker_password,
docker_release_repository=docker_release_repository,
build_config=build_config,
source_repo_url=source_repo_url,
release_id=release_id,
release_uploader=release_uploader,
is_dry_run=dry_run,
)
36 changes: 25 additions & 11 deletions exasol_script_languages_container_ci/lib/asset_uploader.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,39 @@
import logging
from pathlib import Path

from exasol_script_languages_container_ci.lib.github_release_asset_uploader import GithubReleaseAssetUploader
from exasol_script_languages_container_ci.lib.github_release_asset_uploader import (
GithubReleaseAssetUploader,
)


class AssetUploader:

def __init__(self, release_asset_uploader: GithubReleaseAssetUploader):
self._release_asset_uploader = release_asset_uploader

def upload_assets(self,
repo_id: str, release_id: int, content_type: str,
artifact_path: str, file_suffix: str, label_prefix: str):
release_artifacts = glob.glob(f'{artifact_path}/*{file_suffix}')
def upload_assets(
self,
repo_id: str,
release_id: int,
content_type: str,
artifact_path: str,
file_suffix: str,
label_prefix: str,
):
release_artifacts = glob.glob(f"{artifact_path}/*{file_suffix}")
for release_artifact in release_artifacts:
artifact_file_name = Path(release_artifact).name
if artifact_file_name.endswith(file_suffix):
artifact_file_name = artifact_file_name[:-len(file_suffix)]
artifact_file_name = artifact_file_name[: -len(file_suffix)]
else:
logging.error(f"Artifact file: {artifact_file_name} does not end with {file_suffix}. "
f"Using {artifact_file_name} as label.")
self._release_asset_uploader.upload(archive_path=release_artifact,
label=f"{label_prefix} {artifact_file_name}",
repo_id=repo_id, release_id=release_id, content_type=content_type)
logging.error(
f"Artifact file: {artifact_file_name} does not end with {file_suffix}. "
f"Using {artifact_file_name} as label."
)
self._release_asset_uploader.upload(
archive_path=release_artifact,
label=f"{label_prefix} {artifact_file_name}",
repo_id=repo_id,
release_id=release_id,
content_type=content_type,
)
44 changes: 30 additions & 14 deletions exasol_script_languages_container_ci/lib/branch_config.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from enum import Enum, auto
import re
from enum import Enum, auto


class BuildSteps(Enum):
Expand All @@ -9,14 +9,26 @@ class BuildSteps(Enum):


class BranchConfig(Enum):
DEVELOP = {BuildSteps.BUILD_ALL_ALWAYS: True, BuildSteps.REBUILD: True,
BuildSteps.PUSH_TO_DOCKER_RELEASE_REPO: False}
MAIN = {BuildSteps.BUILD_ALL_ALWAYS: True, BuildSteps.REBUILD: True,
BuildSteps.PUSH_TO_DOCKER_RELEASE_REPO: True}
REBUILD = {BuildSteps.BUILD_ALL_ALWAYS: True, BuildSteps.REBUILD: True,
BuildSteps.PUSH_TO_DOCKER_RELEASE_REPO: False}
OTHER = {BuildSteps.BUILD_ALL_ALWAYS: False, BuildSteps.REBUILD: False,
BuildSteps.PUSH_TO_DOCKER_RELEASE_REPO: False}
DEVELOP = {
BuildSteps.BUILD_ALL_ALWAYS: True,
BuildSteps.REBUILD: True,
BuildSteps.PUSH_TO_DOCKER_RELEASE_REPO: False,
}
MAIN = {
BuildSteps.BUILD_ALL_ALWAYS: True,
BuildSteps.REBUILD: True,
BuildSteps.PUSH_TO_DOCKER_RELEASE_REPO: True,
}
REBUILD = {
BuildSteps.BUILD_ALL_ALWAYS: True,
BuildSteps.REBUILD: True,
BuildSteps.PUSH_TO_DOCKER_RELEASE_REPO: False,
}
OTHER = {
BuildSteps.BUILD_ALL_ALWAYS: False,
BuildSteps.REBUILD: False,
BuildSteps.PUSH_TO_DOCKER_RELEASE_REPO: False,
}

@staticmethod
def build_always(branch_name: str) -> bool:
Expand All @@ -28,16 +40,20 @@ def rebuild(branch_name) -> bool:

@staticmethod
def push_to_docker_release_repo(branch_name: str) -> bool:
return get_branch_config(branch_name).value[BuildSteps.PUSH_TO_DOCKER_RELEASE_REPO]
return get_branch_config(branch_name).value[
BuildSteps.PUSH_TO_DOCKER_RELEASE_REPO
]


def get_branch_config(branch_name: str) -> BranchConfig:
matches = ((re.compile(r"refs/heads/(master|main)"), BranchConfig.MAIN),
(re.compile(r"refs/heads/develop"), BranchConfig.DEVELOP),
(re.compile(r"refs/heads/rebuild/.*"), BranchConfig.REBUILD))
matches = (
(re.compile(r"refs/heads/(master|main)"), BranchConfig.MAIN),
(re.compile(r"refs/heads/develop"), BranchConfig.DEVELOP),
(re.compile(r"refs/heads/rebuild/.*"), BranchConfig.REBUILD),
)

branch_cfg = BranchConfig.OTHER
for (branch_regex, branch_config) in matches:
for branch_regex, branch_config in matches:
if branch_regex.match(branch_name):
branch_cfg = branch_config
break
Expand Down
Loading

0 comments on commit 01ebd6a

Please sign in to comment.