feat: ✨ payload pack #88
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: 🏞️ » generate preview image | |
on: | |
pull_request_target: | |
paths: | |
- "icons/*.svg" | |
- "icons-lc/**/*.svg" | |
permissions: | |
contents: read | |
jobs: | |
icon-review: | |
name: Icon Review | |
runs-on: ubuntu-latest | |
env: | |
TARGET_BRANCH: ${{ github.event.pull_request.base.ref }} | |
permissions: | |
pull-requests: write | |
steps: | |
- name: 📥 Checkout Fork | |
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 | |
with: | |
ref: ${{ github.event.pull_request.head.ref }} | |
repository: ${{ github.event.pull_request.head.repo.full_name }} | |
fetch-depth: 0 | |
path: fork | |
persist-credentials: false | |
- name: 📥 Checkout Original | |
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 | |
with: | |
fetch-depth: 0 | |
path: main | |
persist-credentials: false | |
- name: 🔧 Setup Bun | |
uses: oven-sh/setup-bun@4bc047ad259df6fc24a6c9b0f9a0cb08cf17fbe5 # v2 | |
with: | |
bun-version-file: "main/.bun-version" | |
- name: 🔍 Review SVG files | |
working-directory: main | |
run: | | |
files=$(git diff --no-index ../main ../fork --diff-filter=ACMRTUX --name-only | grep '^\.\./fork/**/.*\.svg$') | |
filesCount=$(echo "$files" | wc -l) | |
bunx --bun [email protected] --bigIcon ${files} | |
echo svg_files_count=$filesCount >> $GITHUB_ENV | |
- name: ⬆️ Upload PNG | |
env: | |
IMAGE_UPLOAD: ${{ secrets.IMAGE_UPLOAD }} | |
id: upload | |
run: | | |
IMAGE_URL=$(curl --location 'https://freeimage.host/json' --form 'source=@"./main/preview.png"' --form 'type="file"' --form 'action="upload"' --form 'auth_token="${{env.IMAGE_UPLOAD}}"' | jq -r '.image.url') | |
echo image_url=$IMAGE_URL >> $GITHUB_ENV | |
- name: 📃 Generate text | |
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
script: | | |
const iconsCount = parseInt("${{ env.svg_files_count }}"); | |
const imageURL = "${{ env.image_url }}"; | |
const image = `<img src="${imageURL}" alt="Generated preview" />`; | |
const pluralS = iconsCount > 1 ? "s" : ""; | |
let preview = ""; | |
if (iconsCount > 10) { | |
preview = `<details><summary>🏞️ <b>Generated preview</b></summary><br/>${image}</details>`; | |
} else { | |
preview = image; | |
} | |
const comment = ` | |
<!-- Preview generated by GitHub Actions --> | |
## Preview | |
Thank you for creating a pull request. This preview shows you how your icon${pluralS} will look on the different themes: | |
${preview} | |
Check how your icon fits in a 16x16 grid with our Pixel Perfect Checker by following [this link](https://pixp..pages.dev/lucodear/lucodear-icons/pull/${{ github.event.pull_request.number }}). | |
You can find more information on how to contribute in the [contribution guidelines](https://github.com/lucodear/lucodear-icons/blob/main/CONTRIBUTING.md). | |
`; | |
// Write comment to environment variable | |
core.exportVariable('comment', comment); | |
- name: 🕵️ Find comment if exists | |
uses: peter-evans/find-comment@3eae4d37986fb5a8592848f6a574fdf654e61f9e # v3.1.0 | |
id: find-comment | |
with: | |
issue-number: ${{ github.event.pull_request.number }} | |
comment-author: "github-actions[bot]" | |
body-includes: <!-- Preview generated by GitHub Actions --> | |
- name: ✍️ Post or update comment in PR | |
uses: peter-evans/create-or-update-comment@71345be0265236311c031f5c7866368bd1eff043 # v4.0.0 | |
with: | |
comment-id: ${{ steps.find-comment.outputs.comment-id }} | |
issue-number: ${{ github.event.pull_request.number }} | |
body: | | |
${{ env.comment }} | |
edit-mode: replace |