feat: process screenshot with ImageMagic #43
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: main | |
on: | |
push: | |
branches: | |
- main | |
pull_request: | |
workflow_dispatch: | |
jobs: | |
main: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
- name: Build | |
run: | | |
mkdir output | |
mv index.html copy.png favicon.png og.png favicon.ico likely.css likely.js output | |
- name: Make screenshot | |
uses: chuhlomin/webpage-screenshot-action@main | |
with: | |
url: file://${{github.workspace}}/output/index.html | |
mode: page | |
output: screenshot.png | |
width: 1024 | |
height: 768 | |
deviceScaleFactor: 2 | |
- name: Setup Image Magic | |
uses: mfinelli/setup-imagemagick@v2 | |
- name: Round corners and shadow | |
run: | | |
width=$(identify -format "%w" "screenshot.png") | |
height=$(identify -format "%h" "screenshot.png") | |
convert \ | |
screenshot.png \ | |
\( -size ${width}x${height} xc:black -fill white \ | |
-draw "roundRectangle 0,0,${width},${height},20,20" \) \ | |
-alpha Off -compose CopyOpacity -composite \ | |
screenshot.png.temp | |
convert \ | |
screenshot.png.temp \ | |
\( +clone -background black -shadow 25x80+0+16 \) \ | |
-background none \ | |
-reverse -layers merge screenshot.png | |
- name: Upload screenshot | |
uses: actions/upload-artifact@v3 | |
if: github.event_name == 'pull_request' | |
with: | |
name: screenshot | |
path: screenshot.png | |
- name: Commit screenshot (if changed) | |
if: github.event_name == 'push' || github.event_name == 'workflow_dispatch' | |
run: | | |
if (git status --porcelain | grep screenshot.png) | |
then | |
git config user.name github-actions | |
git config user.email github-actions@github.com | |
git add screenshot.png | |
git commit -m "Update screenshot [skip ci]" | |
git push | |
fi | |
- name: Publish | |
uses: cloudflare/wrangler-action@v3.0.2 | |
if: github.event_name == 'push' | |
with: | |
apiToken: ${{ secrets.CF_API_TOKEN }} | |
accountId: ${{ secrets.CF_ACCOUNT_ID }} | |
command: pages deploy output --project-name=timestamp --branch=main --commit-dirty=true |