Add buildPDF.yml - attempt 1 #1
This file contains hidden or 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: Build Guide PDF | ||
| on: | ||
| page_build: # Triggers after GitHu Pages finishes buildng/deploying | ||
| jobs: | ||
| post-deploy: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Add dependencies | ||
| run: | | ||
| sudo apt-get update | ||
| sudo apt-get install -y wkhtmltopdf curl sed pdfunite grep | ||
| - name: Verify installation | ||
| run: wkhtmltopdf --version | ||
| - name: Build PDF | ||
| run: | | ||
| # From https://gist.github.com/hamoid/a9b0bdc1c96e6e6995cfad6f4b069279 | ||
| filename="openrndr-guide" | ||
| domain="guide.openrndr.org" | ||
| path="" # /some/folder/ if the guide is not located at / | ||
| mkdir -p ~/manual | ||
| cd ~/manual || exit | ||
| # curl downloads the index page of the website | ||
| # grep extracts the <nav> ... </nav> section | ||
| # sed(1) injects a line break in front of every URL and adds the full domain | ||
| # sed(2) deletes from each line the " character and everything that follows, leaving the clean URL | ||
| # tail deletes the first line, which contains a lonely <nav> tag | ||
| urlstr=$(curl -s "https://$domain$path" | grep -o -E '<nav .*</nav>' | sed "s/href=\"\//href=\"\nhttps:\/\/$domain\//g" | sed "s/\".*//g" | tail +2) | ||
| # convert a long string into an array | ||
| urls=($urlstr) | ||
| # count how many items in the array | ||
| length=${#urls[@]} | ||
| echo "Found $length URLs" | ||
| # one by one create NNNN.pdf files from each URL | ||
| for (( i=0; i<${length}; i++ )); | ||
| do | ||
| echo "# Page $i of $length" | ||
| padded=$(printf "%04d" $i) | ||
| wkhtmltopdf ${urls[$i]} $padded.pdf | ||
| done | ||
| date=$(date +"%F") | ||
| # finally join all the PDF files into one | ||
| pdfunite *.pdf ~/$filename-$date.pdf | ||
| - name: Upload Artifact | ||
| uses: actions/upload-artifact@v2 | ||
| with: | ||
| name: generated-pdf | ||
| path: ~/$filename-$date.pdf | ||