-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
77 lines (69 loc) · 2.75 KB
/
component-image.yml
File metadata and controls
77 lines (69 loc) · 2.75 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
name: Component Image Generator
on:
issue_comment:
types: [created]
permissions:
pull-requests: write
jobs:
prepare:
name: Prepare
if: github.event.issue.pull_request && startsWith(github.event.comment.body, '@esphomebot generate image')
runs-on: ubuntu-latest
outputs:
name: ${{ steps.get_component.outputs.name }}
name_lower: ${{ steps.get_component.outputs.name_lower }}
comment_id: ${{ steps.create-comment.outputs.result }}
steps:
- name: Comment
id: create-comment
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
with:
script: |
const result = await github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: `@${context.actor} Generating image...`
})
return result.data.id
- name: Get Component name
id: get_component
env:
COMMENT_BODY: ${{ github.event.comment.body }}
run: |
# Extract component name using bash parameter expansion (no external commands)
component="${COMMENT_BODY#@esphomebot generate image }"
# Validate component name: only lowercase alphanumeric and underscores
if [[ "$component" =~ ^[a-z0-9_]+$ ]]; then
echo "name=$component" >> $GITHUB_OUTPUT
echo "name_lower=${component,,}" >> $GITHUB_OUTPUT
else
echo "::error::Invalid component name. Must contain only lowercase letters, numbers, and underscores."
exit 1
fi
generate:
name: Generate
if: github.event.issue.pull_request && startsWith(github.event.comment.body, '@esphomebot generate image')
runs-on: ubuntu-latest
needs: prepare
steps:
- name: Generate
uses: esphome/component-image-generator@d0d2a195b500e8c37c17f299ff6b90933f2197cf # v1.0.0
with:
component: ${{ needs.prepare.outputs.name }}
- name: Upload
uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7.0.0
id: upload-artifact
with:
name: ${{ needs.prepare.outputs.name }}
path: ${{ needs.prepare.outputs.name_lower }}.svg
- name: Update Comment
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
with:
script: |
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: ${{ needs.prepare.outputs.comment_id }},
body: `@${context.actor} Here is the image for the component ${{ steps.upload-artifact.outputs.artifact-url }}`
})