-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaction.yml
109 lines (97 loc) · 3.69 KB
/
action.yml
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
name: 'Comment on PR with Structurizr Diagrams'
description: 'Automatically comments on PRs with Structurizr diagrams.'
branding:
icon: 'activity'
color: 'white'
inputs:
repo-token:
description: 'GITHUB_TOKEN from secrets'
required: true
output-path:
description: 'Path to the generated images'
required: true
default: 'docs/diagrams'
runs:
using: 'composite'
steps:
- name: Get PR Info
env:
GITHUB_TOKEN: ${{ inputs.repo-token }}
WORKFLOW_RUN_EVENT_OBJ: ${{ toJSON(github.event.workflow_run) }}
run: |
PREVIOUS_JOB_ID=$(jq -r '.id' <<< "$WORKFLOW_RUN_EVENT_OBJ")
echo "Previous Job ID: $PREVIOUS_JOB_ID"
echo "PREVIOUS_JOB_ID=$PREVIOUS_JOB_ID" >> "$GITHUB_ENV"
PR_NUMBER=$(jq -r '.pull_requests[0].number' \
<<< "$WORKFLOW_RUN_EVENT_OBJ")
echo "PR Number: $PR_NUMBER"
echo "PR_NUMBER=$PR_NUMBER" >> "$GITHUB_ENV"
HEAD_SHA=$(jq -r '.pull_requests[0].head.sha' \
<<< "$WORKFLOW_RUN_EVENT_OBJ")
echo "Head sha: $HEAD_SHA"
echo "HEAD_SHA=$HEAD_SHA" >> "$GITHUB_ENV"
shell: bash
- name: Checkout Repository
uses: actions/checkout@v4
env:
GITHUB_TOKEN: ${{ inputs.repo-token }}
with:
ref: ${{ github.event.workflow_run.head_branch }}
- name: List Diagram Files
env:
HEAD_SHA: ${{ env.HEAD_SHA }}
run: |
cd ${{ inputs.output-path }}
echo 'PNG_FILES_MARKDOWN<<EOF' >> "$GITHUB_ENV"
for png_file in *.png; do
# Skip legend files in this loop
if [[ $png_file == *"-key.png" ]]; then
continue
fi
base_name=$(basename $png_file .png)
legend_file="${base_name}-key.png"
# URLs for diagram and its legend
png_raw_file_path="https://github.com/${{ github.repository }}/blob/${{ github.event.workflow_run.head_branch }}/${{ inputs.output-path }}/${png_file}?raw=true"
legend_raw_file_path="https://github.com/${{ github.repository }}/blob/${{ github.event.workflow_run.head_branch }}/${{ inputs.output-path }}/${legend_file}?raw=true"
echo "<details>" >> "$GITHUB_ENV"
clean_base_name=${base_name#structurizr-}
echo "<summary>${clean_base_name}</summary>" >> "$GITHUB_ENV"
if [ -f "$legend_file" ]; then
echo "<img src=\"${legend_raw_file_path}\">" >> "$GITHUB_ENV"
echo "" >> "$GITHUB_ENV"
fi
echo " <img src=\"${png_raw_file_path}\">" >> "$GITHUB_ENV"
echo "</details>" >> "$GITHUB_ENV"
done
echo EOF >> "$GITHUB_ENV"
shell: bash
- name: Find Comment
uses: peter-evans/find-comment@v2
id: find-comment
env:
PR_NUMBER: ${{ env.PR_NUMBER }}
GITHUB_TOKEN: ${{ inputs.repo-token }}
with:
issue-number: ${{ env.PR_NUMBER }}
comment-author: 'github-actions[bot]'
- name: Comment on PR
uses: peter-evans/create-or-update-comment@v3
env:
GITHUB_TOKEN: ${{ inputs.repo-token }}
PR_NUMBER: ${{ env.PR_NUMBER }}
HEAD_SHA: ${{ env.HEAD_SHA }}
PREVIOUS_JOB_ID: ${{ env.PREVIOUS_JOB_ID }}
PNG_FILES_MARKDOWN: ${{ env.PNG_FILES_MARKDOWN }}
JOB_PATH: "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ env.PREVIOUS_JOB_ID }}"
with:
issue-number: ${{ env.PR_NUMBER }}
comment-id: ${{ steps.find-comment.outputs.comment-id }}
edit-mode: replace
reactions: |
heart
hooray
body: |
## C4 Diagrams
Commit: ${{ env.HEAD_SHA }}
Logs: ${{ env.JOB_PATH }}
${{ env.PNG_FILES_MARKDOWN }}