fix: use printf for JSON body and Authorization header for Gitea API
Release / build-and-release (push) Failing after 56s
Release / build-and-release (push) Failing after 56s
This commit is contained in:
@@ -61,12 +61,20 @@ jobs:
|
|||||||
ENDJSON
|
ENDJSON
|
||||||
|
|
||||||
- name: Create Release and upload assets
|
- name: Create Release and upload assets
|
||||||
|
env:
|
||||||
|
# Ini cara paling aman agar variabel terbaca oleh shell
|
||||||
|
MY_TOKEN: ${{ secrets.TOKEN_BUILD }}
|
||||||
run: |
|
run: |
|
||||||
TOKEN="${{ secrets.TOKEN_BUILD }}"
|
TOKEN="$MY_TOKEN"
|
||||||
|
# Gunakan variabel bawaan Gitea Actions untuk keandalan
|
||||||
REPO="${{ gitea.repository }}"
|
REPO="${{ gitea.repository }}"
|
||||||
TAG="${{ gitea.ref_name }}"
|
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")
|
JSON_BODY=$(printf '{"tag_name":"%s","name":"%s","body":"Release %s","draft":false,"prerelease":false}' "$TAG" "$TAG" "$TAG")
|
||||||
|
|
||||||
RELEASE_RESP=$(curl -s -X POST \
|
RELEASE_RESP=$(curl -s -X POST \
|
||||||
@@ -74,20 +82,37 @@ jobs:
|
|||||||
-H "Content-Type: application/json" \
|
-H "Content-Type: application/json" \
|
||||||
-d "$JSON_BODY" \
|
-d "$JSON_BODY" \
|
||||||
"$API/repos/$REPO/releases")
|
"$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]*')
|
# Cara lebih aman ambil ID (menghapus "id": dan tanda koma)
|
||||||
if [ -z "$RELEASE_ID" ]; then
|
RELEASE_ID=$(echo "$RELEASE_RESP" | grep -o '"id":[0-9]*' | cut -d':' -f2)
|
||||||
echo "Failed to create release"
|
|
||||||
|
if [ -z "$RELEASE_ID" ] || [ "$RELEASE_ID" = "null" ]; then
|
||||||
|
echo "Gagal membuat release. Response: $RELEASE_RESP"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
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
|
for FILE in wgrplane-linux-amd64 wgrplane-linux-arm64 latest.json; do
|
||||||
echo "Uploading $FILE..."
|
if [ -f "$FILE" ]; then
|
||||||
curl -s -X POST \
|
echo "Sedang mengupload: $FILE..."
|
||||||
-H "Authorization: token $TOKEN" \
|
UPLOAD_STATUS=$(curl -s -o /dev/null -w "%{http_code}" -X POST \
|
||||||
-F "attachment=@$FILE" \
|
-H "Authorization: token $TOKEN" \
|
||||||
"$API/repos/$REPO/releases/$RELEASE_ID/assets?name=$FILE"
|
-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
|
done
|
||||||
|
|
||||||
- name: Cleanup build artifacts
|
- name: Cleanup build artifacts
|
||||||
|
|||||||
Reference in New Issue
Block a user