From 182ce76ba2fcd78da3727e005f3d7c8d57b4bffe Mon Sep 17 00:00:00 2001 From: Jesse Hills <3060199+jesserockz@users.noreply.github.com> Date: Wed, 12 Jun 2024 11:08:12 +1200 Subject: [PATCH] [CI] Make action to generate component images (#3925) --- .github/workflows/component-image.yml | 66 +++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 .github/workflows/component-image.yml diff --git a/.github/workflows/component-image.yml b/.github/workflows/component-image.yml new file mode 100644 index 000000000..609a8aa31 --- /dev/null +++ b/.github/workflows/component-image.yml @@ -0,0 +1,66 @@ +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 }} + comment_id: ${{ steps.create-comment.outputs.result }} + steps: + - name: Comment + id: create-comment + uses: actions/github-script@v7.0.1 + 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 + run: |- + comment="${{ github.event.comment.body }}" + component=$(echo $comment | sed -n 's/^@esphomebot generate image //p') + echo "name=$component" >> $GITHUB_OUTPUT + + 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@v1.0.0 + with: + component: ${{ needs.prepare.outputs.name }} + + - name: Upload + uses: actions/upload-artifact@v4.3.3 + id: upload-artifact + with: + name: ${{ needs.prepare.outputs.name }} + path: ${{ needs.prepare.outputs.name }}.svg + + - name: Update Comment + uses: actions/github-script@v7.0.1 + 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 }}` + })