diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index be710ce..e80a9e2 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -51,13 +51,9 @@ jobs: cp -r fonts/ /usr/share/fonts/ fc-cache make all - - name: Check layouts + - name: Run checks run: | - set -x - [[ "$(pdfinfo cheatsheets.pdf | grep Pages | awk '{print $2}')" == "2" ]] || exit 1 - [[ "$(pdfinfo handout-tips.pdf | grep Pages | awk '{print $2}')" == "1" ]] || exit 1 - [[ "$(pdfinfo handout-beginner.pdf | grep Pages | awk '{print $2}')" == "1" ]] || exit 1 - [[ "$(pdfinfo handout-intermediate.pdf | grep Pages | awk '{print $2}')" == "1" ]] || exit 1 + make check - uses: actions/upload-artifact@v2 if: ${{ always() }} with: diff --git a/Makefile b/Makefile index 466e681..2b7c133 100644 --- a/Makefile +++ b/Makefile @@ -36,6 +36,14 @@ handouts: convert -density 150 handout-beginner.pdf handout-beginner.png convert -density 150 handout-intermediate.pdf handout-intermediate.png +.PHONY: check +check: + ./check-num-pages.sh cheatsheets.pdf 2 + ./check-num-pages.sh handout-tips.pdf 1 + ./check-num-pages.sh handout-beginner.pdf 1 + ./check-num-pages.sh handout-intermediate.pdf 1 + ./check-links.py cheatsheets.pdf + .PHONY: fonts fonts: make -C fonts/ diff --git a/check-links.py b/check-links.py new file mode 100755 index 0000000..3a3e797 --- /dev/null +++ b/check-links.py @@ -0,0 +1,20 @@ +#!/usr/bin/env python +import sys + +import pdfx + + +pdf = pdfx.PDFx(sys.argv[1]) + +refs = [ref for ref in pdf.get_references() if ref.reftype == 'url'] + +status_codes = list(map(lambda ref: pdfx.downloader.get_status_code(ref.ref), refs)) + +broken_links = [refs[idx].ref for idx in range(len(refs)) if status_codes[idx] != 200] + +# it seems that Twitter does not respond well to the link checker and throws a 400 +if all(['twitter.com' in url for url in broken_links]): + sys.exit(0) +else: + print('Broken links:', broken_links) + sys.exit(1) diff --git a/check-num-pages.sh b/check-num-pages.sh new file mode 100755 index 0000000..06d01b4 --- /dev/null +++ b/check-num-pages.sh @@ -0,0 +1,10 @@ +#!/bin/bash +# +# Check that a given pdf has a certain number of pages. +# Usage: +# check-num-pages.sh [pdffile] [num_pages] + +set -x +pdffile=$1 +num_pages=$2 +[[ "$(pdfinfo $pdffile | grep Pages | awk '{print $2}')" == "$num_pages" ]] || exit 1 diff --git a/requirements/requirements.in b/requirements/requirements.in index 930f75e..6476718 100644 --- a/requirements/requirements.in +++ b/requirements/requirements.in @@ -1,6 +1,7 @@ bump2version cartopy==0.19.0.post1 matplotlib==3.4.2 +pdfx pip-tools pre-commit scipy diff --git a/requirements/requirements.txt b/requirements/requirements.txt index b1a0f4f..ab7607c 100644 --- a/requirements/requirements.txt +++ b/requirements/requirements.txt @@ -12,10 +12,18 @@ bump2version==1.0.1 # via -r requirements.in cartopy==0.19.0.post1 # via -r requirements.in +cffi==1.15.0 + # via cryptography cfgv==3.2.0 # via pre-commit +chardet==4.0.0 + # via + # pdfminer.six + # pdfx click==8.0.0 # via pip-tools +cryptography==35.0.0 + # via pdfminer.six cycler==0.10.0 # via matplotlib distlib==0.3.1 @@ -40,6 +48,10 @@ numpy==1.19.5 # cartopy # matplotlib # scipy +pdfminer.six==20201018 + # via pdfx +pdfx==1.4.1 + # via -r requirements.in pep517==0.10.0 # via pip-tools pillow==8.1.2 @@ -48,6 +60,8 @@ pip-tools==6.1.0 # via -r requirements.in pre-commit==2.11.1 # via -r requirements.in +pycparser==2.20 + # via cffi pyparsing==2.4.7 # via matplotlib pyshp==2.1.3 @@ -65,6 +79,8 @@ six==1.15.0 # cycler # python-dateutil # virtualenv +sortedcontainers==2.4.0 + # via pdfminer.six toml==0.10.2 # via # pep517