Skip to content

Commit

Permalink
Merge pull request #79 from jimustafa/update-checks
Browse files Browse the repository at this point in the history
update checks
  • Loading branch information
rougier authored Nov 9, 2021
2 parents 9535515 + b67f73c commit 3a87fd1
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 6 deletions.
8 changes: 2 additions & 6 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
8 changes: 8 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Expand Down
20 changes: 20 additions & 0 deletions check-links.py
Original file line number Diff line number Diff line change
@@ -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)
10 changes: 10 additions & 0 deletions check-num-pages.sh
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions requirements/requirements.in
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
bump2version
cartopy==0.19.0.post1
matplotlib==3.4.2
pdfx
pip-tools
pre-commit
scipy
Expand Down
16 changes: 16 additions & 0 deletions requirements/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 3a87fd1

Please sign in to comment.