-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaction.yml
More file actions
310 lines (270 loc) · 10.9 KB
/
action.yml
File metadata and controls
310 lines (270 loc) · 10.9 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
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
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
name: Poe Slash Command Processor
description: |
Executes a PoeThePoet command. Designed to be used in slash commands, and can auto-commit changes back to the PR's branch.
branding:
icon: check-circle
color: blue
inputs:
command:
description: "Poe command to run. If not provided, we'll infer the command from the body of the specified comment-id."
required: false
pr:
description: "PR Number"
required: false
comment-id:
description: "Comment ID (optional, for reply chaining)"
required: false
github-token:
description: "GitHub Token. Required for CI to run after commits are pushed."
required: false
no-commit:
description: "Disable auto-commit step"
required: false
default: "false"
start-message:
description: "Message to include in the start comment"
required: false
default: ""
success-message:
description: "Message to include in the success comment"
required: false
default: ""
failure-message:
description: "Message to include in the failure comment"
required: false
default: ""
runs:
using: "composite"
steps:
- name: Resolve poe command
id: resolve-command
shell: bash
env:
GH_TOKEN: ${{ inputs.github-token }}
run: |
set -euo pipefail
if [[ "${{ inputs.command }}" ]]; then
# Command was provided explicitly
echo "Using command from input: ${{ inputs.command }}"
command="${{ inputs.command }}"
# Command was not provided, so we need to infer it from the comment body
elif [[ -z "${{ inputs.comment-id }}" ]]; then
echo "No 'command' or 'comment-id' input was provided. At least one is required."
exit 1
else
COMMENT_JSON=$(gh api repos/${{ github.repository }}/issues/comments/${{ inputs.comment-id }})
echo "::group::👀 Debug Comment JSON"
echo $COMMENT_JSON | jq
echo "::endgroup::"
command=$(echo $COMMENT_JSON | jq -r .body)
if [[ -z "$command" ]]; then
echo "No command found in comment body."
exit 1
fi
echo "Using command from comment body: $command"
fi
# Take just the first line of the command
command=$(echo "$command" | head -n 1)
# Remove 'poe' or '/poe' prefix from command
command=$(echo "$command" | sed -E '1s/^(\/?poe )?//')
# Remove leading and trailing whitespace
command=$(echo "$command" | xargs)
echo "Resolved command: ${command}"
echo command="$command" >> $GITHUB_OUTPUT
- name: Get PR info
if: inputs.pr
id: pr-info
shell: bash
run: |
PR_JSON=$(gh api repos/${{ github.repository }}/pulls/${{ inputs.pr }})
echo "::group::👀 Debug PR JSON"
echo $PR_JSON | jq
echo $PR_JSON | jq -r .head.repo.full_name
echo $PR_JSON | jq -r .head.ref
echo "::endgroup::"
echo repo=$(echo $PR_JSON | jq -r .head.repo.full_name) >> $GITHUB_OUTPUT
echo branch=$(echo $PR_JSON | jq -r .head.ref) >> $GITHUB_OUTPUT
env:
GH_TOKEN: ${{ inputs.github-token }}
- name: Generate run link
id: vars
shell: bash
run: echo "run-url=https://github.com/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID" >> "$GITHUB_OUTPUT"
- name: Post job start comment
if: inputs.pr || inputs.comment-id
uses: peter-evans/create-or-update-comment@v4
id: comment-start
with:
comment-id: ${{ inputs.comment-id }}
issue-number: ${{ inputs.pr }}
body: |
> ${{ inputs.start-message || format('**Running `poe {0}`...**', steps.resolve-command.outputs.command) }}
>
> [Link to job logs.](${{ steps.vars.outputs.run-url }})
>
- name: Checkout PR
if: inputs.pr
uses: actions/checkout@v4
with:
ref: ${{ steps.pr-info.outputs.branch }}
submodules: true # Initialize submodules if needed
repository: ${{ steps.pr-info.outputs.repo }}
token: ${{ inputs.github-token }}
- name: Checkout default branch (no existing PR)
if: "! inputs.pr"
uses: actions/checkout@v4
with:
repository: ${{ steps.pr-info.outputs.repo }}
token: ${{ inputs.github-token }}
- name: Fetch tool versions
id: tool-versions
continue-on-error: true
uses: marocchino/tool-versions-action@v1
- name: Set up Python
uses: actions/setup-python@v5
with:
# Use the provided Python version or the default one
python-version: ${{ steps.tool-versions.outputs.python || '3.11' }}
- name: Install uv
uses: astral-sh/setup-uv@v5
with:
# Set up the provided version or the latest if not specified
version: ${{ steps.tool-versions.outputs.uv || 'latest' }}
# Use the provided Python version or the default one
python-version: ${{ steps.tool-versions.outputs.python || '3.11' }}
- name: Install Poetry
uses: Gr1N/setup-poetry@v9
with:
# Set up the provided version or the latest if not specified
poetry-version: ${{ steps.tool-versions.outputs.poetry || '' }}
- name: Install poethepoet
shell: bash
# Currently, we just install the latest version of poethepoet.
# This should be fine (for now) since Poe changes are generally
# backward compatible.
run: uv tool install poethepoet
- name: Install dependencies
shell: bash
run: |
poe install || echo "Failed 'poe install' or the task does not exist. Continuing..."
- name: Print Pre-Run Marker
# Pre-run and post-run markers just help the reader find the relevant
# sections in the logs.
shell: bash
run: |
# Printing Pre-Run Marker
echo "------------------------------------"
echo "------------------------------------"
echo "-- Running Command: 'poe ${{ steps.resolve-command.outputs.command }}' --"
echo "------------------------------------"
echo "------------------------------------"
- name: Run `poe ${{ steps.resolve-command.outputs.command }}`
shell: bash
id: run-poe-task
run: |
set -euo pipefail
set +e # Temporarily disable exit on error to capture exit code
poe ${{ steps.resolve-command.outputs.command }}
EXIT_CODE=$?
set -e # Re-enable exit on error
# Printing Post-Run Marker
echo "------------------------------------"
echo "------------------------------------"
echo "-- Execution Completed: 'poe ${{ steps.resolve-command.outputs.command }}' --"
echo "------------------------------------"
echo "------------------------------------"
if [ -s "$GITHUB_STEP_SUMMARY" ]; then
echo "Step summary file exists and is non-empty: $GITHUB_STEP_SUMMARY"
# Use multiline output syntax for GitHub Actions
{
echo "has-summary=true"
echo "summary-text<<__POE_EOF__"
cat "$GITHUB_STEP_SUMMARY"
echo "__POE_EOF__"
} >> "$GITHUB_OUTPUT"
else
echo "No step summary content found."
echo "has-summary=false" >> $GITHUB_OUTPUT
echo "summary-text=" >> $GITHUB_OUTPUT
fi
exit "$EXIT_CODE"
- name: Auto commit changes
id: auto-commit
uses: stefanzweifel/git-auto-commit-action@v5
if: >
inputs.no-commit != 'true'
&& inputs.pr
with:
commit_message: "Auto-committed changes from Poe command `${{ steps.resolve-command.outputs.command }}`"
commit_user_name: Octavia Squidington III
commit_user_email: octavia-squidington-iii@users.noreply.github.com
- name: Append success comment
if: >
steps.comment-start.outputs.comment-id
&& steps.auto-commit.outputs.changes_detected == 'true'
uses: peter-evans/create-or-update-comment@v4
with:
comment-id: ${{ steps.comment-start.outputs.comment-id }}
reactions: hooray
body: >
🤖 Auto-commit successful: ${{ steps.auto-commit.outputs.commit_hash }}
- name: Append success comment with output
if: >
steps.comment-start.outputs.comment-id
uses: peter-evans/create-or-update-comment@v4
with:
comment-id: ${{ steps.comment-start.outputs.comment-id }}
reactions: "+1"
body: |
> ${{ inputs.success-message || format(' 🟦 Poe command `{0}` completed successfully.', steps.resolve-command.outputs.command) }}
${{ steps.run-poe-task.outputs.has-summary == 'true' && format('
<details><summary>✳️ Show/Hide Summary Output</summary>
{0}
</details>', steps.run-poe-task.outputs.summary-text) || '' }}
- name: Append failure comment
if: failure() && steps.comment-start.outputs.comment-id
uses: peter-evans/create-or-update-comment@v4
with:
comment-id: ${{ steps.comment-start.outputs.comment-id }}
reactions: confused
body: |
> ${{ inputs.failure-message || format('❌ Poe command `{0}` failed. Please inspect the logs.', steps.resolve-command.outputs.command) }}
${{ steps.run-poe-task.outputs.has-summary == 'true' && format('
<details><summary>✴️ Show/Hide Summary Output</summary>
{0}
</details>', steps.run-poe-task.outputs.summary-text) || '' }}
# Create a new PR if no PR was provided
- name: Create Pull Request
if: >
inputs.no-commit != 'true'
&& ! inputs.pr
id: create-pr
uses: peter-evans/create-pull-request@v7
with:
title: "Auto-generated PR: `poe ${{ steps.resolve-command.outputs.command }}`"
commit-message: "Auto-committed changes from `poe ${{ steps.resolve-command.outputs.command }}`"
body: |
## Output of `poe ${{ steps.resolve-command.outputs.command }}`
This PR was automatically generated by the Poe GitHub Action.
It contains the output of the command `${{ steps.resolve-command.outputs.command }}`.
Please review the changes and consider merging them if they are acceptable.
[Link to job logs.](${{ steps.vars.outputs.run-url }})
branch: auto-commit/poe-processor-${{ github.run_id }}
draft: true
commit-user-name: Octavia Squidington III
commit-user-email: octavia-squidington-iii@users.noreply.github.com
token: ${{ inputs.github-token }}
- name: Append PR link to comment
if: >
steps.comment-start.outputs.comment-id
&& inputs.no-commit != 'true'
&& ! inputs.pr
&& steps.create-pr.outputs.pull-request-url
uses: peter-evans/create-or-update-comment@v4
with:
comment-id: ${{ steps.comment-start.outputs.comment-id }}
body: |
>
> 🚀 PR Created:
>
> - ${{ steps.create-pr.outputs.pull-request-url }}