Skip to content

Commit

Permalink
feat: Upgrade Nerd Fonts to version 3.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
cdalvaro committed May 1, 2023
1 parent be7239a commit 3624c70
Show file tree
Hide file tree
Showing 11 changed files with 67 additions and 38 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,6 @@ jobs:
run: sudo apt update -y && sudo apt install -y python3-fonttools fonttools

- name: Execute tests
env:
PLATFORM: ${{ matrix.platform }}
run: bash tests/patch-test.sh
6 changes: 3 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Default directories
in/
out/
tests/assets/
/in/
/out/
/tests/assets/
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# Changelog

The following list only reflects changes made on this project. Please, refer to the [Nerd Fonts 2.3.1 Release Notes](https://www.nerdfonts.com/releases) for the complete list of changes.
The following list only reflects changes made on this project. Please, refer to the [Nerd Fonts 3.0.0 Release Notes](https://www.nerdfonts.com/releases) for the complete list of changes.

**3.0.0**

* Upgrade Nerd Fonts to `3.0.0`
* Change Docker base image to `ubuntu:jammy-20230308`

**2.3.1**

Expand Down
15 changes: 4 additions & 11 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,13 @@ ARG BUILD_DATE
ARG VCS_REF

# https://github.com/ryanoasis/nerd-fonts/releases
ENV NERDFONTS_VERSION="v2.3.1" \
NERDFONTS_SHA256="53f17da9b2c73c4bb4f81a5c8561940618e6808df91f36c8aa9890eb0caabe18"
ENV NERDFONTS_VERSION="v3.0.0" \
NERDFONTS_SHA256="994e953cd69e2fd114ce79af422354b14b95418191365f99e11987c55e487243"
ENV IMAGE_VERSION="${NERDFONTS_VERSION}"

ENV BUILD_DIR="/build" \
NERDFONTS_DIR="/nerd-fonts"

ENV INPUT_DIR="${NERDFONTS_DIR}/in" \
OUTPUT_DIR="${NERDFONTS_DIR}/out" \
REPOSITORY_DIR="${NERDFONTS_DIR}/repo"
RUN mkdir -p "${INPUT_DIR}" "${OUTPUT_DIR}" "${REPOSITORY_DIR}"
REPOSITORY_DIR="/nerd-fonts/repo"
RUN mkdir -p "${REPOSITORY_DIR}"

# Install nerd fonts
COPY assets/build/ ${BUILD_DIR}
Expand All @@ -38,8 +34,5 @@ LABEL org.opencontainers.image.licenses="MIT"
COPY entrypoint.sh /sbin/entrypoint.sh
RUN chmod +x /sbin/entrypoint.sh

# Shared resources
VOLUME [ "${INPUT_DIR}", "${OUTPUT_DIR}" ]

WORKDIR ${REPOSITORY_DIR}
ENTRYPOINT ["/sbin/entrypoint.sh"]
16 changes: 9 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
[![Architecture ARM64][arch_arm64_badge]][arch_link]
[![Architecture ARM/v7][arch_arm_badge]][arch_link]

# Dockerized Nerd Fonts Patcher v2.3.1
# Dockerized Nerd Fonts Patcher v3.0.0

Dockerfile to build a Nerd Fonts Patcher image for the Docker opensource container platform.

Expand All @@ -28,17 +28,19 @@ Just copy all your fonts you want to patch into `$(pwd)/in` directory and execut

```sh
docker run --rm \
--volume $(pwd)/in:/nerd-fonts/in \
--volume $(pwd)/out:/nerd-fonts/out \
--user $(id -u):$(id -g) \
--volume "$(pwd)/in":/input \
--volume "$(pwd)/out":/output \
--env PUID=$(id -u) --env PGID=$(id -g) \
ghcr.io/cdalvaro/docker-nerd-fonts-patcher:latest \
--quiet --no-progressbars \
--mono --adjust-line-height --complete --careful
```

The container will patch all files with extensions `.otf` and `.ttf` inside `$(pwd)/in` and
The container will patch all files with extensions: `.otf`, `.ttf`, `.woff`, `.eot`, `.ttc` inside `$(pwd)/in` and
leave them into `$(pwd)/out`.

Environment variables `PUID` and `PGID` are used to set the user and group id of the files created by the container.

More information is available at the [official documentation][patch-your-own-font] site.

## Available Sources
Expand All @@ -61,9 +63,9 @@ or from [GitHub Container Registry](https://ghcr.io/cdalvaro/docker-nerd-fonts-p
docker pull ghcr.io/cdalvaro/docker-nerd-fonts-patcher
```

[nerdfonts_badge]: https://img.shields.io/badge/Nerd%20Fonts-v2.3.1-lightgrey.svg
[nerdfonts_badge]: https://img.shields.io/badge/Nerd%20Fonts-v3.0.0-lightgrey.svg

[nerdfonts_release_notes]: https://github.com/ryanoasis/nerd-fonts/releases/tag/v2.3.1 "Nerd Fonts Release Notes"
[nerdfonts_release_notes]: https://github.com/ryanoasis/nerd-fonts/releases/tag/v3.0.0 "Nerd Fonts Release Notes"

[ubuntu_badge]: https://img.shields.io/badge/ubuntu-jammy--20230308-E95420.svg?logo=Ubuntu

Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.3.1
3.0.0
32 changes: 26 additions & 6 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

set -e

INPUT_DIR="/input"
OUTPUT_DIR="/output"

# Auxiliary functions
RESET='\033[0m'
RED='\033[1;31m'
Expand All @@ -21,11 +24,16 @@ function log_error() {
(>&2 echo -e "${RED}Error${RESET}: $*")
}

if [[ -z "${REPOSITORY_DIR}" ]]; then
log_error "REPOSITORY_DIR environment variable should be set but it is not. Please report this issue at: https://github.com/cdalvaro/docker-nerd-fonts-patcher/issues"
exit 1
fi

# Validate arguments
options=()
while [[ $# -gt 0 ]]; do
param="$1"; shift
case "$param" in
case "${param}" in
-h|--help)
exec fontforge -script font-patcher --help ;;
-v|--version)
Expand All @@ -34,7 +42,7 @@ while [[ $# -gt 0 ]]; do
log_warn "Output directory cannot be modified. Default is: ${CYAN}${OUTPUT_DIR}/${RESET}"
shift ;;
*)
options+=("$param") ;;
options+=("${param}") ;;
esac
done

Expand All @@ -47,19 +55,31 @@ fi
# Get fonts available in the input directory
fonts=()
while IFS='' read -r line; do
fonts+=("$line")
done < <(find "${INPUT_DIR}/" -type f -iregex '.*\.\(otf\|ttf\)$' 2>/dev/null)
fonts+=("${line}")
done < <(find "${INPUT_DIR}/" -type f -iregex '.*\.\(otf\|ttf\|woff\|eot\|ttc\)$' 2>/dev/null || true)

# Check whether there are fonts to patch
if [ ${#fonts[@]} -eq 0 ]; then
log_error "There are no ${CYAN}.otf${RESET} neither ${CYAN}.ttf${RESET} fonts inside ${CYAN}${INPUT_DIR}/${RESET} directory"
if [[ ${#fonts[@]} -eq 0 ]]; then
log_error "There are no fonts with extensions: ${CYAN}.otf${RESET}, ${CYAN}.ttf${RESET}, ${CYAN}.woff${RESET}, ${CYAN}.eot${RESET} or ${CYAN}.ttc${RESET} inside ${CYAN}${INPUT_DIR}/${RESET} directory"
exit 1
fi

touch "${OUTPUT_DIR}/font-patcher-log.txt"
rm -f "${REPOSITORY_DIR}/font-patcher-log.txt"
ln -s "${OUTPUT_DIR}/font-patcher-log.txt" "${REPOSITORY_DIR}/font-patcher-log.txt"

# Patch fonts
for font in "${fonts[@]}"; do
log_info "Patching font ${CYAN}${font}${RESET} ..."
fontforge -script font-patcher -out "${OUTPUT_DIR}/" "${options[@]}" "${font}"
done

if [[ -n "${PUID}" ]]; then
OWNERSHIP="${PUID}"
[[ -n "${PGID}" ]] && OWNERSHIP="${OWNERSHIP}:${PGID}"

log_info "Changing ownership of ${CYAN}${OUTPUT_DIR}/${RESET} to ${CYAN}${OWNERSHIP}${RESET} ..."
chown -R "${OWNERSHIP}" "${OUTPUT_DIR}"
fi

exit 0
Empty file added in/.gitkeep
Empty file.
Empty file added out/.gitkeep
Empty file.
15 changes: 10 additions & 5 deletions tests/lib/common.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/usr/bin/env bash

# shellcheck disable=SC2312

#--- ENV VARIABLE ---------------------------------------------------------------------------------------------------
# NAME: IMAGE_NAME
# DESCRIPTION: The name and tag of the Docker image. Default: 'cdalvaro/docker-nerd-fonts-patcher:latest'.
Expand All @@ -25,7 +27,9 @@ function lowercase() {
# DESCRIPTION: Echo debug information to stdout.
#----------------------------------------------------------------------------------------------------------------------
function log_debug() {
if [[ $(lowercase "${DEBUG}") == true || $(lowercase "${ECHO_DEBUG}") == true ]]; then
ECHO_DEBUG=$(lowercase "${ECHO_DEBUG:-${DEBUG:-false}}")

if [[ "${ECHO_DEBUG}" == true ]]; then
echo "[DEBUG] - $*"
fi
}
Expand Down Expand Up @@ -172,9 +176,10 @@ function patch_fonts()
local INPUT_DIR="${1}"; shift
local OUTPUT_DIR="${1}"; shift

docker run --rm \
--volume "${INPUT_DIR}/":/nerd-fonts/in \
--volume "${OUTPUT_DIR}/":/nerd-fonts/out \
--user "$(id -u)":"$(id -g)" -- "${IMAGE_NAME}" \
docker run --rm --platform "${PLATFORM}" \
--volume "${INPUT_DIR}/":/input \
--volume "${OUTPUT_DIR}/":/output \
--env PUID="$(id -u)" --env PGID="$(id -g)" \
-- "${IMAGE_NAME}" \
--quiet --no-progressbars "$@"
}
10 changes: 6 additions & 4 deletions tests/patch-test.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/usr/bin/env bash

# shellcheck disable=SC2312

set -e

# https://stackoverflow.com/a/4774063/3398062
Expand All @@ -8,18 +10,18 @@ COMMON_FILE="${SCRIPT_PATH}/lib/common.sh"

# shellcheck source=tests/lib/common.sh
source "${COMMON_FILE}"
[ "$(lowercase "${DEBUG}")" == true ] && set -vx
[[ "$(lowercase "${DEBUG:-false}")" == true ]] && set -vx

log_info "🧪 Running patch tests ..."

### GIVEN
FIRACODE_VERSION="6"
FIRACODE_SHA256="a4997c2f905fb20a6d814baf7b9bab7df7de574a8e87d6af509685a43291caf1"
FIRACODE_VERSION="6.2"
FIRACODE_SHA256="0949915ba8eb24d89fd93d10a7ff623f42830d7c5ffc3ecbf960e4ecad3e3e79"
FIRACODE_FILE_NAME="FiraCode.zip"
FIRACODE_URL="https://github.com/tonsky/FiraCode/releases/download/${FIRACODE_VERSION}/Fira_Code_v${FIRACODE_VERSION}.zip"

NERDFONTS_VERSION="$(cat VERSION)"
FIRACODE_NERD_FONT_SHA256="9d0018e5a299b582c42d6e3e80cd4f3b0a3489e14e0c8ad126869248fa11c172"
FIRACODE_NERD_FONT_SHA256="705b7eaa5b687987cc0e65a961314250be0cbdac71e6ae5a8be5c8064361f37c"
FIRACODE_NERD_FONT_FILE_NAME="FiraCodeNerdFont.zip"
FIRACODE_NERD_FONT_URL="https://github.com/ryanoasis/nerd-fonts/releases/download/v${NERDFONTS_VERSION}/FiraCode.zip"

Expand Down

0 comments on commit 3624c70

Please sign in to comment.