Background
I'm maintaining a forked repository that contains a LaTeX project. The README.md
contains a .png
preview of the .pdf
compiled from the example .tex
file included in the repo. I often forget to update the .png
version using the following ImageMagick command:
magick convert -density 1200 -background white -alpha off Twenty-Seconds-Icons_cv.pdf -quality 90 Twenty-Seconds-Icons_cv.png
Thus I would like to automate this process using GitHub Actions.
Workflow
I think the main.yml
file should look something like this, however, I don't fully understand what I am doing.
name: PDF to PNG
on:
push:
branches:
- kaspar
pull_request:
branches:
- kaspar
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Install ImageMagick
run: sudo apt install imagemagick # Seems to work and already be included with ubuntu-latest...
- name: Convert PDF to PNG
run: # How?
- name: Commit the updated PNG
run: # How?
Output:
Run sudo apt install imagemagick
sudo apt install imagemagick
shell: /usr/bin/bash -e {0}
WARNING: apt does not have a stable CLI interface. Use with caution in scripts.
Reading package lists...
Building dependency tree...
Reading state information...
imagemagick is already the newest version (8:6.9.10.23+dfsg-2.1ubuntu11.2).
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
Questions
run:
; is this true?.pdf
file in the repo from inside the GitHub Actions Ubuntu machine?.png
file, is there a ~
directory?.png
file generated by ImageMagick to the repo?git commit <file> -m "updated png version of the CV"
work?I figured out a solution to my problem:
name: PDF to PNG
on:
push:
branches:
- kaspar
pull_request:
branches:
- kaspar
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Install ghostscript
run: sudo apt install ghostscript
- name: Change ImageMagick security policy
run: |
DQT='"'
SRC="rights=${DQT}none${DQT} pattern=${DQT}PDF${DQT}"
RPL="rights=${DQT}read\|write${DQT} pattern=${DQT}PDF${DQT}"
sudo sed -i "s/$SRC/$RPL/" /etc/ImageMagick-6/policy.xml
- name: Convert PDF to PNG
run: convert -density 900 -background white -alpha off Twenty-Seconds-Icons_cv.pdf -quality 90 Twenty-Seconds-Icons_cv.png
- name: Commit PNG
id: commit
run: |
git config --local user.email "action[bot]@github.com"
git config --local user.name "github-actions[bot]"
git add Twenty-Seconds-Icons_cv.png
if [-z "$(git status --porcelain)"]; then
echo "::set-output name=push::false"
else
git commit -m "[bot] updated Twenty-Seconds-Icons_cv.png"
echo "::set-output name=push::true"
fi
shell: bash
- name: Push Commit
if: steps.commit.outputs.push == 'true'
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.SECRET_TOKEN }}