Skip to content

Commit

Permalink
Update to GF repo tempalte and CI
Browse files Browse the repository at this point in the history
  • Loading branch information
pathumego committed May 31, 2024
1 parent 69f790c commit f53da70
Show file tree
Hide file tree
Showing 17 changed files with 1,787 additions and 10 deletions.
116 changes: 116 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
name: Build font and specimen

on: push

jobs:
build:
name: Build and test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python 3.10
uses: actions/setup-python@v5
with:
python-version: "3.10"
- name: Install sys tools/deps
run: |
sudo apt-get update
sudo apt-get install ttfautohint
sudo snap install yq
- uses: actions/cache@v4
with:
path: ./venv/
key: ${{ runner.os }}-venv-${{ hashFiles('**/requirements*.txt') }}
restore-keys: |
${{ runner.os }}-venv-
- name: gen zip file name
id: zip-name
shell: bash
# Set the archive name to repo name + "-assets" e.g "MavenPro-assets"
run: echo "ZIP_NAME=$(echo '${{ github.repository }}' | awk -F '/' '{print $2}')-fonts" >> $GITHUB_ENV

# If a new release is cut, use the release tag to auto-bump the source files
# - name: Bump release
# if: github.event_name == 'release'
# run: |
# . venv/bin/activate
# SRCS=$(yq e ".sources[]" sources/config.yaml)
# TAG_NAME=${GITHUB_REF/refs\/tags\//}
# echo "Bumping $SRCS to $TAG_NAME"
# for src in $SRCS
# do
# bumpfontversion sources/$src --new-version $TAG_NAME;
# done

- name: Build font
run: make build
- name: Check with fontbakery
run: make test
continue-on-error: true
- name: proof
run: make proof
- name: setup site
run: cp scripts/index.html out/index.html
- name: Deploy
uses: peaceiris/actions-gh-pages@v4
if: ${{ github.ref == 'refs/heads/main' }}
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./out
- name: Archive artifacts
uses: actions/upload-artifact@v4
with:
name: ${{ env.ZIP_NAME }}
path: |
fonts
out
outputs:
zip_name: ${{ env.ZIP_NAME }}

# There are two ways a release can be created: either by pushing a tag, or by
# creating a release from the GitHub UI. Pushing a tag does not automatically
# create a release, so we have to do that ourselves. However, creating a
# release from the GitHub UI *does* push a tag, and we don't want to create
# a new release in that case because one already exists!

release:
name: Create and populate release
needs: build
runs-on: ubuntu-latest
if: contains(github.ref, 'refs/tags/')
env:
ZIP_NAME: ${{ needs.build.outputs.zip_name }}
GH_TOKEN: ${{ github.token }}
steps:
- uses: actions/checkout@v4
- name: Download font artefact files
uses: actions/download-artifact@v4
with:
name: ${{ env.ZIP_NAME }}
path: ${{ env.ZIP_NAME }}
- name: Copy DESCRIPTION.en_us.html to artefact directory
run: cp documentation/DESCRIPTION.en_us.html ${{ env.ZIP_NAME }}/DESCRIPTION.en_us.html
- name: Copy ARTICLE.en_us.html to artefact directory
run: cp documentation/ARTICLE.en_us.html ${{ env.ZIP_NAME }}/ARTICLE.en_us.html
continue-on-error: true
- name: Copy OFL.txt to artefact directory
run: cp OFL.txt ${{ env.ZIP_NAME }}/OFL.txt
- name: Remove proof/fontbakery stuff from release
run: rm -rf ${{ env.ZIP_NAME }}/out
- name: gen release file name
shell: bash
run: echo "RELEASE_ZIP_NAME=$(echo '${{ github.repository }}' | awk -F '/' '{print $2}')-${{github.ref_name}}" >> $GITHUB_ENV
- name: Create release bundle
run: mv ${{ env.ZIP_NAME }} ${{ env.RELEASE_ZIP_NAME }}; zip -r ${{ env.RELEASE_ZIP_NAME }}.zip ${{ env.RELEASE_ZIP_NAME }}
- name: Check for release
id: create_release
run: |
if ! gh release view ${{ github.ref_name }}; then
git show -s --format=%B ${{ github.ref_name }} | tail -n +4 | gh release create ${{ github.ref_name }} -t ${{ github.ref_name }} -F -
fi
- name: Populate release
run: |
gh release upload ${{ github.ref_name }} ${{ env.RELEASE_ZIP_NAME }}.zip --clobber
- name: Set release live
run: |
gh release edit ${{ github.ref_name }} --draft=false
48 changes: 40 additions & 8 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,41 @@
_site/
font.designspace
FontMenuNameDB
.vagrant
/masters
/instances
/build
*~
venv
out
venv-test
build.stamp
proof
fonts
node_modules
package-lock.json
package.json
master_ufo
instance_ufos
.ninja_log
build.ninja

# OS generated files #
######################
.DS_Store
/ttf-build
.DS_Store?
._*
.Spotlight-V100
.Trashes
ehthumbs.db
Thumbs.db

# Autosaved by application when editing
######################
*(تم الحفظ تلقائيًا).*
*(automaticky uloženo).*
*(Automatisch gesichert).*
*(Autosaved).*
*(guardado automáticamente).*
*(enregistré automatiquement).*
*(salvato automaticamente).*
*(自動保存).*
*(자동 저장됨).*
*(Salvo Automaticamente).*
*(Автосохранение).*
*(Otomatik Kaydedildi).*
*(自动存储).*
*(已自動儲存).*
70 changes: 70 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
SOURCES=$(shell python3 scripts/read-config.py --sources )
FAMILY=$(shell python3 scripts/read-config.py --family )
DRAWBOT_SCRIPTS=$(shell ls documentation/*.py)
DRAWBOT_OUTPUT=$(shell ls documentation/*.py | sed 's/\.py/.png/g')

help:
@echo "###"
@echo "# Build targets for $(FAMILY)"
@echo "###"
@echo
@echo " make build: Builds the fonts and places them in the fonts/ directory"
@echo " make test: Tests the fonts with fontbakery"
@echo " make proof: Creates HTML proof documents in the proof/ directory"
@echo " make images: Creates PNG specimen images in the documentation/ directory"
@echo

build: build.stamp

venv: venv/touchfile

venv-test: venv-test/touchfile

customize: venv
. venv/bin/activate; python3 scripts/customize.py

build.stamp: venv sources/config.yaml $(SOURCES)
rm -rf fonts
(for config in sources/config*.yaml; do . venv/bin/activate; gftools builder $$config; done) && touch build.stamp

venv/touchfile: requirements.txt
test -d venv || python3 -m venv venv
. venv/bin/activate; pip install -Ur requirements.txt
touch venv/touchfile

venv-test/touchfile: requirements-test.txt
test -d venv-test || python3 -m venv venv-test
. venv-test/bin/activate; pip install -Ur requirements-test.txt
touch venv-test/touchfile

test: venv-test build.stamp
TOCHECK=$$(find fonts/variable -type f 2>/dev/null); if [ -z "$$TOCHECK" ]; then TOCHECK=$$(find fonts/ttf -type f 2>/dev/null); fi ; . venv-test/bin/activate; mkdir -p out/ out/fontbakery; fontbakery check-googlefonts -l WARN --full-lists --succinct --badges out/badges --html out/fontbakery/fontbakery-report.html --ghmarkdown out/fontbakery/fontbakery-report.md $$TOCHECK || echo '::warning file=sources/config.yaml,title=Fontbakery failures::The fontbakery QA check reported errors in your font. Please check the generated report.'

proof: venv build.stamp
TOCHECK=$$(find fonts/variable -type f 2>/dev/null); if [ -z "$$TOCHECK" ]; then TOCHECK=$$(find fonts/ttf -type f 2>/dev/null); fi ; . venv/bin/activate; mkdir -p out/ out/proof; diffenator2 proof $$TOCHECK -o out/proof

images: venv $(DRAWBOT_OUTPUT)

%.png: %.py build.stamp
. venv/bin/activate; python3 $< --output $@

clean:
rm -rf venv
find . -name "*.pyc" -delete

update-project-template:
npx update-template https://github.com/googlefonts/googlefonts-project-template/

update: venv venv-test
venv/bin/pip install --upgrade pip-tools
# See https://pip-tools.readthedocs.io/en/latest/#a-note-on-resolvers for
# the `--resolver` flag below.
venv/bin/pip-compile --upgrade --verbose --resolver=backtracking requirements.in
venv/bin/pip-sync requirements.txt

venv-test/bin/pip install --upgrade pip-tools
venv-test/bin/pip-compile --upgrade --verbose --resolver=backtracking requirements-test.in
venv-test/bin/pip-sync requirements-test.txt

git commit -m "Update requirements" requirements.txt requirements-test.txt
git push
File renamed without changes.
Binary file added documentation/image1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
140 changes: 140 additions & 0 deletions documentation/image1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
# This script is meant to be run from the root level
# of your font's git repository. For example, from a Unix terminal:
# $ git clone my-font
# $ cd my-font
# $ python3 documentation/image1.py --output documentation/image1.png

# Import moduels from external python packages: https://pypi.org/
from drawbot_skia.drawbot import *
from fontTools.ttLib import TTFont
from fontTools.misc.fixedTools import floatToFixedToStr

# Import moduels from the Python Standard Library: https://docs.python.org/3/library/
import subprocess
import sys
import argparse

# Constants, these are the main "settings" for the image
WIDTH, HEIGHT, MARGIN, FRAMES = 2048, 2048, 128, 1
FONT_PATH = "fonts/variable/AbhayaLibre[wght].ttf"
FONT_LICENSE = "OFL v1.1"
AUXILIARY_FONT = "Helvetica"
AUXILIARY_FONT_SIZE = 48

# Update BIG_TEXT for multiple lines

BIG_TEXT_LINES = ["හරි?", "AbGg"]
BIG_TEXT_FONT_SIZE = 730
BIG_TEXT_SIDE_MARGIN = MARGIN * 1
BIG_TEXT_BOTTOM_MARGIN = MARGIN * 3



GRID_VIEW = False # Toggle this for a grid overlay

# Handel the "--output" flag
# For example: $ python3 documentation/image1.py --output documentation/image1.png
parser = argparse.ArgumentParser()
parser.add_argument("--output", metavar="PNG", help="where to write the PNG file")
args = parser.parse_args()

# Load the font with the parts of fonttools that are imported with the line:
# from fontTools.ttLib import TTFont
# Docs Link: https://fonttools.readthedocs.io/en/latest/ttLib/ttFont.html
ttFont = TTFont(FONT_PATH)

# Constants that are worked out dynamically
MY_URL = subprocess.check_output("git remote get-url origin", shell=True).decode()
MY_HASH = subprocess.check_output("git rev-parse --short HEAD", shell=True).decode()
FONT_NAME = ttFont["name"].getDebugName(4)
FONT_VERSION = "v%s" % floatToFixedToStr(ttFont["head"].fontRevision, 16)


# Draws a grid
def grid():
stroke(1, 0, 0, 0.75)
strokeWidth(2)
STEP_X, STEP_Y = 0, 0
INCREMENT_X, INCREMENT_Y = MARGIN / 2, MARGIN / 2
rect(MARGIN, MARGIN, WIDTH - (MARGIN * 2), HEIGHT - (MARGIN * 2))
for x in range(29):
polygon((MARGIN + STEP_X, MARGIN), (MARGIN + STEP_X, HEIGHT - MARGIN))
STEP_X += INCREMENT_X
for y in range(29):
polygon((MARGIN, MARGIN + STEP_Y), (WIDTH - MARGIN, MARGIN + STEP_Y))
STEP_Y += INCREMENT_Y
polygon((WIDTH / 2, 0), (WIDTH / 2, HEIGHT))
polygon((0, HEIGHT / 2), (WIDTH, HEIGHT / 2))


# Remap input range to VF axis range
# This is useful for animation
# (E.g. sinewave(-1,1) to wght(100,900))
def remap(value, inputMin, inputMax, outputMin, outputMax):
inputSpan = inputMax - inputMin # FIND INPUT RANGE SPAN
outputSpan = outputMax - outputMin # FIND OUTPUT RANGE SPAN
valueScaled = float(value - inputMin) / float(inputSpan)
return outputMin + (valueScaled * outputSpan)


# Draw the page/frame and a grid if "GRID_VIEW" is set to "True"
def draw_background():
newPage(WIDTH, HEIGHT)
fill(0)
rect(-2, -2, WIDTH + 2, HEIGHT + 2)
if GRID_VIEW:
grid()
else:
pass


# Draw main text
def draw_main_text():
fill(1)
stroke(None)
font(FONT_PATH)
fontSize(BIG_TEXT_FONT_SIZE)
y = BIG_TEXT_BOTTOM_MARGIN
for line in BIG_TEXT_LINES:
text(line, (BIG_TEXT_SIDE_MARGIN, y))
y += BIG_TEXT_FONT_SIZE * 1.2 # Adjust the line spacing as needed


# Divider lines
def draw_divider_lines():
stroke(1)
strokeWidth(5)
lineCap("round")
line((MARGIN, HEIGHT - (MARGIN * 1.5)), (WIDTH - MARGIN, HEIGHT - (MARGIN * 1.5)))
line((MARGIN, MARGIN + (MARGIN / 2)), (WIDTH - MARGIN, MARGIN + (MARGIN / 2)))
stroke(None)


# Draw text describing the font and it's git status & repo URL
def draw_auxiliary_text():
# Setup
font(AUXILIARY_FONT)
fontSize(AUXILIARY_FONT_SIZE)
POS_TOP_LEFT = (MARGIN, HEIGHT - MARGIN * 1.25)
POS_TOP_RIGHT = (WIDTH - MARGIN, HEIGHT - MARGIN * 1.25)
POS_BOTTOM_LEFT = (MARGIN, MARGIN)
POS_BOTTOM_RIGHT = (WIDTH - MARGIN * 0.95, MARGIN)
URL_AND_HASH = MY_URL + "at commit " + MY_HASH
URL_AND_HASH = URL_AND_HASH.replace("\n", " ")
# Draw Text
text(FONT_NAME, POS_TOP_LEFT, align="left")
text(FONT_VERSION, POS_TOP_RIGHT, align="right")
text(URL_AND_HASH, POS_BOTTOM_LEFT, align="left")
text(FONT_LICENSE, POS_BOTTOM_RIGHT, align="right")


# Build and save the image
if __name__ == "__main__":
draw_background()
draw_main_text()
draw_divider_lines()
draw_auxiliary_text()
# Save output, using the "--output" flag location
saveImage(args.output)
# Print done in the terminal
print("DrawBot: Done")
Binary file added documentation/image2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit f53da70

Please sign in to comment.