Skip to content

Commit d490df2

Browse files
docs: add workflow architecture explanation (hiero-ledger#1778)
Signed-off-by: Siddhartha Ganguly <gangulysiddhartha22@gmail.com>
1 parent 344bdb3 commit d490df2

2 files changed

Lines changed: 102 additions & 0 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ This changelog is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.
171171
- Added `__eq__` and `__hash__` functions for Key
172172

173173
### Documentation
174+
- Added `docs/workflows/02-architecture.md`: explains the orchestration (YAML) vs. business logic (JS) separation pattern for GitHub workflows (#1742)
174175
- Fix relative links in `testing.md`, clean up `CONTRIBUTING.md` TOC, and normalize test file naming and paths (`#1706`)
175176
- Added comprehensive docstring to `compress_with_cryptography` function (#1626)
176177
- Replaced the docstring in `entity_id_helper.py` with one that is correct. (#1623)

docs/workflows/02-architecture.md

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
# 02: How Workflows Are Structured (Orchestration + Logic)
2+
3+
Building on the basics from [01-what-are-workflows.md](./01-what-are-workflows.md), this document explains **exactly how** we structure workflows in the Hiero Python SDK repository.
4+
5+
We use a very deliberate pattern called **Orchestration vs. Logic separation**.
6+
This makes it much easier for you (and future contributors) to **create**, **tweak**, **understand**, and **maintain** automations.
7+
8+
## The Simple Flow
9+
10+
1. Something happens on GitHub
11+
(someone comments `/assign`, a PR is opened, code is pushed…)
12+
13+
2.
14+
15+
3. The **workflow (.yml)** wakes up and quickly decides:
16+
“Should this run right now?”
17+
(based on event type, branch, labels, etc.)
18+
19+
4.
20+
21+
5. If yes → it calls the matching **script (.js)**
22+
23+
6.
24+
25+
7. The **script** does all the real work
26+
(reads details, thinks, decides, talks to GitHub, writes comments…)
27+
28+
8.
29+
30+
9. Results show up in GitHub
31+
(comment posted, label added, check passed/failed, log messages…)
32+
33+
## Two Folders – Two Very Different Jobs
34+
35+
| Folder | File type | Role | Contains mostly… | Thinking allowed? |
36+
|-------------------------------|---------------|-------------------|--------------------------------------------------|-------------------|
37+
| `.github/workflows/` | `*.yml` | **Orchestration** | When to run, permissions, setup, calling script | Almost none |
38+
| `.github/scripts/` | `*.js` (main) | **Business Logic**| Decisions, API calls, calculations, comments | All of it |
39+
40+
**Golden rule used by the maintainers:**
41+
42+
> If it involves **thinking**, **deciding**, **checking conditions**, **calling APIs**, **handling errors**, or **writing messages to users** → put it in a **script**.<br>
43+
> If it is only about **starting the process**, **setting security**, or **connecting things** → put it in the **workflow YAML**.
44+
45+
## What Each Layer Is Responsible For
46+
47+
### Workflows (.github/workflows/*.yml) – Orchestration
48+
49+
Responsible for:
50+
51+
- Defining **triggers** (`on: pull_request`, `on: issue_comment`, etc.)
52+
- Setting **permissions** (`permissions: { issues: write }`)
53+
- Selecting **runners** (`runs-on: ubuntu-latest`)
54+
- Controlling **concurrency** (prevent duplicate runs)
55+
- Wiring **inputs**, **environment variables**, **secrets**
56+
- Calling the script (usually via `actions/github-script`)
57+
58+
Should contain **almost zero decision-making logic**.
59+
Complex `if:` conditions, string parsing, API calls, etc. do **not** belong here.
60+
61+
### Scripts (.github/scripts/*.js) – Business Logic
62+
63+
Responsible for:
64+
65+
- Interpreting the **event payload** (`context.payload`)
66+
- Making **decisions** (“Is this a valid /assign?”, “Does the issue have the right label?”)
67+
- Calling **GitHub APIs** (`github.rest.issues.addLabels`, `createComment`, …)
68+
- Computing **results**
69+
- Handling **errors** (`try/catch`, `core.setFailed`)
70+
- Producing **logs** (`core.info`, `core.warning`)
71+
- Generating **user-facing comments** (helpful messages, emojis, instructions)
72+
73+
**If it involves thinking → it belongs in the script.**
74+
75+
## Naming Convention (Very Important!)
76+
77+
We deliberately name workflows and their scripts **very similarly** so you can instantly see which files belong together:
78+
79+
Examples from the repository:
80+
81+
- `.github/workflows/bot-gfi-assign-on-comment.yml`
82+
`.github/scripts/bot-gfi-assign-on-comment.js`
83+
84+
This makes scanning `.github/` much faster when you want to understand or fix something.
85+
86+
## Best Practices Summary
87+
88+
- **Workflows** should have a **good, descriptive title**
89+
(the `name:` field – it appears in the Actions tab and in PR checks)
90+
Good: `Beginner Issues – Auto-assign when /assign is commented`
91+
Bad: `assign`
92+
93+
- **Scripts** should be **well documented**:
94+
- Start with a comment block explaining **purpose**
95+
- Add inline comments for any non-obvious logic
96+
- Example:
97+
```js
98+
// Purpose: Assigns a good-first-issue only if it's still free and correctly labeled
99+
// Allowed only via /assign command in issue comments
100+
```
101+

0 commit comments

Comments
 (0)