fix: use printf for JSON body and Authorization header for Gitea API
Release / build-and-release (push) Failing after 56s

This commit is contained in:
datadunia
2026-05-08 04:14:57 +07:00
parent 4a3d099ff9
commit c42683e968
+36 -11
View File
@@ -61,12 +61,20 @@ jobs:
ENDJSON
- name: Create Release and upload assets
env:
# Ini cara paling aman agar variabel terbaca oleh shell
MY_TOKEN: ${{ secrets.TOKEN_BUILD }}
run: |
TOKEN="${{ secrets.TOKEN_BUILD }}"
TOKEN="$MY_TOKEN"
# Gunakan variabel bawaan Gitea Actions untuk keandalan
REPO="${{ gitea.repository }}"
TAG="${{ gitea.ref_name }}"
API="https://git.datadunia.com/api/v1"
API="${{ gitea.server_url }}/api/v1"
echo "Menciptakan release untuk tag: $TAG"
# 1. Create Release
# Menggunakan -w "%{http_code}" untuk debugging jika gagal
JSON_BODY=$(printf '{"tag_name":"%s","name":"%s","body":"Release %s","draft":false,"prerelease":false}' "$TAG" "$TAG" "$TAG")
RELEASE_RESP=$(curl -s -X POST \
@@ -74,20 +82,37 @@ jobs:
-H "Content-Type: application/json" \
-d "$JSON_BODY" \
"$API/repos/$REPO/releases")
echo "Release response: $RELEASE_RESP"
RELEASE_ID=$(echo "$RELEASE_RESP" | grep -o '"id":[0-9]*' | head -1 | grep -o '[0-9]*')
if [ -z "$RELEASE_ID" ]; then
echo "Failed to create release"
# Cara lebih aman ambil ID (menghapus "id": dan tanda koma)
RELEASE_ID=$(echo "$RELEASE_RESP" | grep -o '"id":[0-9]*' | cut -d':' -f2)
if [ -z "$RELEASE_ID" ] || [ "$RELEASE_ID" = "null" ]; then
echo "Gagal membuat release. Response: $RELEASE_RESP"
exit 1
fi
echo "Release berhasil dibuat dengan ID: $RELEASE_ID"
# 2. Upload 3 File menggunakan loop
# Sesuai Swagger: POST /repos/{owner}/{repo}/releases/{id}/assets
for FILE in wgrplane-linux-amd64 wgrplane-linux-arm64 latest.json; do
echo "Uploading $FILE..."
curl -s -X POST \
-H "Authorization: token $TOKEN" \
-F "attachment=@$FILE" \
"$API/repos/$REPO/releases/$RELEASE_ID/assets?name=$FILE"
if [ -f "$FILE" ]; then
echo "Sedang mengupload: $FILE..."
UPLOAD_STATUS=$(curl -s -o /dev/null -w "%{http_code}" -X POST \
-H "Authorization: token $TOKEN" \
-F "attachment=@$FILE" \
"$API/repos/$REPO/releases/$RELEASE_ID/assets?name=$FILE")
if [ "$UPLOAD_STATUS" == "201" ]; then
echo "Berhasil upload $FILE"
else
echo "Gagal upload $FILE (HTTP Status: $UPLOAD_STATUS)"
exit 1
fi
else
echo "Error: File $FILE tidak ditemukan di direktori!"
exit 1
fi
done
- name: Cleanup build artifacts