From 244900b1421947ff16588d48b5c43afbd43da849 Mon Sep 17 00:00:00 2001 From: Bryan Elliott Date: Fri, 29 Oct 2021 13:12:00 -0400 Subject: [PATCH] Rewrite buildscript for broader OS support (#2) This commit adds support for github actions (to validate font build upon commit to main branch). It also brings wider OS support (for example, a fresh install of ImageMagick on Windows uses the new magick command instead of convert) and early failure detection (e.g., if there's no Python installation). --- .github/workflows/build.yml | 33 +++++++++++++++++++++++ .gitignore | 1 + README.md | 4 --- build.sh | 52 +++++++++++++++++++++++++++++++------ requirements.txt | 3 +++ 5 files changed, 81 insertions(+), 12 deletions(-) create mode 100644 .github/workflows/build.yml create mode 100644 requirements.txt diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..c91e6d2 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,33 @@ +# This is a basic workflow to help you get started with Actions + +name: Build Font + +# Controls when the workflow will run +on: + # Triggers the workflow on push or pull request events but only for the main branch + push: + branches: [ main ] + pull_request: + branches: [ main ] + + # Allows you to run this workflow manually from the Actions tab + workflow_dispatch: + +# A workflow run is made up of one or more jobs that can run sequentially or in parallel +jobs: + # This workflow contains a single job called "build" + build: + # The type of runner that the job will run on + runs-on: ubuntu-latest + + # Steps represent a sequence of tasks that will be executed as part of the job + steps: + # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it + - uses: actions/checkout@v2 + + # installs python3 + - uses: actions/setup-python@v2.2.2 + + # Runs a set of commands using the runners shell + - name: Run a multi-line script + run: ./build.sh diff --git a/.gitignore b/.gitignore index b210c60..e8df9d7 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ backups/* logs/* *.otf +src/pysilfont diff --git a/README.md b/README.md index 2880eeb..3b9e5e5 100644 --- a/README.md +++ b/README.md @@ -11,10 +11,6 @@ An example of text can be seen here: ### Prerequisites * have python3 and imagemagick installed (commands vary per OS) -* Install python scripts: - * `pip3 install fontmake` - * `pip3 install git+https://github.com/silnrsi/pysilfont` - * `python3 -m pip install fonttools[ufo,lxml,woff,unicode]` ### Run builder diff --git a/build.sh b/build.sh index eb86771..f70879c 100755 --- a/build.sh +++ b/build.sh @@ -1,21 +1,57 @@ #!/usr/bin/env bash +# Detect ImageMagick - newer versions use the command "magick" instead of "convert" +IMAGEMAGICK="$(which magick 2>/dev/null)" +if [[ -z "$IMAGEMAGICK" ]]; then + IMAGEMAGICK="$(which convert 2>/dev/null)" +fi + +# ImageMagick is not needed for primary font generation +if ! "$IMAGEMAGICK" wizard: /dev/null 2>/dev/null; then + echo "No ImageMagick available; skipping demo image generation" + IMAGEMAGICK="" +fi + +# Detect Python; prefer python 3.x +PYTHON="$(which python3 2>/dev/null)" +if [[ -z "$PYTHON" ]]; then + PYTHON="$(which python 2>/dev/null)" +fi + +if [[ -z "$PYTHON" ]]; then + echo "No Python installed. Aborting." >&2 + exit -1 +fi + +PSFNORMALIZE="$(which psfnormalize 2>/dev/null)" + +# If psfnormalize isn't present, try to install it, and the other req's +if [[ -z "$PSFNORMALIZE" ]]; then + rm -rf ~/work/mawkin-sans/mawkin-sans/src/pysilfont > /dev/null 2>&1 + "$PYTHON" -m pip install -r requirements.txt +fi + set -e psfnormalize mawkin_sans.ufo -fontmake --validate-ufo --autohint --ufo-paths mawkin_sans.ufo --output otf --output-path mawkin_sans.otf +"$PYTHON" -m fontmake --validate-ufo --autohint --ufo-paths mawkin_sans.ufo --output otf --output-path mawkin_sans.otf -convert -background white -fill black \ - -font './mawkin_sans.otf' -pointsize 200 label:"Mawkin\n. .Sans" \ - title.png +if [[ -n "$IMAGEMAGICK" ]]; then + echo "Generating title.png" + "$IMAGEMAGICK" -background white -fill black \ + -font './mawkin_sans.otf' -pointsize 200 label:"Mawkin\n. .Sans" \ + title.png -convert -background white -fill black \ - -font './mawkin_sans.otf' -pointsize 60 label:"the last metroid\n. .is in captivity\nthe galaxy\n. .is at peace\n\n\nMawkin\n. .Sans" \ - demo.png + echo "Generating demo.png" + "$IMAGEMAGICK" -background white -fill black \ + -font './mawkin_sans.otf' -pointsize 60 label:"the last metroid\n. .is in captivity\nthe galaxy\n. .is at peace\n\n\nMawkin\n. .Sans" \ + demo.png +fi +echo "Generating mawkin_sans.woff2" # Convert OTF to WOFF2 for webfont -python3 <