@@ -41,247 +41,111 @@ jobs:
4141 TAG="${{ github.event.client_payload.release_tag }}"
4242 else
4343 # Scheduled check - get latest release
44- TAG=$(curl -s https://api.github.com/repos/${{ secrets.SENTIENCE_CHROME_REPO }}/releases/latest | jq -r '.tag_name // empty')
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')
46+
47+ # Check if we already processed this tag (check if branch exists)
48+ if git ls-remote --exit-code --heads origin "sync-extension-$TAG"; then
49+ echo "Branch for $TAG already exists, skipping."
50+ echo "skip=true" >> $GITHUB_OUTPUT
51+ exit 0
52+ fi
4553 fi
4654
47- if [ -z "$TAG" ] || [ "$TAG" == "null" ]; then
48- echo "No release found, skipping"
49- echo "skip=true" >> $GITHUB_OUTPUT
50- exit 0
55+ if [ -z "$TAG" ]; then
56+ echo "Could not determine release tag."
57+ exit 1
5158 fi
5259
60+ echo "Syncing tag: $TAG"
5361 echo "tag=$TAG" >> $GITHUB_OUTPUT
54- echo "Release tag: $TAG"
5562
5663 - name : Download extension files
5764 if : steps.release.outputs.skip != 'true'
5865 run : |
5966 TAG="${{ steps.release.outputs.tag }}"
6067 REPO="${{ secrets.SENTIENCE_CHROME_REPO }}"
6168
62- # Download release assets
69+ # Setup temp directory
6370 mkdir -p extension-temp
6471 cd extension-temp
6572
66- # Download individual files from release (reliable method - no zip)
67- echo "📁 Downloading individual files from release..."
68- echo "Available release assets:"
69- curl -s -H "Authorization: token ${{ secrets.SENTIENCE_CHROME_TOKEN }}" \
70- "https://api.github.com/repos/$REPO/releases/tags/$TAG" | \
71- jq -r '.assets[] | select(.name | endswith(".js") or endswith(".wasm") or endswith(".json") or endswith(".d.ts")) | .name' || true
73+ echo "⬇️ Fetching release assets for $TAG from $REPO..."
7274
73- curl -L -H "Authorization: token ${{ secrets.SENTIENCE_CHROME_TOKEN }}" \
75+ # 1. Get the URL for 'extension-files.tar.gz' specifically
76+ # We query the release assets API and filter by name
77+ ASSET_URL=$(curl -s -H "Authorization: token ${{ secrets.SENTIENCE_CHROME_TOKEN }}" \
7478 "https://api.github.com/repos/$REPO/releases/tags/$TAG" | \
75- jq -r '.assets[] | select(.name | endswith(".js") or endswith(".wasm") or endswith(".json") or endswith(".d.ts")) | "\(.browser_download_url)|\(.name)"' | \
76- while IFS='|' read -r url name; do
77- if [ -n "$url" ] && [ "$url" != "null" ] && [ -n "$name" ]; then
78- # Handle asset names that might have paths like "pkg/sentience_core.js" or "extension-package/manifest.json"
79- # GitHub releases might preserve directory structure in asset names
80- # Strip "extension-package/" prefix if present, as we'll handle it in copy step
81- if [[ "$name" == extension-package/* ]]; then
82- # Asset name is "extension-package/manifest.json" - strip prefix
83- filename="${name#extension-package/}"
84- dir=$(dirname "$filename")
85- if [ "$dir" != "." ]; then
86- mkdir -p "$dir"
87- fi
88- echo " Downloading $name -> $filename"
89- curl -L -H "Authorization: token ${{ secrets.SENTIENCE_CHROME_TOKEN }}" "$url" -o "$filename"
90- elif [[ "$name" == pkg/* ]]; then
91- # Asset name is "pkg/sentience_core.js" - create pkg directory
92- mkdir -p pkg
93- filename=$(basename "$name")
94- echo " Downloading $name -> pkg/$filename"
95- curl -L -H "Authorization: token ${{ secrets.SENTIENCE_CHROME_TOKEN }}" "$url" -o "pkg/$filename"
96- else
97- # Asset name is just "manifest.json" - put at root
98- dir=$(dirname "$name")
99- if [ "$dir" != "." ]; then
100- mkdir -p "$dir"
101- fi
102- echo " Downloading $name"
103- curl -L -H "Authorization: token ${{ secrets.SENTIENCE_CHROME_TOKEN }}" "$url" -o "$name"
104- fi
105- fi
106- done
107-
108- # Verify downloaded files
109- echo "📋 Downloaded files structure:"
110- find . -type f -name "*.js" -o -name "*.wasm" -o -name "*.json" | sort
111- echo ""
112- echo "Directory structure:"
113- ls -laR . | head -50
114- echo ""
115- echo "🔍 Verifying critical files:"
116- if [ -f "manifest.json" ]; then
117- echo "✅ manifest.json found ($(wc -c < manifest.json) bytes)"
118- head -5 manifest.json
119- else
120- echo "❌ manifest.json NOT FOUND"
121- fi
122- if [ -d "pkg" ]; then
123- echo "✅ pkg directory found with $(ls -1 pkg | wc -l) files"
124- else
125- echo "❌ pkg directory NOT FOUND"
126- fi
127-
128- - name : Copy extension files
129- if : steps.release.outputs.skip != 'true'
130- run : |
131- # Create extension directory structure
132- mkdir -p src/extension/pkg
133-
134- # Copy extension files (handle both root and extension-package/ subdirectory)
135- # Check root first, then extension-package/ subdirectory
136- if [ -f "extension-temp/manifest.json" ]; then
137- size=$(wc -c < extension-temp/manifest.json)
138- if [ "$size" -gt 0 ]; then
139- echo "✅ Copying manifest.json ($size bytes)"
140- cp extension-temp/manifest.json src/extension/
141- # Verify copy
142- if [ -f "src/extension/manifest.json" ] && [ "$(wc -c < src/extension/manifest.json)" -gt 0 ]; then
143- echo "✅ manifest.json copied successfully"
144- else
145- echo "❌ manifest.json copy failed or file is empty"
146- exit 1
147- fi
148- else
149- echo "❌ manifest.json is empty ($size bytes)"
150- exit 1
151- fi
152- elif [ -f "extension-temp/extension-package/manifest.json" ]; then
153- size=$(wc -c < extension-temp/extension-package/manifest.json)
154- if [ "$size" -gt 0 ]; then
155- echo "✅ Copying manifest.json from extension-package/ ($size bytes)"
156- cp extension-temp/extension-package/manifest.json src/extension/
157- # Verify copy
158- if [ -f "src/extension/manifest.json" ] && [ "$(wc -c < src/extension/manifest.json)" -gt 0 ]; then
159- echo "✅ manifest.json copied successfully"
160- else
161- echo "❌ manifest.json copy failed or file is empty"
162- exit 1
163- fi
164- else
165- echo "❌ manifest.json is empty ($size bytes)"
166- exit 1
167- fi
168- else
169- echo "❌ manifest.json not found in extension-temp/"
170- echo "Available files:"
171- find extension-temp -type f | head -20
79+ jq -r '.assets[] | select(.name == "extension-files.tar.gz") | .browser_download_url')
80+
81+ if [ -z "$ASSET_URL" ] || [ "$ASSET_URL" == "null" ]; then
82+ echo "❌ Critical Error: extension-files.tar.gz not found in release assets!"
83+ echo "Debug: Listing available assets..."
84+ curl -s -H "Authorization: token ${{ secrets.SENTIENCE_CHROME_TOKEN }}" \
85+ "https://api.github.com/repos/$REPO/releases/tags/$TAG" | jq -r '.assets[].name'
17286 exit 1
17387 fi
88+
89+ # 2. Download the tarball
90+ echo "📦 Downloading tarball from $ASSET_URL..."
91+ curl -L -H "Authorization: token ${{ secrets.SENTIENCE_CHROME_TOKEN }}" \
92+ -H "Accept: application/octet-stream" \
93+ "$ASSET_URL" -o extension.tar.gz
94+
95+ # 3. Extract it
96+ echo "📂 Extracting..."
97+ tar -xzf extension.tar.gz
98+ rm extension.tar.gz
17499
175- if [ -f "extension-temp/content.js" ]; then
176- cp extension-temp/content.js src/extension/
177- elif [ -f "extension-temp/extension-package/content.js" ]; then
178- cp extension-temp/extension-package/content.js src/extension/
179- else
180- echo "⚠️ content.js not found"
181- fi
182-
183- if [ -f "extension-temp/background.js" ]; then
184- cp extension-temp/background.js src/extension/
185- elif [ -f "extension-temp/extension-package/background.js" ]; then
186- cp extension-temp/extension-package/background.js src/extension/
187- else
188- echo "⚠️ background.js not found"
189- fi
100+ # 4. Verify extraction
101+ echo "✅ Extraction complete. Contents:"
102+ ls -la
190103
191- if [ -f "extension-temp/injected_api.js" ]; then
192- cp extension-temp/injected_api.js src/extension/
193- elif [ -f "extension-temp/extension-package/injected_api.js" ]; then
194- cp extension-temp/extension-package/injected_api.js src/extension/
195- else
196- echo "⚠️ injected_api.js not found"
104+ if [ ! -f "manifest.json" ]; then
105+ echo "❌ Error: manifest.json missing after extraction"
106+ exit 1
197107 fi
198108
199- # Copy WASM files - try multiple locations and patterns
200- echo "🔍 Searching for pkg directory and WASM files..."
109+ - name : Update extension files
110+ if : steps.release.outputs.skip != 'true'
111+ run : |
112+ # Target directory in sdk-ts
113+ TARGET_DIR="sentience-chrome"
201114
202- # Check all possible locations
203- if [ -d "extension-temp/pkg" ]; then
204- echo "✅ Found pkg directory at extension-temp/pkg"
205- cp -r extension-temp/pkg/* src/extension/pkg/ 2>/dev/null || true
206- elif [ -d "extension-temp/extension-package/pkg" ]; then
207- echo "✅ Found pkg directory at extension-temp/extension-package/pkg"
208- cp -r extension-temp/extension-package/pkg/* src/extension/pkg/ 2>/dev/null || true
209- else
210- echo "⚠️ pkg directory not found, searching for individual files..."
211-
212- # Search for files in various locations
213- find extension-temp -name "sentience_core.js" -type f | while read file; do
214- echo " Found: $file"
215- cp "$file" src/extension/pkg/ 2>/dev/null || true
216- done
217-
218- find extension-temp -name "sentience_core_bg.wasm" -type f | while read file; do
219- echo " Found: $file"
220- cp "$file" src/extension/pkg/ 2>/dev/null || true
221- done
222-
223- find extension-temp -name "*.d.ts" -type f | while read file; do
224- echo " Found: $file"
225- cp "$file" src/extension/pkg/ 2>/dev/null || true
226- done
227- fi
115+ # Ensure target directory exists and is clean
116+ rm -rf "$TARGET_DIR"
117+ mkdir -p "$TARGET_DIR"
228118
229- # Verify copied files
230- echo "📋 Copied files:"
231- echo "Extension root:"
232- ls -la src/extension/ || echo "⚠️ Extension directory empty"
233- echo ""
234- echo "WASM files (pkg directory):"
235- if [ -d "src/extension/pkg" ]; then
236- ls -la src/extension/pkg/ || echo "⚠️ pkg directory empty"
237- else
238- echo "❌ ERROR: pkg directory not created!"
239- exit 1
240- fi
119+ # Copy files from temp directory
120+ cp -r extension-temp/* "$TARGET_DIR/"
241121
242- # Verify required files exist
243- if [ ! -f "src/extension/pkg/sentience_core.js" ]; then
244- echo "❌ ERROR: sentience_core.js not found!"
245- exit 1
246- fi
247- if [ ! -f "src/extension/pkg/sentience_core_bg.wasm" ]; then
248- echo "❌ ERROR: sentience_core_bg.wasm not found!"
122+ # Verify copy
123+ if [ ! -f "$TARGET_DIR/manifest.json" ]; then
124+ echo "❌ Failed to copy manifest.json to $TARGET_DIR"
249125 exit 1
250126 fi
251- echo "✅ All required WASM files verified"
252127
253- # Clean up temporary directory
254- cd ..
128+ # Cleanup
255129 rm -rf extension-temp
256- echo "🧹 Cleaned up extension-temp directory"
130+
131+ echo "✅ Extension files updated in $TARGET_DIR"
132+ ls -la "$TARGET_DIR"
257133
258134 - name : Check for changes
259135 if : steps.release.outputs.skip != 'true'
260136 id : changes
261137 run : |
262- git config --local user.email "action@github.com"
263- git config --local user.name "GitHub Action"
264-
265- # Show what files exist before adding
266- echo "📋 Files in src/extension before git add:"
267- find src/extension -type f | sort || echo "No files found"
268-
269- # Add all files including binary files
270- # Use -f to force add in case files are in .gitignore
271- git add -f src/extension/ || true
138+ git add sentience-chrome/
272139
273- # Show what was staged
274- echo "📋 Staged files:"
275- git diff --staged --name-only || echo "No staged files"
276-
277- # Check if there are actual changes
140+ # Check if anything actually changed
278141 if git diff --staged --quiet; then
142+ echo "No changes detected."
279143 echo "changed=false" >> $GITHUB_OUTPUT
280- echo "No changes detected"
281144 else
145+ echo "Changes detected."
282146 echo "changed=true" >> $GITHUB_OUTPUT
283- echo "Changes detected"
284- # Show file sizes to verify binary files are included
147+
148+ # Show staged files to verify binary files are included
285149 echo "📊 Staged file sizes:"
286150 git diff --staged --name-only | while read file; do
287151 if [ -f "$file" ]; then
@@ -295,9 +159,8 @@ jobs:
295159 if : steps.release.outputs.skip != 'true' && steps.changes.outputs.changed == 'true'
296160 uses : peter-evans/create-pull-request@v5
297161 with :
298- # Use PR_TOKEN if available (for repos with org restrictions), otherwise use GITHUB_TOKEN
299- # To use PAT: create secret named PR_TOKEN with a Personal Access Token that has 'repo' scope
300- token : ${{ secrets.PR_TOKEN }}
162+ # Use PR_TOKEN if available, otherwise GITHUB_TOKEN
163+ token : ${{ secrets.PR_TOKEN || secrets.GITHUB_TOKEN }}
301164 commit-message : " chore: sync extension files from sentience-chrome ${{ steps.release.outputs.tag }}"
302165 title : " Sync Extension: ${{ steps.release.outputs.tag }}"
303166 body : |
@@ -313,4 +176,3 @@ jobs:
313176 labels : |
314177 automated
315178 extension-sync
316-
0 commit comments