4141 TAG="${{ github.event.client_payload.release_tag }}"
4242 else
4343 # Scheduled check - get latest release
44- TAG=$(curl -s -H "Authorization: token ${{ secrets.SENTIENCE_CHROME_TOKEN }}" \
45- "https://api.github.com/repos/${{ secrets.SENTIENCE_CHROME_REPO }}/releases/latest" | jq -r '.tag_name // empty')
44+ # Note: This also needs a token with access to the private repo
45+ HTTP_CODE=$(curl -s -o latest_release.json -w "%{http_code}" \
46+ -H "Authorization: token ${{ secrets.SENTIENCE_CHROME_TOKEN }}" \
47+ "https://api.github.com/repos/${{ secrets.SENTIENCE_CHROME_REPO }}/releases/latest")
48+
49+ if [ "$HTTP_CODE" != "200" ]; then
50+ echo "❌ Failed to fetch latest release. HTTP Code: $HTTP_CODE"
51+ cat latest_release.json
52+ exit 1
53+ fi
54+
55+ TAG=$(cat latest_release.json | jq -r '.tag_name // empty')
4656
4757 # Check if we already processed this tag
4858 if git ls-remote --exit-code --heads origin "sync-extension-$TAG"; then
7282
7383 echo "⬇️ Fetching release info for $TAG from $REPO..."
7484
75- # Capture response to file for debugging
76- # Use -f to fail on HTTP errors (404/403) so we don't parse error HTML
77- # We explicitly print the response body on failure for debugging
85+ # 1. Get Release Info
7886 HTTP_CODE=$(curl -s -w "%{http_code}" -o release.json \
7987 -H "Authorization: token ${{ secrets.SENTIENCE_CHROME_TOKEN }}" \
8088 "https://api.github.com/repos/$REPO/releases/tags/$TAG")
@@ -86,39 +94,50 @@ jobs:
8694 exit 1
8795 fi
8896
89- # Check if we got a valid release object (sanity check for "Not Found" message)
90- if grep -q "Not Found" release.json; then
91- echo "❌ Critical Error: Release tag $TAG not found in repo $REPO (API returned 404 message)"
92- cat release.json
93- exit 1
94- fi
95-
96- # Robust extraction with safe navigation operator
97- # The ? prevents jq from crashing if .assets is missing/null
98- ASSET_URL=$(cat release.json | jq -r '.assets[]? | select(.name == "extension-files.tar.gz") | .browser_download_url')
99-
97+ # Check for asset URL
98+ ASSET_URL=$(cat release.json | jq -r '.assets[]? | select(.name == "extension-files.tar.gz") | .url')
99+
100100 if [ -z "$ASSET_URL" ] || [ "$ASSET_URL" == "null" ]; then
101101 echo "❌ Critical Error: extension-files.tar.gz not found in release assets!"
102- echo "Available assets in release :"
103- cat release.json | jq -r '.assets[].name' || echo "No assets found or invalid JSON"
102+ echo "Available assets:"
103+ cat release.json | jq -r '.assets[].name'
104104 exit 1
105105 fi
106106
107- # 2. Download the tarball
108- echo "📦 Downloading tarball from $ASSET_URL..."
109- curl -L -H "Authorization: token ${{ secrets.SENTIENCE_CHROME_TOKEN }}" \
107+ echo "📦 Downloading tarball from asset API endpoint..."
108+ # NOTE: For private repos, we must use the API URL (.url) with Accept: application/octet-stream header
109+ # Using .browser_download_url often redirects to S3 which breaks auth headers
110+
111+ HTTP_CODE=$(curl -L -s -w "%{http_code}" -o extension.tar.gz \
112+ -H "Authorization: token ${{ secrets.SENTIENCE_CHROME_TOKEN }}" \
110113 -H "Accept: application/octet-stream" \
111- "$ASSET_URL" -o extension.tar.gz
114+ "$ASSET_URL")
115+
116+ if [ "$HTTP_CODE" != "200" ] && [ "$HTTP_CODE" != "302" ]; then
117+ echo "❌ Failed to download asset. HTTP Code: $HTTP_CODE"
118+ # If it's a small file (error message), show it
119+ if [ $(stat -c%s extension.tar.gz) -lt 1000 ]; then
120+ cat extension.tar.gz
121+ fi
122+ exit 1
123+ fi
112124
113- # 3. Extract it
125+ # 3. Verify File Type before extracting
126+ FILE_TYPE=$(file -b --mime-type extension.tar.gz)
127+ echo "📄 Downloaded file type: $FILE_TYPE"
128+
129+ if [[ "$FILE_TYPE" != *"gzip"* ]] && [[ "$FILE_TYPE" != *"octet-stream"* ]]; then
130+ echo "❌ Error: Downloaded file is not a gzip archive. It is: $FILE_TYPE"
131+ echo "First 100 bytes:"
132+ head -c 100 extension.tar.gz
133+ exit 1
134+ fi
135+
136+ # 4. Extract
114137 echo "📂 Extracting..."
115138 tar -xzf extension.tar.gz
116139 rm extension.tar.gz
117140
118- # 4. Verify extraction
119- echo "✅ Extraction complete. Contents:"
120- ls -la
121-
122141 if [ ! -f "manifest.json" ]; then
123142 echo "❌ Error: manifest.json missing after extraction"
124143 exit 1
@@ -131,7 +150,6 @@ jobs:
131150 TARGET_DIR="sentience/extension"
132151
133152 # Ensure target directory exists and is clean
134- # Note: We preserve the directory structure, just update contents
135153 rm -rf "$TARGET_DIR"
136154 mkdir -p "$TARGET_DIR"
137155
0 commit comments