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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatize casks update on releases #1008

Merged
merged 20 commits into from
Dec 14, 2022
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
89 changes: 89 additions & 0 deletions .github/workflows/casks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
name: Create Casks PR

env:
HOMEBREW_REPO: Homebrew/homebrew-cask-fonts
HOMEBREW_FORK: Finii/homebrew-cask-fonts
FORK_USER: Finii
FORK_TOKEN: tvguho_cng_11NQ2SVID0Fs35qI0dkGL2_r0WStECYXKRoaOg8ZkkhjtKKJrzRYEzXkGBolrn2NqJFGFCT5COv8lyixqy

on:
workflow_dispatch:

jobs:
create-casks:
name: Create casks
runs-on: ubuntu-latest
steps:
- name: Fetch stuff (no checkout)
uses: Bhacaz/checkout-files@v2
with:
files: bin/scripts/lib/fonts.json bin/scripts/fetch-archives.sh bin/scripts/generate-casks.sh
branch: ${{ github.head_ref || github.ref_name }}
- name: Fetch release artifacts
run: |
cd bin/scripts
chmod u+x *
./fetch-archives.sh latest Heavy
- name: Determine release tag
id: releasetag
run: |
TAG=$(ls archives/_Release* | head -n 1 | sed 's/.*_Release_//')
echo "Release has tag ${TAG}"
echo "tag=${TAG}" >> $GITHUB_OUTPUT
- name: Create all casks
run: |
cd bin/scripts
./generate-casks.sh --setversion ${{ steps.releasetag.outputs.tag }}
- name: Upload casks as artifacts
uses: actions/upload-artifact@v2
with:
name: casks
path: casks
outputs:
tag: ${{ steps.releasetag.outputs.tag }}

commit-casks:
name: Create commits
runs-on: ubuntu-latest
needs: create-casks
steps:
- name: Do some preparation
id: notsecret
run: |
PAK=$(echo "${FORK_TOKEN}" | tr 'A-Za-z' 'N-ZA-Mn-za-m')
echo "pak=${PAK}" >> $GITHUB_OUTPUT
- name: Checkout Homebrew
uses: actions/checkout@v3
with:
repository: ${{ env.HOMEBREW_FORK }}
path: homebrew
ref: nerdfonts
token: ${{ steps.notsecret.outputs.pak }}
- name: Update Homebrew fork
run: |
cd homebrew
git remote add upstream https://github.com/${{ env.HOMEBREW_REPO }}.git
git fetch upstream master
git reset --hard upstream/master
git push --force origin HEAD:nerdfonts
- name: Retrieve new casks
uses: actions/download-artifact@v2
with:
name: casks
path: casks
- name: Prepare changes
run: |
cp casks/* homebrew/Casks
- name: Commit changes
uses: EndBug/add-and-commit@v9
with:
cwd: homebrew
fetch: false
add: Casks
message: "[ci] Update Nerd Font casks to ${{ needs.create-casks.outputs.tag }}"
committer_name: GitHub Actions
committer_email: 41898282+github-actions[bot]@users.noreply.github.com
- name: Create PR
run: |
echo "Well, this would automatically create a PR, but this is disabled for now:"
echo gh pr create -p ${{ env.HOMEBREW_REPO }} -B master -H nerdfonts -R ${{ env.HOMEBREW_FORK }} -d -f
22 changes: 0 additions & 22 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -196,17 +196,6 @@ jobs:
cd -- "$GITHUB_WORKSPACE/bin/scripts"
./archive-fonts.sh "${{ matrix.font }}"

- name: Generate cask
# The casks are not used at the moment, but probably Ryan
# wanted to push them out somewhere
id: cask_generate
if: false
run: |
cd -- "$GITHUB_WORKSPACE/bin/scripts"
gen=$(./generate-casks.sh "${{ matrix.font }}")
echo $gen
echo path=$(echo "$gen" | grep '^## Created' | sed -E 's/.*: +//') >> $GITHUB_OUTPUT

- name: Upload zip file archive for release
uses: softprops/action-gh-release@v0.1.14
if: needs.setup-fonts-matrix.outputs.rel_upload == 'true'
Expand All @@ -226,17 +215,6 @@ jobs:
patched-fonts/${{ matrix.font }}
LICENSE

- name: Upload casks as artifacts
if: false
uses: actions/upload-artifact@v2
with:
name: casks
# adding multiple paths (i.e. LICENSE) is a workaround to get a least common ancestor
# of the root directory for artifact path purposes
path: |
${{ steps.cask_generate.outputs.path }}
LICENSE

release-font-patcher:
name: Archive font patcher and add to release
needs: [ setup-fonts-matrix, build ]
Expand Down
4 changes: 3 additions & 1 deletion bin/scripts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ Note: Usually you need to call the scripts in this directory while actually bein
* `data/`: Contains plain text files used to generate the CSS and cheat sheet files
* `data/sankey/`: Contains instructions on how to create the sankey glyph table manually [3]
* `docker-entrypoint.sh`: This script is packaged into the docker container and is usually used to start patching [2]
* `fetch-archives.sh`: Script to download the release zip archives [6]
* `fpfix.py`: Can be used to set isFixedPitch property in a font [x]
* `generate-casks.sh`: Generates cask files for fonts from data in `patched-fonts/` and `archives/`, unused and not recommended by homebrew-fonts
* `generate-casks.sh`: Generates cask files for fonts from data in `archives/` [6]
* `generate-css.sh`: Generates the Nerd Fonts CCS, which can be used to access the glyphs on a web page [1]
* `generate-fontconfig.sh`: Generates font configuration to enable use of unpatched fonts with Symbols Only Nerd Font [1]
* `generate-font-image-previews.sh`: Generates the preview images for `nerdfonts.com` (i.e. gh-pages) [3]
Expand All @@ -33,4 +34,5 @@ Note: Usually you need to call the scripts in this directory while actually bein
[3] To be used manually (sigh)
[4] To be used manually
[5] Used by CI (github packsvgs workflow)
[6] Used by CI (github casks workflow)
[x] Probably not used by anything
72 changes: 72 additions & 0 deletions bin/scripts/fetch-archives.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#!/usr/bin/env bash
# Nerd Fonts Version: 2.3.0-RC
# Script Version: 2.0.0
#
# Fetches the current release files.
# It fetches the latest release, not release candidate.
# Or fetches the specified release's files.
#
# The second parameter specifies the beginning of the artifact
# name that shall be fetched. If unspecified all artifacts will
# be fetched.
#
# Example runs
# fetch-archives
# fetch-archives v2.2.2
# fetch-archives v2.2.2 Heavy
# fetch-archives latest HeavyDat

set -e

LINE_PREFIX="# [Nerd Fonts] "
scripts_root_dir="$(cd "$(dirname "$0")" && pwd)"
outputdir=$(realpath "${scripts_root_dir}/../../archives")

if [ $# -ge 1 ]; then
versiontag=$1
else
versiontag="latest"
fi

if [ "${versiontag}" != "latest" ]; then
echo "${LINE_PREFIX} Fetching release archives with version tag '${versiontag}'"
releasedata=$(curl -Lf "https://api.github.com/repos/ryanoasis/nerd-fonts/releases")
num=$(jq ".[] | select(.tag_name == \"${versiontag}\") | .assets | length" <<< ${releasedata})
if [ -z "${num}" ]; then
echo "${LINE_PREFIX} Release tag ${versiontag} unknown"
exit 1
fi
files=($(jq -r ".[] | select(.tag_name == \"${versiontag}\") | .assets[].name | @sh" <<< ${releasedata}))
else
echo "${LINE_PREFIX} Fetching latest release archives"
releasedata=$(curl -Lf "https://api.github.com/repos/ryanoasis/nerd-fonts/releases/latest")
versiontag=$(jq -r ".tag_name" <<< ${releasedata})
num=$(jq ".assets | length" <<< ${releasedata})
files=($(jq -r ".assets[].name | @sh" <<< ${releasedata}))
fi

echo "${LINE_PREFIX} Found ${num} artifacts"

if [ $# -ge 2 ]; then
pattern=$2
echo "${LINE_PREFIX} Limiting archive to pattern '${pattern}'"
else
pattern=""
echo "${LINE_PREFIX} No limiting pattern given"
fi
if [ $# -gt 2 ]; then
echo "${LINE_PREFIX} Too many parameters, exiting"
exit 2
fi

for assetname in ${files[@]}; do
assetname=${assetname:1:-1}
if [[ ! "${assetname}" =~ ^"${pattern}" ]]; then
continue
fi
echo >&2 "${LINE_PREFIX} Fetching ${versiontag}/${assetname}"
mkdir -p "${outputdir}"
touch "${outputdir}/_Release_${versiontag}"
curl --fail -Lo "${outputdir}/${assetname}" "https://github.com/ryanoasis/nerd-fonts/releases/download/${versiontag}/${assetname}" \
|| echo " => error fetching"
done
Loading