Skip to content

Commit 4d375ac

Browse files
authored
Merge pull request #1 from edenlabllc/feature/RMK-1-add-code-structure
#1 - init commit
2 parents 964aba6 + 3969f89 commit 4d375ac

File tree

27 files changed

+1216
-0
lines changed

27 files changed

+1216
-0
lines changed

.github/workflows/core.yaml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: GitHub Actions Common CI
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
- feature/*
8+
9+
env:
10+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
11+
VERSION: v1
12+
13+
jobs:
14+
ci:
15+
name: Checkout main repository, release GitHub Actions Common
16+
runs-on: ubuntu-22.04
17+
steps:
18+
- name: Initialize environment variables
19+
run: |
20+
GIT_BRANCH="${GITHUB_REF#refs/heads/}"
21+
22+
if [[ "master" != "${GIT_BRANCH}" ]]; then
23+
VERSION="${VERSION}-develop"
24+
fi
25+
26+
echo "GIT_BRANCH=${GIT_BRANCH}" >> ${GITHUB_ENV}
27+
echo "VERSION=${VERSION}" >> ${GITHUB_ENV}
28+
29+
- name: Checkout main repository
30+
uses: actions/checkout@v4
31+
with:
32+
ref: ${{ github.ref }}
33+
34+
- name: Release GitHub Actions Common
35+
run: |
36+
./release-service.sh ${{ env.VERSION }} ${{ env.GIT_BRANCH }} ${{ env.GITHUB_SHA }} ""

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
.DS_Store
2+
.idea/
3+
*.egg-info/
4+
*.egg
5+
dist/
6+
build/
7+
__pycache__/

docs/CODEOWNERS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# These owners will be the default owners for everything in
2+
# the repo and will be requested for review when someone opens a pull request.
3+
* @anovikov-el @apanasiuk-el

examples/requirements.txt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# === Public GitHub package ===
2+
# Installs from the v1 tag of a public GitHub repository
3+
# No authentication required
4+
git+https://github.com/edenlabllc/github_actions.common.git@v1#egg=github_actions.common
5+
6+
# === Private GitHub package ===
7+
# Installs from v1 tag of a private GitHub repository
8+
# Requires a GitHub Personal Access Token (with 'repo' scope)
9+
# The token should be passed securely via environment variables
10+
# Example usage:
11+
# export GITHUB_TOKEN=ghp_XXXXXXXXXXXXXXXXXXXXXXXXXXXX
12+
# pip install -r requirements.txt
13+
#
14+
# Do NOT hardcode your token here!
15+
git+https://${GITHUB_TOKEN}@github.com/edenlabllc/github_actions.common.git@v1#egg=github_actions.common

pyproject.toml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
[project]
2+
name = "github_actions.common"
3+
version = "v1"
4+
description = "Common helpers and utilities for GitHub Actions used across edenlab repositories"
5+
readme = "README.md"
6+
license = { text = "Apache-2.0" }
7+
requires-python = ">=3.10"
8+
authors = [{ name = "Edenlabllc" }]
9+
maintainers = [
10+
{ name = "@anovikov-el" },
11+
{ name = "@apanasiuk-el" }
12+
]
13+
keywords = [
14+
"python", "github", "actions",
15+
"ci", "cd", "devops", "infrastructure",
16+
"aws", "azure", "gcp", "devops",
17+
"rmk",
18+
]
19+
classifiers = [
20+
"Intended Audience :: Developers",
21+
"Topic :: Software Development :: Build Tools",
22+
"License :: OSI Approved :: Apache Software License",
23+
"Programming Language :: Python :: 3.10",
24+
"Programming Language :: Python :: 3.11"
25+
]
26+
dependencies = [
27+
"requests~=2.32.3",
28+
"GitPython~=3.1.44",
29+
"PyGithub==2.5.0",
30+
"slack_sdk~=3.34.0",
31+
"packaging~=24.2",
32+
"utils~=1.0.2",
33+
"boto3~=1.37.18",
34+
"botocore~=1.37.18"
35+
]
36+
37+
[build-system]
38+
requires = ["setuptools>=61.0", "wheel"]
39+
build-backend = "setuptools.build_meta"
40+
41+
[tool.setuptools]
42+
package-dir = {"" = "src"}
43+
44+
[tool.setuptools.packages.find]
45+
where = ["src"]

release-service.sh

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
VERSION="${1}"
6+
GIT_BRANCH="${2}"
7+
GITHUB_SHA="${3}"
8+
RELEASE_FILES="${4}"
9+
10+
echo "Release service (only for master)."
11+
if [[ "master" == "${GIT_BRANCH}" ]]; then
12+
echo "Configure Git user.name and user.email."
13+
git config user.name github-actions
14+
git config user.email github-actions@github.com
15+
16+
RELEASE_MSG="Release ${VERSION}"
17+
18+
echo "Add Git tag ${VERSION}."
19+
git tag -a "${VERSION}" -m "${RELEASE_MSG}"
20+
git push origin "${VERSION}" -f
21+
22+
if gh release view "${VERSION}" &> /dev/null; then
23+
echo "GitHub release ${VERSION} already exists."
24+
echo "Skipped."
25+
else
26+
echo "Create GitHub release ${VERSION}."
27+
gh release create "${VERSION}" --target "${GITHUB_SHA}" --notes "${RELEASE_MSG}" ${RELEASE_FILES}
28+
fi
29+
else
30+
echo "Skipped."
31+
fi

src/github_actions/__init__.py

Whitespace-only changes.
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# github_actions/common/__init__.py
2+
3+
from .actions.init_project import GETTenant, ProjectInitializer, RMKConfigInitCommand
4+
from .credentials.cluster_provider_credentials import (
5+
AWSConfig, AzureConfig, ClusterProviders, Credentials, EnvironmentConfig, GCPConfig
6+
)
7+
from .input_output.input import ArgumentParser
8+
from .input_output.output import GitHubOutput
9+
from .notification.slack_notification import SlackNotifier
10+
from .providers.aws_provider.aws import (
11+
AWSSessionManager, EKSClusterFetcher, EBSVolumeFetcher, ECRManager, S3BucketManager
12+
)
13+
from .select_environment.allowed_environments import AllowEnvironments
14+
from .select_environment.select_environment import (
15+
EnvironmentSelectorInterface, EnvironmentSelector, ExtendedEnvironmentSelector
16+
)
17+
from .utils.cmd import BaseCommand, CMDInterface
18+
from .utils.github_environment_variables import GitHubContext
19+
from .utils.install_rmk import RMKInstaller
20+
21+
22+
__all__ = [
23+
"AWSConfig",
24+
"AWSSessionManager",
25+
"AllowEnvironments",
26+
"ArgumentParser",
27+
"AzureConfig",
28+
"BaseCommand",
29+
"CMDInterface",
30+
"ClusterProviders",
31+
"Credentials",
32+
"EBSVolumeFetcher",
33+
"ECRManager",
34+
"EKSClusterFetcher",
35+
"EnvironmentConfig",
36+
"EnvironmentSelector",
37+
"EnvironmentSelectorInterface",
38+
"ExtendedEnvironmentSelector",
39+
"GCPConfig",
40+
"GETTenant",
41+
"GitHubContext",
42+
"GitHubOutput",
43+
"ProjectInitializer",
44+
"RMKConfigInitCommand",
45+
"RMKInstaller",
46+
"S3BucketManager",
47+
"SlackNotifier",
48+
]

src/github_actions/common/actions/__init__.py

Whitespace-only changes.
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
import json
2+
import os
3+
4+
from argparse import Namespace
5+
from git import Repo, GitCommandError
6+
7+
from ..utils.cmd import BaseCommand, CMDInterface
8+
9+
10+
class RMKConfigInitCommand(BaseCommand, CMDInterface):
11+
def __init__(self, environment: str, args: Namespace):
12+
super().__init__(environment)
13+
self.cluster_provider = args.rmk_cluster_provider
14+
self.github_token = args.github_token
15+
self.slack_notification = ""
16+
self.slack_channel = ""
17+
self.slack_message_details = ""
18+
self.slack_webhook = ""
19+
20+
def execute(self):
21+
self.run()
22+
23+
def run(self):
24+
"""Configure Slack notifications if enabled."""
25+
os.environ["RMK_GITHUB_TOKEN"] = self.github_token
26+
if self.slack_notification == "true":
27+
os.environ["RMK_SLACK_WEBHOOK"] = self.slack_webhook
28+
os.environ["RMK_SLACK_CHANNEL"] = self.slack_channel
29+
30+
flags_slack_message_details = ""
31+
if self.slack_message_details.splitlines():
32+
flags_slack_message_details = " ".join(
33+
[f'--slack-message-details="{detail}"' for detail in self.slack_message_details.splitlines()]
34+
)
35+
36+
self.run_command(f"rmk config init --cluster-provider={self.cluster_provider}"
37+
f" --progress-bar=false --slack-notifications {flags_slack_message_details}")
38+
else:
39+
self.run_command(f"rmk config init --cluster-provider={self.cluster_provider} --progress-bar=false")
40+
41+
42+
class GETTenant(BaseCommand, CMDInterface):
43+
def __init__(self, environment: str):
44+
super().__init__(environment)
45+
46+
def execute(self) -> str:
47+
return self.run()
48+
49+
def run(self) -> str:
50+
output = self.run_command(f"rmk --log-format=json config view", True)
51+
rmk_config = json.loads(output)
52+
return rmk_config["config"]["Tenant"]
53+
54+
55+
class ProjectInitializer:
56+
GIT_CONFIG = {
57+
"name": "github-actions",
58+
"email": "github-actions@github.com",
59+
}
60+
61+
def __init__(self, environment: str):
62+
print("Initialize project repository.")
63+
self.environment = environment
64+
self.configure_git()
65+
66+
def configure_git(self):
67+
"""Configure Git user settings."""
68+
try:
69+
repo = Repo(".")
70+
repo.config_writer().set_value("user", "name", self.GIT_CONFIG["name"]).release()
71+
repo.config_writer().set_value("user", "email", self.GIT_CONFIG["email"]).release()
72+
except GitCommandError as err:
73+
raise ValueError(f"failed to configure Git: {err}")
74+
75+
def configure_rmk_init(self, args: Namespace):
76+
"""Configure Slack notifications using SlackConfigCommand."""
77+
rmk_init = RMKConfigInitCommand(self.environment, args)
78+
rmk_init.execute()

0 commit comments

Comments
 (0)