feat: contentlayer #458
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: Icon Review | |
on: | |
pull_request_target: | |
paths: | |
- 'icons/*.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@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 | |
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@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 | |
with: | |
fetch-depth: 0 | |
path: main | |
persist-credentials: false | |
- name: Review SVG files 🔍 | |
working-directory: main | |
run: | | |
files=$(git diff --no-index ../main ../fork --diff-filter=ACMRTUX --name-only | grep '.svg$') | |
filesCount=$(echo "$files" | wc -l) | |
npx [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 imageURL = "${{ env.image_url }}"; | |
const image = `<img src="${imageURL}" alt="Generated preview" />`; | |
let preview = ""; | |
if (parseInt("${{ env.svg_files_count }}") > 10) { | |
preview = `<details><summary>🏞️ <b>Generated preview</b></summary><br/>${image}</details>`; | |
} else { | |
preview = image; | |
} | |
const comment = ` | |
## Preview | |
Thank you for creating a pull request. This preview shows you how your changes 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.lucode.ar/material-extensions/vscode-material-icon-theme/pull/${{ github.event.pull_request.number }}). | |
You can find more information on how to contribute in the [contribution guidelines](https://github.com/material-extensions/vscode-material-icon-theme/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: fc | |
with: | |
issue-number: ${{ github.event.pull_request.number }} | |
comment-author: 'github-actions[bot]' | |
body-includes: This preview shows you how your changes will look on the different themes | |
- name: Post or update comment in PR ✍️ | |
uses: peter-evans/create-or-update-comment@71345be0265236311c031f5c7866368bd1eff043 # v4.0.0 | |
with: | |
comment-id: ${{ steps.fc.outputs.comment-id }} | |
issue-number: ${{ github.event.pull_request.number }} | |
body: | | |
${{ env.comment }} | |
edit-mode: replace |