mirror of
https://github.com/alacritty/alacritty.git
synced 2026-12-06 11:12:25 +03:00
This removes all CI builds from travis-ci, due to their recent changes in policy and harsh limitations on builds. With build times over 2 hours, it was a significant hindrance to development. Instead of Travis CI, the CI is now split on Sourcehut and GitHub. Since Sourcehut only supports Linux/BSD, all builds on those operating systems are executed there. The GitHub Actions CI is used to build for Windows/macOS, which are not available on Sourcehut. Since asset deployment for releases requires builds on all platforms, this is also done on GitHub actions. Though the new `upload_asset.sh` script makes sure that migration in the future is fairly simple and we do not tie ourselves to the overly complicated GitHub Actions ecosystem.
94 lines
2.3 KiB
Bash
Executable File
94 lines
2.3 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# Assure parameters are correct.
|
|
if [ $# -lt 2 ]; then
|
|
echo "Usage: upload_asset.sh <FILE> <TOKEN>"
|
|
exit 1
|
|
fi
|
|
|
|
repo="alacritty/alacritty"
|
|
file_path=$1
|
|
bearer=$2
|
|
|
|
echo "Starting asset upload from $file_path to $repo."
|
|
|
|
# Get the release for this tag.
|
|
tag="$(git describe --tags --abbrev=0)"
|
|
|
|
# Make sure the git tag could be determined.
|
|
if [ -z "$tag" ]; then
|
|
printf "\e[31mError: Unable to find git tag\e[0m\n"
|
|
exit 1
|
|
fi
|
|
|
|
echo "Git tag: $tag"
|
|
|
|
# Get the upload URL for the current tag.
|
|
#
|
|
# Since this might be a draft release, we can't just use the /releases/tags/:tag
|
|
# endpoint which only shows published releases.
|
|
echo "Checking for existing release..."
|
|
upload_url=$(\
|
|
curl \
|
|
-H "Authorization: Bearer $bearer" \
|
|
"https://api.github.com/repos/$repo/releases" \
|
|
2> /dev/null \
|
|
| grep -E "(upload_url|tag_name)" \
|
|
| paste - - \
|
|
| grep -e "tag_name\": \"$tag" \
|
|
| head -n 1 \
|
|
| sed 's/.*\(https.*assets\).*/\1/' \
|
|
)
|
|
|
|
# Create a new release if we didn't find one for this tag.
|
|
if [ -z "$upload_url" ]; then
|
|
echo "No release found."
|
|
echo "Creating new release..."
|
|
|
|
# Create new release.
|
|
response=$(
|
|
curl -f \
|
|
-X POST \
|
|
-H "Authorization: Bearer $bearer" \
|
|
-d "{\"tag_name\":\"$tag\",\"draft\":true}" \
|
|
"https://api.github.com/repos/$repo/releases" \
|
|
2> /dev/null\
|
|
)
|
|
|
|
# Abort if the release could not be created.
|
|
if [ $? -ne 0 ]; then
|
|
printf "\e[31mError: Unable to create new release.\e[0m\n"
|
|
exit 1;
|
|
fi
|
|
|
|
# Extract upload URL from new release.
|
|
upload_url=$(\
|
|
echo "$response" \
|
|
| grep "upload_url" \
|
|
| sed 's/.*: "\(.*\){.*/\1/' \
|
|
)
|
|
fi
|
|
|
|
# Propagate error if no URL for asset upload could be found.
|
|
if [ -z "$upload_url" ]; then
|
|
printf "\e[31mError: Unable to find release upload url.\e[0m\n"
|
|
exit 2
|
|
fi
|
|
|
|
# Upload the file to the tag's release.
|
|
file_name=${file_path##*/}
|
|
echo "Uploading asset $file_name to $upload_url..."
|
|
curl -f \
|
|
-X POST \
|
|
-H "Authorization: Bearer $bearer" \
|
|
-H "Content-Type: application/octet-stream" \
|
|
--data-binary @"$file_path" \
|
|
"$upload_url?name=$file_name" \
|
|
&> /dev/null \
|
|
|| { \
|
|
printf "\e[31mError: Unable to upload asset.\e[0m\n" \
|
|
&& exit 3; \
|
|
}
|
|
|
|
printf "\e[32mSuccess\e[0m\n"
|