Skip to content

Commit

Permalink
upup
Browse files Browse the repository at this point in the history
  • Loading branch information
ugurkocde committed Oct 28, 2024
1 parent d4d7795 commit 777efba
Showing 1 changed file with 17 additions and 75 deletions.
92 changes: 17 additions & 75 deletions .github/scripts/scrapers/github_desktop.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
#!/bin/bash

# Azure Storage settings
AZURE_STORAGE_ACCOUNT="$AZURE_STORAGE_ACCOUNT"
AZURE_CONTAINER="$AZURE_CONTAINER"
AZURE_SAS_TOKEN="$AZURE_SAS_TOKEN" # Will be set from GitHub Secrets

# Get the latest version from the changelog
VERSION=$(curl -s https://central.github.com/deployments/desktop/desktop/changelog.json | grep -o '"version":"[^"]*' | head -1 | cut -d'"' -f4)

Expand Down Expand Up @@ -67,97 +72,34 @@ python3 process_zip.py
# Clean up the temporary files
rm "$TEMP_ZIP" process_zip.py

# Check if release exists
RELEASE_TAG="github-desktop-latest"
RELEASE_INFO=$(curl -s \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${GITHUB_TOKEN}" \
-H "X-GitHub-Api-Version: 2022-11-28" \
"https://api.github.com/repos/${GITHUB_REPOSITORY}/releases/tags/${RELEASE_TAG}")

DMG_FILE="github_desktop.dmg"
BLOB_NAME="github-desktop/${VERSION}/${DMG_FILE}"

if [[ $(echo "$RELEASE_INFO" | jq -r '.message // empty') == "Not Found" ]]; then
# Create new release if it doesn't exist
echo "Creating new release..."
RELEASE_RESPONSE=$(curl -L \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${GITHUB_TOKEN}" \
-H "X-GitHub-Api-Version: 2022-11-28" \
"https://api.github.com/repos/${GITHUB_REPOSITORY}/releases" \
-d "{
\"tag_name\":\"${RELEASE_TAG}\",
\"name\":\"GitHub Desktop ${VERSION}\",
\"draft\":false,
\"prerelease\":false,
\"make_latest\":\"true\"
}")
RELEASE_ID=$(echo "$RELEASE_RESPONSE" | jq -r '.id')
else
# Update existing release
echo "Updating existing release..."
RELEASE_ID=$(echo "$RELEASE_INFO" | jq -r '.id')

# Delete existing assets
ASSETS=$(curl -s \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${GITHUB_TOKEN}" \
-H "X-GitHub-Api-Version: 2022-11-28" \
"https://api.github.com/repos/${GITHUB_REPOSITORY}/releases/${RELEASE_ID}/assets")

echo "$ASSETS" | jq -r '.[] | .id' | while read ASSET_ID; do
curl -X DELETE \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${GITHUB_TOKEN}" \
-H "X-GitHub-Api-Version: 2022-11-28" \
"https://api.github.com/repos/${GITHUB_REPOSITORY}/releases/assets/${ASSET_ID}"
done
fi
# Upload to Azure Blob Storage
echo "Uploading DMG to Azure Storage..."
UPLOAD_URL="https://${AZURE_STORAGE_ACCOUNT}.blob.core.windows.net/${AZURE_CONTAINER}/${BLOB_NAME}${AZURE_SAS_TOKEN}"

# Upload DMG file
echo "Uploading DMG file..."
UPLOAD_RESPONSE=$(curl -L \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${GITHUB_TOKEN}" \
-H "X-GitHub-Api-Version: 2022-11-28" \
-H "Content-Type: application/octet-stream" \
"https://uploads.github.com/repos/${GITHUB_REPOSITORY}/releases/${RELEASE_ID}/assets?name=${DMG_FILE}" \
--data-binary "@${DMG_FILE}")

echo "Upload response: $UPLOAD_RESPONSE"

UPLOAD_URL=$(echo "$UPLOAD_RESPONSE" | jq -r '.browser_download_url')

if [[ "$UPLOAD_URL" == "null" ]]; then
echo "Error uploading DMG file. Response:"
echo "$UPLOAD_RESPONSE" | jq '.'
exit 1
fi
curl -X PUT -H "x-ms-blob-type: BlockBlob" \
-H "Content-Type: application/octet-stream" \
--data-binary "@${DMG_FILE}" \
"${UPLOAD_URL}"

# Verify the file exists
echo "Verifying uploaded file..."
VERIFY_RESPONSE=$(curl -s -o /dev/null -w "%{http_code}" "$UPLOAD_URL")
if [[ "$VERIFY_RESPONSE" != "200" ]]; then
echo "Error: Unable to verify uploaded file at $UPLOAD_URL"
exit 1
fi
# Create the JSON file with Azure Storage URL
DOWNLOAD_URL="https://${AZURE_STORAGE_ACCOUNT}.blob.core.windows.net/${AZURE_CONTAINER}/${BLOB_NAME}${AZURE_SAS_TOKEN}"

# Create the JSON file
cat > "Apps/github_desktop.json" << EOF
{
"name": "GitHub Desktop",
"description": "GitHub Desktop is an application that enables you to interact with GitHub using a GUI",
"version": "$VERSION",
"url": "$UPLOAD_URL",
"url": "$DOWNLOAD_URL",
"bundleId": "com.github.GitHubClient",
"homepage": "https://desktop.github.com/",
"fileName": "github_desktop.dmg"
}
EOF

# Add to supported_apps.json
# Add to supported_apps.json if it doesn't exist
if [ -f "supported_apps.json" ]; then
if ! grep -q '"github_desktop":' supported_apps.json; then
sed -i '$ d' supported_apps.json
Expand Down

0 comments on commit 777efba

Please sign in to comment.