-
Notifications
You must be signed in to change notification settings - Fork 40
/
github_actions_cicd.py
executable file
·161 lines (132 loc) · 4.76 KB
/
github_actions_cicd.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
#!/usr/bin/env python3
# coding=utf-8
# vim:ts=4:sts=4:sw=4:et
#
# Author: Hari Sekhon
# Date: 2023-04-17 03:54:00 +0100 (Mon, 17 Apr 2023)
#
# https://github.com/HariSekhon/Diagrams-as-Code
#
# License: see accompanying Hari Sekhon LICENSE file
#
# If you're using my code you're welcome to connect with me on LinkedIn
# and optionally send me feedback to help steer this or other code I publish
#
# https://www.linkedin.com/in/HariSekhon
#
"""
GitHub Actions CI/CD
"""
__author__ = 'Hari Sekhon'
__version__ = '0.4.1'
import os
#import requests
from diagrams import Diagram, Cluster, Edge
# ============================================================================ #
# On-premise / Open Source resources:
#
# https://diagrams.mingrammer.com/docs/nodes/onprem
#
#from diagrams.onprem.client import User # , Users
from diagrams.onprem.ci import Jenkins, GithubActions
from diagrams.onprem.vcs import Git, Github
# ============================================================================ #
# SaaS:
#
# https://diagrams.mingrammer.com/docs/nodes/saas
#
from diagrams.saas.chat import Slack
# ============================================================================ #
#
# Programming - flowcharts, programming languages and frameworks
#
# https://diagrams.mingrammer.com/docs/nodes/programming
#
from diagrams.programming.language import Python
from diagrams.programming.flowchart import Document
# ============================================================================ #
#
# Custom - for creating a custom object using a downloaded image
#
# https://diagrams.mingrammer.com/docs/nodes/custom
#
from diagrams.custom import Custom
# ============================================================================ #
# pylint: disable=C0103
headers = {'user-agent': 'Mozilla/5.0'}
hari_icon = "hari.jpeg"
# rolling_eyes_url = "https://em-content.zobj.net/thumbs/240/apple/354/face-with-rolling-eyes_1f644.png"
rolling_eyes_icon = "rolling_eyes.png"
# r = requests.get(rolling_eyes_url, headers=headers)
# with open(rolling_eyes_icon, 'wb') as f:
# f.write(r.content)
# r = requests.get(hari_url, headers=headers)
# with open(hari_icon, 'wb') as f:
# f.write(r.content)
# ============================================================================ #
graph_attr = {
"splines": "spline",
}
image_dir = 'images'
# pylint: disable=W0104,W0106
with Diagram('GitHub Actions CI/CD - Auto-(Re)Generate Diagrams',
show=not bool(os.environ.get('CI', 0)),
direction='LR',
filename=os.path.join(image_dir, "github_actions_cicd"),
graph_attr=graph_attr,
):
#hari = User("Hari\nPythonista")
hari = Custom("Hari\nPythonista", hari_icon)
#giovanni = User("Giovanni")
giovanni = Custom("Giovanni", rolling_eyes_icon)
#ravi = User("Ravi")
ravi = Custom("Ravi", "man-shrugging-medium-skin-tone.png")
#you = User("You")
you = Custom("You", "flushed-face.png")
#users = Users("Users")
git = Git("Git")
hari \
>> Edge(label="crazy midnight to 4am coding") \
>> [
# can't handle svg
#Custom("D2", "d2_graphic.svg")
#Custom("D2", "d2_logo.png")
Custom("D2", "d2_graphic.png"),
Python("Python")
] \
>> Edge(label="git commit") \
>> git
with Cluster("GitHub"):
github_repo = Github("Diagrams-as-Code\nGitHub repo")
with Cluster("GitHub Actions\nCI/CD"):
python_workflow = GithubActions("Generate Python\nImages workflow")
d2_workflow = GithubActions("Generate D2\nImages workflow")
readme = Document("README.md")
git >> Edge(label="git push") >> github_repo
github_repo >> Edge(label="*.py changes trigger workflow") >> python_workflow
github_repo >> Edge(label="*.d2 changes trigger workflow") >> d2_workflow
[python_workflow, d2_workflow] \
>> Edge(label="git commit new / updated diagrams") \
>> github_repo \
>> readme
with Cluster("Banned by Giovanni"):
with Cluster("Do Not Use"):
# hari \
# - Edge(color='red', style="dashed") \
Jenkins("Jenkins") \
<< Edge(label="banned", color='red', style="dashed") \
<< giovanni
# github_actions \
# << Edge(label="I will just about tolerate this") \
# << giovanni
slack = Slack("Slack")
hari \
>> Edge(label="Hey Guys,\nlook what I just did\nthis weekend!") \
>> slack
ravi \
>> Edge(label="Hey,\nwhat did I miss?") \
>> slack
giovanni \
>> Edge(label="Hari is doing his\n\"rain man\"\nthing again...") \
>> slack
you >> readme # << users