Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

archive-fonts: Create tar.xz packs #1235

Merged
merged 3 commits into from
Jun 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -210,12 +210,12 @@ jobs:
fontforge --script `pwd`/../../font-patcher --version
./gotta-patch-em-all-font-patcher\!.sh -j "/${{ matrix.font }}"

- name: Archive font package zip files
- name: Archive font packages
run: |
cd -- "$GITHUB_WORKSPACE/bin/scripts"
./archive-fonts.sh "${{ matrix.font }}"

- name: Upload zip file archive for release
- name: Upload zip and tar.xz archive for release
uses: softprops/[email protected]
if: needs.setup-fonts-matrix.outputs.rel_upload == 'true'
with:
Expand Down
112 changes: 62 additions & 50 deletions bin/scripts/archive-fonts.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
#!/usr/bin/env bash
# Nerd Fonts Version: 3.0.1
# Script Version: 1.1.2
# Script Version: 1.2.0
# Iterates over all patched fonts directories
# to generate ruby cask files for homebrew-fonts (https://github.com/caskroom/homebrew-fonts)
# adds Windows versions of the fonts as well (casks files just won't download them)
# used for debugging
# set -x
# to generate release archives of the patched font(s)
#
# Example run with pattern matching:
# ./archive-fonts heavydata
# Example with same font names for different paths
Expand All @@ -14,73 +12,87 @@
set -e

LINE_PREFIX="# [Nerd Fonts] "
scripts_root_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/"
parent_dir="${PWD}/../../"
echo "dir $scripts_root_dir"
outputdir=$scripts_root_dir../../archives
root_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." >/dev/null 2>&1 || exit && pwd -P)"
outputdir=${root_dir}/archives

mkdir -p "$outputdir"

cd "$scripts_root_dir/../../patched-fonts/" || {
echo >&2 "$LINE_PREFIX Could not find patched fonts directory"
exit 1
cd "${root_dir}/patched-fonts/" || {
echo >&2 "$LINE_PREFIX Could not find patched fonts directory"
exit 1
}

# limit archiving to given pattern (first script param) or entire root folder if no param given:
if [ $# -eq 1 ]
then
if [ $# -eq 1 ]; then
pattern=$1
search_pattern="*$1*.zip"
search_pattern=$1
echo "$LINE_PREFIX Limiting archive to pattern '$pattern'"
else
pattern=".*"
search_pattern="*.zip"
search_pattern=""
echo "$LINE_PREFIX No limiting pattern given, will search entire folder"
fi

# create a mini readme with basic info on Nerd Fonts project
touch "$outputdir/readme.md"
mini_readme="$outputdir/readme.md"
cat "$parent_dir/src/archive-readme.md" >> "$mini_readme"
cat "$root_dir/src/archive-readme.md" >> "$mini_readme"

# clear out the directory zips
find "${outputdir:?}" -name "$search_pattern" -type f -delete
# clear out the directory
find "${outputdir:?}" -maxdepth 1 \( -name "${search_pattern}.zip" -o -name "${search_pattern}.tar.xz" \) -type f -print -delete

#find ./Hack -maxdepth 0 -type d | # uncomment to test 1 font
#find ./ProFont -maxdepth 0 -type d | # uncomment to test 1 font
# find ./IBMPlexMono -maxdepth 0 -type d | # uncomment to test 1 font
# uncomment to test all fonts:
find . -maxdepth 1 -iregex "\./$pattern" -type d |
while read -r filename
do
find . -maxdepth 1 -iregex "\./$pattern" -type d | sort |
while read -r filename; do
basename=$(basename "$filename")
searchdir=$filename

basename=$(basename "$filename")
searchdir=$filename
[[ -d "$outputdir" ]] || mkdir -p "$outputdir"

[[ -d "$outputdir" ]] || mkdir -p "$outputdir"
rm -f "${outputdir}/${basename}.tar"
expected=$(find "${searchdir}" -iname "*.[ot]tf" -exec echo "+" \; | wc -l)
echo "${LINE_PREFIX} Packing ${basename}.tar.xz (${expected} fonts)"
# This finds all files, uniq on the filename (ignoring path):
while IFS= read -d $'\0' -r descriptor; do
path=$(echo ${descriptor} | sed 's/|.*//')
file=$(echo ${descriptor} | sed 's/.*|//')
if $(echo ${file} | grep -qi '.[ot]tf'); then
expected=$((expected - 1))
fi
# Need to cd to the file because we want to archive 'flat' (without subdirs):
x=$(cd "$path" && tar rf "$outputdir/$basename.tar" --no-recursion "$file")
done < <(find "${searchdir}" -type f -exec bash -c 'printf "%s\000" "{}" | sed "s!\(.*\)/!\1|!"' \; | sort -z -u '-t|' -k2,2 | sort -z)

# add font files:
# -ic (ignore case not working)
zip -9 "$outputdir/$basename" -rj "$searchdir" -i '*.[ot]tf' -i '*.[OT]TF' -q
zipStatus=$?
if [ "$zipStatus" != "0" ]
then
echo "$LINE_PREFIX Could not create archive with the path junked (-j option) - likely same font names for different paths, zip status: $zipStatus"
echo "$LINE_PREFIX Retrying with full path"
# add font files and license files as full paths:
zip -9 "$outputdir/$basename" -r "$searchdir" -i '*.[ot]tf' -i '*.[OT]TF' -i '*[Ll]icen[sc]e*' -i '*LICEN[SC]E*' -i 'OFL*' -i 'ofl*' -q
else
# we can copy the font files without full paths but not necessarily the license files:
# add license files separately:
# zip -9 "$outputdir/$basename" -rj "$searchdir" -i '*license*' -i '*LICENSE*'
# work around to copy duplicate license files (only the last duplicate found)
# so we don't have to copy entire paths and can still use the junk option (-j)
find "$searchdir" -type f -iname "*licen[sc]e*" -o -iname 'ofl*' | awk -F/ '{a[$NF]=$0}END{for(i in a)print a[i]}' | zip -9 -j "$outputdir/$basename" -@
fi;
if [ $expected -ne 0 ]; then
# Should never happen, but who knows
echo "${LINE_PREFIX} Did not pack expected number of font files! Likely same font names for different paths."
exit 1
fi
x=$(cd "${outputdir}" && tar rf "${outputdir}/${basename}.tar" "readme.md")
xz -f -9 -T0 "${outputdir}/${basename}.tar"

# add mini readme file
zip -9 "$outputdir/$basename" -rj "$mini_readme" -q
# ZIP stuff:
# add font files:
# -ic (ignore case not working)
echo "${LINE_PREFIX} Packing ${basename}.zip"
zip -9 "$outputdir/$basename" -rj "$searchdir" -i '*.[ot]tf' -i '*.[OT]TF' -q
zipStatus=$?
if [ "$zipStatus" != "0" ]; then
echo "$LINE_PREFIX Could not create archive with the path junked (-j option) - likely same font names for different paths, zip status: $zipStatus"
echo "$LINE_PREFIX Retrying with full path"
# add font files and license files as full paths:
zip -9 "$outputdir/$basename" -r "$searchdir" -i '*.[ot]tf' -i '*.[OT]TF' -i '*[Ll]icen[sc]e*' -i '*LICEN[SC]E*' -i 'OFL*' -i 'ofl*' -q
else
# we can copy the font files without full paths but not necessarily the license files:
# add license files separately:
# zip -9 "$outputdir/$basename" -rj "$searchdir" -i '*license*' -i '*LICENSE*'
# work around to copy duplicate license files (only the last duplicate found)
# so we don't have to copy entire paths and can still use the junk option (-j)
find "$searchdir" -type f -iname "*licen[sc]e*" -o -iname 'ofl*' | awk -F/ '{a[$NF]=$0}END{for(i in a)print a[i]}' | zip -9 -j "$outputdir/$basename" -@
fi;

# add mini readme file
zip -9 "$outputdir/$basename" -rj "$mini_readme" -q
done
rm -f "$mini_readme"

rm -f "$mini_readme"
ls -al "$outputdir"