-
Notifications
You must be signed in to change notification settings - Fork 209
130 lines (123 loc) · 5.37 KB
/
zip-preview.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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
name: Zip Preview
on:
issues:
types: [opened, edited]
issue_comment:
types: [created, edited]
permissions:
issues: write
jobs:
zip_preview_issue:
if: ${{ contains(github.event_name, 'issues') && contains(github.event.issue.labels.*.name, 'Zip/PR included') }}
runs-on: ubuntu-latest
steps:
- name: Generate Preview Content
id: zip_preview
env:
body: ${{ github.event.issue.body }}
run: |
zip_url="$(echo "$body" | sed -n '/### Upload file or Add PR Link/,/###/p' | grep -v "###" | grep -Eo "(http|https)://[a-zA-Z0-9./?=_%:-]*.zip(\?raw=true|)" | head -n 1)"
if [ -z "$zip_url" ]; then
exit 0
else
wget -O download.zip "$zip_url"
echo "sha1=$(sha1sum download.zip | awk {'print $1}')" >> $GITHUB_OUTPUT
unzip download.zip
rm -f download.zip
files="$(find ./ -not -name '*.png' -type f | sed 's|^./||')"
echo "zip_preview<<EOF" >> $GITHUB_OUTPUT
echo '<details>' >> $GITHUB_OUTPUT
echo '<summary>Click to show contents preview</summary>' >> $GITHUB_OUTPUT
echo '' >> $GITHUB_OUTPUT
IFS=$'\n'
for file in $files; do
file_basename="$(basename "$file")"
echo '`'"$file"'`' >> $GITHUB_OUTPUT
if [ "$file_basename" == install ] || [ "$file_basename" == install-32 ] || [ "$file_basename" == install-64 ] || [ "$file_basename" == uninstall ]; then
echo '```bash' >> $GITHUB_OUTPUT
else
echo '```' >> $GITHUB_OUTPUT
fi
cat "$file" >> $GITHUB_OUTPUT
echo $'\n''```' >> $GITHUB_OUTPUT
done
echo '' >> $GITHUB_OUTPUT
echo '</details>' >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
fi
- name: Find Comment
uses: peter-evans/find-comment@v3
if: steps.zip_preview.outputs.zip_preview
id: fc
with:
issue-number: ${{ github.event.issue.number }}
comment-author: 'github-actions[bot]'
body-includes: "The sha1sum of the zip was: ${{ steps.zip_preview.outputs.sha1 }}"
- name: Add zip preview comment for issue
uses: peter-evans/create-or-update-comment@v4
if: steps.zip_preview.outputs.zip_preview
with:
comment-id: ${{ steps.fc.outputs.comment-id }}
issue-number: ${{ github.event.issue.number }}
edit-mode: replace
body: |
A zipfile was found in the body of your issue.
The sha1sum of the zip was: ${{ steps.zip_preview.outputs.sha1 }}
${{ steps.zip_preview.outputs.zip_preview }}
zip_preview_issue_comment:
if: ${{ !contains(github.event_name, 'issues') && contains(github.event_name, 'issue_comment') && contains(github.event.issue.labels.*.name, 'Zip/PR included') && !github.event.issue.pull_request }}
runs-on: ubuntu-latest
steps:
- name: Generate Preview Content
id: zip_preview
env:
body: ${{ github.event.comment.body }}
run: |
zip_url="$(echo "$body" | grep -Eo "(http|https)://[a-zA-Z0-9./?=_%:-]*.zip(\?raw=true|)" | head -n 1)"
if [ -z "$zip_url" ]; then
exit 0
else
wget -O download.zip "$zip_url"
echo "sha1=$(sha1sum download.zip | awk {'print $1}')" >> $GITHUB_OUTPUT
unzip download.zip
rm -f download.zip
files="$(find ./ -not -name '*.png' -type f | sed 's|^./||')"
echo "zip_preview<<EOF" >> $GITHUB_OUTPUT
echo '<details>' >> $GITHUB_OUTPUT
echo '<summary>Click to show contents preview</summary>' >> $GITHUB_OUTPUT
echo '' >> $GITHUB_OUTPUT
IFS=$'\n'
for file in $files; do
file_basename="$(basename "$file")"
echo '`'"$file"'`' >> $GITHUB_OUTPUT
if [ "$file_basename" == install ] || [ "$file_basename" == install-32 ] || [ "$file_basename" == install-64 ] || [ "$file_basename" == uninstall ]; then
echo '```bash' >> $GITHUB_OUTPUT
else
echo '```' >> $GITHUB_OUTPUT
fi
cat "$file" >> $GITHUB_OUTPUT
echo $'\n''```' >> $GITHUB_OUTPUT
done
echo '' >> $GITHUB_OUTPUT
echo '</details>' >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
fi
- name: Find Comment
uses: peter-evans/find-comment@v3
if: steps.zip_preview.outputs.zip_preview
id: fc
with:
issue-number: ${{ github.event.issue.number }}
comment-author: 'github-actions[bot]'
body-includes: "The sha1sum of the zip was: ${{ steps.zip_preview.outputs.sha1 }}"
- name: Add zip preview comment for issue comment
uses: peter-evans/create-or-update-comment@v4
if: steps.zip_preview.outputs.zip_preview
with:
comment-id: ${{ steps.fc.outputs.comment-id }}
issue-number: ${{ github.event.issue.number }}
edit-mode: replace
body: |
A zipfile was found in the body of an issue comment.
The sha1sum of the zip was: ${{ steps.zip_preview.outputs.sha1 }}
${{ steps.zip_preview.outputs.zip_preview }}