-
Notifications
You must be signed in to change notification settings - Fork 68
232 lines (209 loc) · 8.36 KB
/
test-plugin-command.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
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
name: Plugin 'Test' Command
on:
workflow_dispatch:
inputs:
# These first two inputs are required in order for the slash command to function
repository:
description: The repository from which the slash command was dispatched
required: true
comment-id:
description: The comment ID of the originating slash command
required: false
issue-number:
description: The issue number containing the slash command comment
required: true
from-slash-command:
description: Whether this workflow run was invoked by a slash command
required: true
default: 'false'
name:
description: The name of the plugin's executable
required: true
pip-url:
description: The pip_url for the plugin
required: false
default: ''
prepend-text:
description: Text to be prepended to the command output
required: false
default: ''
jobs:
plugin_tests:
runs-on: ubuntu-latest
permissions:
contents: write # to create a github release
pull-requests: write # to create and update PRs
env:
PLUGIN_NAME: ${{ github.event.inputs.name }}
PIP_URL: ${{ github.event.inputs.pip-url }}
steps:
- name: Handle missing pip_url
if: github.event.inputs.from-slash-command == 'true' && github.event.inputs.pip-url == ''
run: echo 'PIP_URL=${{ github.event.inputs.name }}' >> "$GITHUB_ENV"
- name: Add 👀 reaction
if: github.event.inputs.from-slash-command == 'true'
uses: peter-evans/create-or-update-comment@v4
with:
token: ${{ secrets.MELTYBOT_GITHUB_AUTH_TOKEN }}
repository: ${{ github.event.inputs.repository }}
comment-id: ${{ github.event.inputs.comment-id }}
reaction-type: eyes
- name: Set initial edit mode (to conditionally clear previous comment)
id: initial-edit-mode
run: |
should_replace=${{ github.event.inputs.from-slash-command == 'false' && github.event.inputs.comment-id != '' }}
echo "edit-mode=$([ ${should_replace} == 'true' ] && echo 'replace' || echo 'append')" >> $GITHUB_OUTPUT
- name: Append 'starting' notification to comment
id: create-or-update-comment
uses: peter-evans/create-or-update-comment@v4
with:
edit-mode: ${{ steps.initial-edit-mode.outputs.edit-mode }}
comment-id: ${{ github.event.inputs.comment-id }}
issue-number: ${{ github.event.inputs.issue-number }}
body: |
${{ github.event.inputs.prepend-text }}
> [Starting test job...](https://github.com/${{github.repository}}/actions/runs/${{github.run_id}})
> ...
- name: Create requirements.txt
run: echo '${{ env.PIP_URL }}' > requirements.txt
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.10"
cache: 'pip'
- name: Install uv
uses: astral-sh/setup-uv@v4
with:
version: ">=0.4.30"
- name: Install plugin
id: plugin-install
run: |
uv tool install ${{ env.PIP_URL }} 2>&1 | tee install-output.txt
echo "failed=${PIPESTATUS[0]}" >> $GITHUB_ENV
- name: Create installation failure log
if: steps.plugin-install.outputs.failed == '1'
run: |
echo "JOB_OUTPUT<<EOF" >> $GITHUB_ENV
echo "melty-bot % uv tool install ${{ env.PIP_URL }}" >> $GITHUB_ENV
cat install-output.txt >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
- name: Abort if installation failed
if: steps.plugin-install.outputs.failed == '1'
uses: actions/github-script@v7
with:
script: |
core.setFailed('Plugin installation failed')
- name: Print plugin help
id: plugin-help
run: |
${{ env.PLUGIN_NAME }} --help 2>&1 | tee help-output.txt
- name: Print plugin version
id: plugin-version
continue-on-error: true
run: |
${{ env.PLUGIN_NAME }} --version | tee version-output.txt
- name: Print plugin about
id: plugin-about
continue-on-error: true
run: |
${{ env.PLUGIN_NAME }} --about --format=json | tee about-result.json
- name: Print plugin markdown
id: plugin-markdown
continue-on-error: true
run: |
${{ env.PLUGIN_NAME }} --about --format=markdown | tee markdown-result.md
- name: Print discovery output
id: plugin-catalog
continue-on-error: true
run: |
${{ env.PLUGIN_NAME }} --discover | tee catalog.json
# Generates the JOB_OUTPUT env var, accessible via '${{ env.JOB_OUTPUT }}''
# Ref: https://trstringer.com/github-actions-multiline-strings/
- name: Process job output
if: steps.plugin-install.outputs.failed == '0'
run: |
echo "JOB_OUTPUT<<EOF" >> $GITHUB_ENV
if [ -s markdown-result.md ]; then
echo -e "<details><summary>Auto-generated README.md</summary>\n" >> $GITHUB_ENV
cat markdown-result.md >> $GITHUB_ENV
echo -e "\n</details>" >> $GITHUB_ENV
fi
if [ -s version-output.txt ]; then
echo "<details><summary>Version info</summary>" >> $GITHUB_ENV
echo -e "\n\`\`\`" >> $GITHUB_ENV
cat version-output.txt >> $GITHUB_ENV
echo -e "\`\`\`\n" >> $GITHUB_ENV
echo "</details>" >> $GITHUB_ENV
fi
echo "<details><summary>Usage info</summary>" >> $GITHUB_ENV
echo -e "\n\`\`\`" >> $GITHUB_ENV
echo "melty-bot % ${{ env.PLUGIN_NAME }} --help" >> $GITHUB_ENV
cat help-output.txt >> $GITHUB_ENV
echo -e "\`\`\`\n" >> $GITHUB_ENV
echo "</details>" >> $GITHUB_ENV
echo "<details><summary>Detected capabilities</summary>" >> $GITHUB_ENV
echo -e "\n" >> $GITHUB_ENV
if grep -q -e "--discover" help-output.txt; then
echo "> - ✅ 'discover'" >> $GITHUB_ENV
else
echo "> - ❌ 'discover'" >> $GITHUB_ENV
fi
if grep -q -e "--catalog" help-output.txt; then
echo "> - ✅ 'catalog'" >> $GITHUB_ENV
elif grep -q -e "--properties" help-output.txt; then
echo "> - ❌ 'catalog'" >> $GITHUB_ENV
echo "> - ✅ 'properties'" >> $GITHUB_ENV
else
echo "> - ❌ 'catalog'" >> $GITHUB_ENV
echo "> - ❌ 'properties'" >> $GITHUB_ENV
fi
if grep -q -e "--state" help-output.txt; then
echo "> - ✅ 'state'" >> $GITHUB_ENV
else
echo "> - ❌ 'state'" >> $GITHUB_ENV
fi
if grep -q -e "--about" help-output.txt; then
echo "> - ✅ 'about'" >> $GITHUB_ENV
else
echo "> - ❌ 'about'" >> $GITHUB_ENV
fi
echo -e "\n</details>\n" >> $GITHUB_ENV
if [ -s about-result.json ]; then
echo "<details><summary>JSON Metadata</summary>" >> $GITHUB_ENV
echo -e "\n\`\`\`json" >> $GITHUB_ENV
cat about-result.json >> $GITHUB_ENV
echo -e "\`\`\`\n" >> $GITHUB_ENV
echo "</details>" >> $GITHUB_ENV
fi
if [ -s catalog.json ]; then
echo "<details><summary>Discovered streams</summary>" >> $GITHUB_ENV
echo -e "\n" >> $GITHUB_ENV
cat catalog.json | jq --raw-output '.streams[] | (.tap_stream_id // .stream ) | "- `\(.)`"' >> $GITHUB_ENV
echo -e "\n" >> $GITHUB_ENV
echo "</details>" >> $GITHUB_ENV
fi
echo "EOF" >> $GITHUB_ENV
- name: Append summary output
uses: peter-evans/create-or-update-comment@v4
if: always()
with:
comment-id: ${{ steps.create-or-update-comment.outputs.comment-id }}
body: |
> Job completed.
${{ env.JOB_OUTPUT }}
- name: Add reaction (success)
if: github.event.inputs.from-slash-command == 'true'
uses: peter-evans/create-or-update-comment@v4
with:
token: ${{ secrets.MELTYBOT_GITHUB_AUTH_TOKEN }}
repository: ${{ github.event.inputs.repository }}
comment-id: ${{ github.event.inputs.comment-id }}
reaction-type: hooray
- name: Add reaction (failure)
uses: peter-evans/create-or-update-comment@v4
if: failure() && (github.event.inputs.from-slash-command == 'true')
with:
token: ${{ secrets.MELTYBOT_GITHUB_AUTH_TOKEN }}
repository: ${{ github.event.inputs.repository }}
comment-id: ${{ github.event.inputs.comment-id }}
reaction-type: confused