-
Notifications
You must be signed in to change notification settings - Fork 0
99 lines (86 loc) · 3.13 KB
/
d2-diagrams.yml
File metadata and controls
99 lines (86 loc) · 3.13 KB
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
name: Build D2 Architecture Diagrams
on:
pull_request:
paths:
- 'diagrams/**/*.d2'
- '.github/workflows/d2-diagrams.yml'
push:
branches:
- main
paths:
- 'diagrams/**/*.d2'
- '.github/workflows/d2-diagrams.yml'
permissions:
contents: read
pull-requests: write
jobs:
build-diagrams:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install D2
run: |
curl -fsSL https://d2lang.com/install.sh | sh -s --
echo "$HOME/.local/bin" >> $GITHUB_PATH
- name: Build D2 diagrams
run: |
mkdir -p diagrams/output
d2 diagrams/main.d2 diagrams/output/architecture.svg
echo "✅ Generated architecture.svg"
- name: Upload diagram as artifact
uses: actions/upload-artifact@v4
with:
name: architecture-diagram
path: diagrams/output/architecture.svg
retention-days: 90
- name: Post diagram to PR comment
if: github.event_name == 'pull_request'
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
const path = require('path');
// Read the SVG file
const svgPath = path.join(
process.env.GITHUB_WORKSPACE,
'diagrams/output/architecture.svg'
);
const svgContent = fs.readFileSync(svgPath, 'utf8');
// Create comment body with embedded SVG
const commentBody = '## 🏗️ Architecture Diagram Updated\n\n' +
'The D2 architecture diagram has been regenerated based on the changes in this PR.\n\n' +
'### Production Architecture\n\n' +
'<details>\n' +
'<summary>Click to view diagram</summary>\n\n' +
svgContent + '\n\n' +
'</details>\n\n' +
'---\n\n' +
'📥 You can also download the diagram from the [workflow artifacts]' +
'(https://github.com/' + context.repo.owner + '/' + context.repo.repo + '/actions/runs/' + context.runId + ').';
// Find existing comment
const comments = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
});
const botComment = comments.data.find(comment =>
comment.user.type === 'Bot' &&
comment.body.includes('🏗️ Architecture Diagram Updated')
);
// Update or create comment
if (botComment) {
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: botComment.id,
body: commentBody
});
} else {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: commentBody
});
}