53 lines
1.5 KiB
Bash
Executable File
53 lines
1.5 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# create-release.sh — create a Gitea release and attach dist/ assets.
|
|
#
|
|
# Required env vars (set by the workflow):
|
|
# GITEA_TOKEN Gitea API token with release write scope
|
|
# TAG_NAME tag name (e.g. v0.0.1-beta)
|
|
# API_URL Gitea API base URL (e.g. http://gitea.local/api/v1)
|
|
# REPOSITORY owner/repo
|
|
# SHA commit SHA the tag points at
|
|
|
|
set -euo pipefail
|
|
|
|
PAYLOAD=$(cat <<EOF
|
|
{
|
|
"tag_name": "${TAG_NAME}",
|
|
"target_commitish": "${SHA}",
|
|
"name": "Release ${TAG_NAME}",
|
|
"body": "Auto-generated release assets.",
|
|
"draft": false,
|
|
"prerelease": false
|
|
}
|
|
EOF
|
|
)
|
|
|
|
echo "Creating Gitea release for tag ${TAG_NAME}..."
|
|
|
|
RELEASE_RESPONSE=$(curl -fsS -X POST "${API_URL}/repos/${REPOSITORY}/releases" \
|
|
-H "accept: application/json" \
|
|
-H "authorization: token ${GITEA_TOKEN}" \
|
|
-H "Content-Type: application/json" \
|
|
-d "${PAYLOAD}")
|
|
|
|
RELEASE_ID=$(printf '%s' "${RELEASE_RESPONSE}" | grep -oP '"id":\s*\K[0-9]+' | head -n 1)
|
|
if [ -z "${RELEASE_ID}" ]; then
|
|
echo "ERROR: failed to create release. Response:"
|
|
echo "${RELEASE_RESPONSE}"
|
|
exit 1
|
|
fi
|
|
echo "Release created with ID ${RELEASE_ID}"
|
|
|
|
for asset in dist/*.whl dist/*.tar.gz; do
|
|
if [ -f "${asset}" ]; then
|
|
echo "Uploading ${asset}..."
|
|
curl -fsS -X POST "${API_URL}/repos/${REPOSITORY}/releases/${RELEASE_ID}/assets" \
|
|
-H "accept: application/json" \
|
|
-H "authorization: token ${GITEA_TOKEN}" \
|
|
-F "attachment=@${asset}"
|
|
echo
|
|
else
|
|
echo "Skipping ${asset} (not found)"
|
|
fi
|
|
done
|