aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAyose <ayosec@gmail.com>2024-10-24 00:00:00 +0000
committerAyose <ayosec@gmail.com>2024-10-24 00:00:00 +0000
commitecf278007a5fe024fe624c7dea4664239d81f44b (patch)
treeec1dc6ceed2c7b417acc71f4088891ff6c99e26c
parent8ec6c966658c140fb6fc2b3c4b32a099edf34a39 (diff)
downloadr-alacritty-ecf278007a5fe024fe624c7dea4664239d81f44b.tar.gz
r-alacritty-ecf278007a5fe024fe624c7dea4664239d81f44b.tar.bz2
r-alacritty-ecf278007a5fe024fe624c7dea4664239d81f44b.zip
Use the GitHub CLI client to upload release assets.
The binary for Linux is also added to the release. The `contents: write` permission is needed to create releases and upload the assets.
-rw-r--r--.github/workflows/release.yml10
-rwxr-xr-x.github/workflows/upload_asset.sh94
2 files changed, 16 insertions, 88 deletions
diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml
index 81d46970..e5e381c1 100644
--- a/.github/workflows/release.yml
+++ b/.github/workflows/release.yml
@@ -4,6 +4,9 @@ on:
push:
tags: ["v[0-9]+.[0-9]+.[0-9]+*"]
+permissions:
+ contents: write
+
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
CARGO_TERM_COLOR: always
@@ -70,6 +73,8 @@ jobs:
libxcb-xfixes0-dev libxkbcommon-dev python3 scdoc
- name: Test
run: cargo test --release
+ - name: Build
+ run: cargo build --release
- name: Generate manpages
run: |
scdoc < extra/man/alacritty.1.scd | gzip -c > "./alacritty.1.gz"
@@ -78,7 +83,12 @@ jobs:
scdoc < extra/man/alacritty-bindings.5.scd | gzip -c > "./alacritty-bindings.5.gz"
- name: Upload Assets
run: |
+ binpath="alacritty-linux-$(uname -m).gz"
+ gzip -9 --stdout target/release/alacritty > "$binpath"
+
mv ./extra/logo/alacritty-term.svg ./Alacritty.svg
+
+ ./.github/workflows/upload_asset.sh "$binpath"
./.github/workflows/upload_asset.sh ./Alacritty.svg $GITHUB_TOKEN
./.github/workflows/upload_asset.sh ./alacritty.1.gz $GITHUB_TOKEN
./.github/workflows/upload_asset.sh ./alacritty-msg.1.gz $GITHUB_TOKEN
diff --git a/.github/workflows/upload_asset.sh b/.github/workflows/upload_asset.sh
index 9e1f40e5..7b88f376 100755
--- a/.github/workflows/upload_asset.sh
+++ b/.github/workflows/upload_asset.sh
@@ -1,96 +1,14 @@
#!/bin/bash
-# Assure parameters are correct.
-if [ $# -lt 2 ]; then
- echo "Usage: upload_asset.sh <FILE> <TOKEN>"
- exit 1
-fi
+set -xeuo pipefail
-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 \
- --http1.1 \
- -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/' \
-)
+tag=$(git describe --tags --abbrev=0)
-# 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 \
- --http1.1 \
- -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/' \
- )
+if ! gh release view "$tag"
+then
+ gh release create --draft "$tag"
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 \
- --http1.1 \
- -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"
+gh release upload "$tag" "$file_path"