
Some checks failed
Build-Test-Publish / build (linux/amd64) (push) Failing after 24s
Build-Test-Publish / build (linux/arm64) (push) Failing after 26s
Build-Test-Publish / test-install-from-scratch (linux/amd64) (push) Has been skipped
Build-Test-Publish / test-install-from-scratch (linux/arm64) (push) Has been skipped
126 lines
3.5 KiB
Bash
Executable File
126 lines
3.5 KiB
Bash
Executable File
#!/bin/bash
|
|
set -euo pipefail
|
|
|
|
# Publishes bb64 to the Gitea Releases page for the repository.
|
|
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
|
|
ARCH=$(uname -m)
|
|
PROJECT="bb64"
|
|
OUTPUT="${SCRIPT_DIR}/output"
|
|
|
|
ARCH_ALIAS="amd64"
|
|
if [ "$ARCH" = "aarch64" ]; then
|
|
ARCH_ALIAS="arm64"
|
|
fi
|
|
|
|
# Increment version
|
|
VERSION_FILE="${SCRIPT_DIR}/src/version.h"
|
|
if [ ! -f "${VERSION_FILE}" ]; then
|
|
echo "${VERSION_FILE} not found!" >&2
|
|
exit 1
|
|
else
|
|
v=$(cat "${VERSION_FILE}" | grep -o 'static const char \*VERSION = "[0-9.]*";' | cut -d'"' -f2)
|
|
oldv=$v
|
|
v=$((v+1))
|
|
echo "Incrementing version from $oldv to $v" >&2
|
|
echo "static const char *VERSION = \"$v\";" > "${VERSION_FILE}"
|
|
fi
|
|
TAG="v$v"
|
|
|
|
# build release version
|
|
export CMAKE_BUILD_TYPE="Release"
|
|
|
|
docker build \
|
|
-t "${PROJECT}-build" \
|
|
-f "${SCRIPT_DIR}/Dockerfile.dropshell-build" \
|
|
--build-arg PROJECT="${PROJECT}" \
|
|
--build-arg CMAKE_BUILD_TYPE="${CMAKE_BUILD_TYPE}" \
|
|
--output "${OUTPUT}" \
|
|
"${SCRIPT_DIR}"
|
|
|
|
[ -f "${OUTPUT}/${PROJECT}" ] || die "Build failed."
|
|
|
|
cp "${OUTPUT}/${PROJECT}" "${OUTPUT}/${PROJECT}.${ARCH_ALIAS}"
|
|
cp "${OUTPUT}/${PROJECT}" "${OUTPUT}/${PROJECT}.${ARCH}"
|
|
|
|
# Find repo info from .git/config
|
|
REPO_URL=$(git config --get remote.origin.url)
|
|
if [[ ! $REPO_URL =~ gitea ]]; then
|
|
echo "Remote origin is not a Gitea repository: $REPO_URL" >&2
|
|
exit 1
|
|
fi
|
|
# Extract base URL, owner, and repo
|
|
# Example: https://gitea.example.com/username/reponame.git
|
|
BASE_URL=$(echo "$REPO_URL" | sed -E 's#(https?://[^/]+)/.*#\1#')
|
|
OWNER=$(echo "$REPO_URL" | sed -E 's#.*/([^/]+)/[^/]+(\.git)?$#\1#')
|
|
REPO=$(echo "$REPO_URL" | sed -E 's#.*/([^/]+)(\.git)?$#\1#')
|
|
|
|
API_URL="$BASE_URL/api/v1/repos/$OWNER/$REPO"
|
|
|
|
# Create release
|
|
RELEASE_DATA=$(cat <<EOF
|
|
{
|
|
"tag_name": "$TAG",
|
|
"name": "$TAG",
|
|
"body": "bb64 release $TAG",
|
|
"draft": false,
|
|
"prerelease": false,
|
|
"arch": ["${ARCH_ALIAS}"]
|
|
}
|
|
EOF
|
|
)
|
|
|
|
[ -n "$DOCKER_PUSH_TOKEN" ] || die "DOCKER_PUSH_TOKEN not set"
|
|
|
|
RELEASE_ID=$(curl -s -X POST "$API_URL/releases" \
|
|
-H "Content-Type: application/json" \
|
|
-H "Authorization: token $DOCKER_PUSH_TOKEN" \
|
|
-d "$RELEASE_DATA" | grep -o '"id":[0-9]*' | head -1 | cut -d: -f2)
|
|
|
|
if [ -z "$RELEASE_ID" ]; then
|
|
echo "Failed to create release on Gitea." >&2
|
|
exit 1
|
|
fi
|
|
|
|
# Upload binaries and install.sh
|
|
for FILE in ${PROJECT}.${ARCH_ALIAS} ${PROJECT}.${ARCH} install.sh; do
|
|
if [ -f "output/$FILE" ]; then
|
|
filetoupload="output/$FILE"
|
|
elif [ -f "$FILE" ]; then
|
|
filetoupload="$FILE"
|
|
else
|
|
continue
|
|
fi
|
|
|
|
# Auto-detect content type
|
|
ctype=$(file --mime-type -b "$filetoupload")
|
|
|
|
curl -s -X POST "$API_URL/releases/$RELEASE_ID/assets?name=$FILE" \
|
|
-H "Content-Type: $ctype" \
|
|
-H "Authorization: token $TOKEN" \
|
|
--data-binary @"$filetoupload"
|
|
echo "Uploaded $FILE to release $TAG as $ctype."
|
|
done
|
|
|
|
echo "Published bb64 version $v to $REPO_URL (tag $TAG) with binaries for $ARCH_ALIAS / $ARCH."
|
|
|
|
|
|
#--------------------------------------------------------------------------------
|
|
heading "Publishing ${PROJECT} as tool to getpkg.xyz"
|
|
|
|
# Create tool directory structure
|
|
TOOLDIR="${OUTPUT}/tool"
|
|
mkdir "${TOOLDIR}"
|
|
cp "${OUTPUT}/${PROJECT}" "${TOOLDIR}/${PROJECT}"
|
|
|
|
# Use getpkg to publish the tool
|
|
GETPKG="${SCRIPT_DIR}/../getpkg/output/getpkg"
|
|
if [ ! -f "$GETPKG" ]; then
|
|
GETPKG="${SCRIPT_DIR}/../getpkg/getpkg"
|
|
fi
|
|
|
|
if [ -f "$GETPKG" ]; then
|
|
"${GETPKG}" publish "${PROJECT}:${ARCH}" "${TOOLDIR}"
|
|
else
|
|
echo "Warning: getpkg not found, skipping tool publishing to getpkg.xyz"
|
|
fi
|