vscodestat/gitearelease.sh
2024-08-13 00:03:54 +02:00

40 lines
1.2 KiB
Bash

#!/bin/bash
# Variables
# GITEA_TOKEN="xxxxxxxxxx"
# DRONE_TAG="1.1.6"
# DRONE_REPO_NAME="vscodestat"
# DRONE_REPO_OWNER="root"
GITEA_API_URL="https://gitea.raphaelpiccolo.com/api/v1"
RELEASE_NAME="Release ${DRONE_TAG}"
RELEASE_BODY="vscode extension generated"
ARTIFACT_PATH="${DRONE_REPO_NAME}-${DRONE_TAG}.vsix"
# Create a release
response=$(curl -s -X POST "${GITEA_API_URL}/repos/${DRONE_REPO_OWNER}/${DRONE_REPO_NAME}/releases" \
-H "Authorization: token ${GITEA_TOKEN}" \
-H "Content-Type: application/json" \
-d "{
\"tag_name\": \"${DRONE_TAG}\",
\"name\": \"${RELEASE_NAME}\",
\"body\": \"${RELEASE_BODY}\",
\"draft\": false,
\"prerelease\": false
}")
# Extract release ID from the response
release_id=$(echo $response | jq '.id')
if [ -z "$release_id" ]; then
echo "Failed to create release"
exit 1
fi
# Upload the artifact
curl -s -X POST "${GITEA_API_URL}/repos/${DRONE_REPO_OWNER}/${DRONE_REPO_NAME}/releases/${release_id}/assets?name=$(basename ${ARTIFACT_PATH})" \
-H "Authorization: token ${GITEA_TOKEN}" \
-H "Content-Type: $(file -b --mime-type ${ARTIFACT_PATH})" \
--data-binary @"${ARTIFACT_PATH}"
echo "Artifact uploaded successfully."