2018-07-09 16:20:40 +02:00
|
|
|
#!/usr/bin/env bash
|
2019-11-03 19:05:56 +02:00
|
|
|
# Nerd Fonts Version: 2.1.0
|
2021-11-21 17:29:23 +02:00
|
|
|
# Script Version: 1.1.0
|
2016-11-21 05:34:24 +02:00
|
|
|
# Iterates over all archives and uploads to given release
|
|
|
|
|
|
|
|
# uncomment to debug:
|
|
|
|
#set -x
|
2021-11-21 17:29:23 +02:00
|
|
|
|
2017-05-14 00:15:57 +02:00
|
|
|
LINE_PREFIX="# [Nerd Fonts] "
|
2016-11-21 05:34:24 +02:00
|
|
|
|
|
|
|
cd ../../archives/ || {
|
2017-05-14 00:15:57 +02:00
|
|
|
echo >&2 "$LINE_PREFIX Could not find archives directory"
|
2016-11-21 05:34:24 +02:00
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
2021-11-21 17:29:23 +02:00
|
|
|
# We don't need to use a separate access token for accessing Github API when we
|
|
|
|
# are in a Github action, can use the auto provided `GITHUB_TOKEN`
|
|
|
|
# see: https://docs.github.com/en/actions/security-guides/automatic-token-authentication
|
|
|
|
TOKEN=$GITHUB_TOKEN
|
2016-11-21 05:34:24 +02:00
|
|
|
OWNER="ryanoasis"
|
|
|
|
REPO="nerd-fonts"
|
2021-11-21 17:29:23 +02:00
|
|
|
RELEASE_TAG=""
|
2017-01-15 20:05:10 +02:00
|
|
|
|
2021-11-21 17:29:23 +02:00
|
|
|
if [ -z "$1" ]
|
|
|
|
then
|
|
|
|
# before we used to check for tag param and set release URL to releases/latest
|
|
|
|
# but to simplify things let's just fail and always require a proper release/tag
|
|
|
|
echo "$LINE_PREFIX No Tag Release was given"
|
|
|
|
exit 1
|
2017-01-15 20:05:10 +02:00
|
|
|
else
|
2021-11-21 17:29:23 +02:00
|
|
|
echo "$LINE_PREFIX Tag/Release was $1"
|
|
|
|
RELEASE_TAG="$1"
|
2017-01-15 20:05:10 +02:00
|
|
|
fi
|
|
|
|
|
2021-11-26 17:49:18 +02:00
|
|
|
if [ -z "$2" ]
|
|
|
|
then
|
|
|
|
search_pattern="*.zip"
|
|
|
|
echo "$LINE_PREFIX No limiting pattern given, will search entire folder"
|
|
|
|
else
|
|
|
|
pattern=$2
|
|
|
|
search_pattern="*$2*.zip"
|
|
|
|
echo "$LINE_PREFIX Limiting upload archive to pattern '$pattern'"
|
|
|
|
fi
|
|
|
|
|
2021-11-21 17:29:23 +02:00
|
|
|
RELEASE_URL="https://api.github.com/repos/${OWNER}/${REPO}/releases/tags/${RELEASE_TAG}"
|
|
|
|
|
|
|
|
#if [ "$LAST_RELEASE_ID" = null]
|
|
|
|
# then
|
|
|
|
# @TODO add error checking around creating new release if release/tag already exists
|
|
|
|
echo "$LINE_PREFIX Creating new release/tag of ${RELEASE_TAG}"
|
|
|
|
curl \
|
|
|
|
-H "Authorization:token $TOKEN" \
|
|
|
|
-H "Accept: application/vnd.github.v3+json" \
|
|
|
|
https://api.github.com/repos/$OWNER/$REPO/releases \
|
|
|
|
-d "{\"tag_name\":\"${RELEASE_TAG}\", \"prerelease\": true }"
|
|
|
|
#else
|
|
|
|
# echo "$LINE_PREFIX A release did exist and the most recent release id was '$RELEASE'"
|
|
|
|
#fi
|
|
|
|
|
|
|
|
LAST_RELEASE_ID=$(curl -# -XGET -H "Authorization:token $TOKEN" -H 'Content-Type: application/json' "$RELEASE_URL" | jq -r '.id')
|
2017-01-15 20:05:10 +02:00
|
|
|
|
2021-11-21 17:29:23 +02:00
|
|
|
echo "$LINE_PREFIX The last release id was $LAST_RELEASE_ID"
|
2017-01-15 20:05:10 +02:00
|
|
|
|
2016-11-24 03:57:46 +02:00
|
|
|
#find ./Hack -maxdepth 0 -type d | # uncomment to test 1 font
|
2021-11-26 17:49:18 +02:00
|
|
|
find ./ -name "$search_pattern" | # uncomment to test all font
|
2016-11-21 05:34:24 +02:00
|
|
|
while read -r filename
|
|
|
|
do
|
|
|
|
|
|
|
|
basename=$(basename "$filename")
|
2016-11-24 03:57:46 +02:00
|
|
|
|
2021-11-21 17:29:23 +02:00
|
|
|
printf "$LINE_PREFIX Uploading %s \n" "$basename"
|
2016-11-21 05:34:24 +02:00
|
|
|
|
2021-11-21 17:29:23 +02:00
|
|
|
curl \
|
|
|
|
-# -XPOST \
|
|
|
|
-H "Authorization:token $TOKEN" \
|
|
|
|
-H "Content-Type:application/octet-stream" \
|
|
|
|
--data-binary @"$basename" https://uploads.github.com/repos/"$OWNER"/"$REPO"/releases/"$LAST_RELEASE_ID"/assets?name="$basename"
|
2016-11-21 05:34:24 +02:00
|
|
|
|
2016-11-24 03:57:46 +02:00
|
|
|
#exit # uncomment to test only 1 zip
|
2016-11-21 05:34:24 +02:00
|
|
|
|
|
|
|
done
|