Skip to content

Commit 240610c

Browse files
author
SentienceDEV
committed
fix sync pipeline
1 parent 69ca5f1 commit 240610c

File tree

2 files changed

+59
-207
lines changed

2 files changed

+59
-207
lines changed

.github/.DS_Store

6 KB
Binary file not shown.

.github/workflows/sync-extension.yml

Lines changed: 59 additions & 207 deletions
Original file line numberDiff line numberDiff line change
@@ -41,247 +41,102 @@ 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/$](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
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
75+
ASSET_URL=$(curl -s -H "Authorization: token ${{ secrets.SENTIENCE_CHROME_TOKEN }}" \
76+
"[https://api.github.com/repos/$REPO/releases/tags/$TAG](https://api.github.com/repos/$REPO/releases/tags/$TAG)" | \
77+
jq -r '.assets[] | select(.name == "extension-files.tar.gz") | .browser_download_url')
78+
79+
if [ -z "$ASSET_URL" ] || [ "$ASSET_URL" == "null" ]; then
80+
echo "❌ Critical Error: extension-files.tar.gz not found in release assets!"
81+
curl -s -H "Authorization: token ${{ secrets.SENTIENCE_CHROME_TOKEN }}" \
82+
"[https://api.github.com/repos/$REPO/releases/tags/$TAG](https://api.github.com/repos/$REPO/releases/tags/$TAG)" | jq -r '.assets[].name'
83+
exit 1
84+
fi
85+
86+
echo "📦 Downloading tarball from $ASSET_URL..."
7387
curl -L -H "Authorization: token ${{ secrets.SENTIENCE_CHROME_TOKEN }}" \
74-
"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
88+
-H "Accept: application/octet-stream" \
89+
"$ASSET_URL" -o extension.tar.gz
90+
91+
echo "📂 Extracting..."
92+
tar -xzf extension.tar.gz
93+
rm extension.tar.gz
10794
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"
95+
if [ ! -f "manifest.json" ]; then
96+
echo "❌ Error: manifest.json missing after extraction"
97+
exit 1
12698
fi
12799
128-
- name: Copy extension files
100+
- name: Update extension files
129101
if: steps.release.outputs.skip != 'true'
130102
run: |
131-
# Create extension directory structure
132-
mkdir -p sentience/extension/pkg
103+
# Target directory in sdk-python (inside the package source)
104+
# Assuming structure: sdk-python/sentience/extension
105+
TARGET_DIR="sentience/extension"
133106
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 sentience/extension/
141-
# Verify copy
142-
if [ -f "sentience/extension/manifest.json" ] && [ "$(wc -c < sentience/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 sentience/extension/
157-
# Verify copy
158-
if [ -f "sentience/extension/manifest.json" ] && [ "$(wc -c < sentience/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
172-
exit 1
173-
fi
174-
175-
if [ -f "extension-temp/content.js" ]; then
176-
cp extension-temp/content.js sentience/extension/
177-
elif [ -f "extension-temp/extension-package/content.js" ]; then
178-
cp extension-temp/extension-package/content.js sentience/extension/
179-
else
180-
echo "⚠️ content.js not found"
181-
fi
107+
# Ensure target directory exists and is clean
108+
# Note: We preserve the directory structure, just update contents
109+
mkdir -p "$TARGET_DIR"
182110
183-
if [ -f "extension-temp/background.js" ]; then
184-
cp extension-temp/background.js sentience/extension/
185-
elif [ -f "extension-temp/extension-package/background.js" ]; then
186-
cp extension-temp/extension-package/background.js sentience/extension/
187-
else
188-
echo "⚠️ background.js not found"
189-
fi
111+
# Copy files from temp directory
112+
cp -r extension-temp/* "$TARGET_DIR/"
190113
191-
if [ -f "extension-temp/injected_api.js" ]; then
192-
cp extension-temp/injected_api.js sentience/extension/
193-
elif [ -f "extension-temp/extension-package/injected_api.js" ]; then
194-
cp extension-temp/extension-package/injected_api.js sentience/extension/
195-
else
196-
echo "⚠️ injected_api.js not found"
197-
fi
198-
199-
# Copy WASM files - try multiple locations and patterns
200-
echo "🔍 Searching for pkg directory and WASM files..."
201-
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/* sentience/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/* sentience/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" sentience/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" sentience/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" sentience/extension/pkg/ 2>/dev/null || true
226-
done
227-
fi
228-
229-
# Verify copied files
230-
echo "📋 Copied files:"
231-
echo "Extension root:"
232-
ls -la sentience/extension/ || echo "⚠️ Extension directory empty"
233-
echo ""
234-
echo "WASM files (pkg directory):"
235-
if [ -d "sentience/extension/pkg" ]; then
236-
ls -la sentience/extension/pkg/ || echo "⚠️ pkg directory empty"
237-
else
238-
echo "❌ ERROR: pkg directory not created!"
239-
exit 1
240-
fi
241-
242-
# Verify required files exist
243-
if [ ! -f "sentience/extension/pkg/sentience_core.js" ]; then
244-
echo "❌ ERROR: sentience_core.js not found!"
245-
exit 1
246-
fi
247-
if [ ! -f "sentience/extension/pkg/sentience_core_bg.wasm" ]; then
248-
echo "❌ ERROR: sentience_core_bg.wasm not found!"
114+
# Verify copy
115+
if [ ! -f "$TARGET_DIR/manifest.json" ]; then
116+
echo "❌ Failed to copy manifest.json to $TARGET_DIR"
249117
exit 1
250118
fi
251-
echo "✅ All required WASM files verified"
252119
253-
# Clean up temporary directory
254-
cd ..
120+
# Cleanup
255121
rm -rf extension-temp
256-
echo "🧹 Cleaned up extension-temp directory"
122+
123+
echo "✅ Extension files updated in $TARGET_DIR"
124+
ls -la "$TARGET_DIR"
257125
258126
- name: Check for changes
259127
if: steps.release.outputs.skip != 'true'
260128
id: changes
261129
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 sentience/extension before git add:"
267-
find sentience/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 sentience/extension/ || true
130+
git add sentience/extension/
272131
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
278132
if git diff --staged --quiet; then
133+
echo "No changes detected."
279134
echo "changed=false" >> $GITHUB_OUTPUT
280-
echo "No changes detected"
281135
else
136+
echo "Changes detected."
282137
echo "changed=true" >> $GITHUB_OUTPUT
283-
echo "Changes detected"
284-
# Show file sizes to verify binary files are included
138+
139+
# Show staged files
285140
echo "📊 Staged file sizes:"
286141
git diff --staged --name-only | while read file; do
287142
if [ -f "$file" ]; then
@@ -295,9 +150,7 @@ jobs:
295150
if: steps.release.outputs.skip != 'true' && steps.changes.outputs.changed == 'true'
296151
uses: peter-evans/create-pull-request@v5
297152
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 }}
153+
token: ${{ secrets.PR_TOKEN || secrets.GITHUB_TOKEN }}
301154
commit-message: "chore: sync extension files from sentience-chrome ${{ steps.release.outputs.tag }}"
302155
title: "Sync Extension: ${{ steps.release.outputs.tag }}"
303156
body: |
@@ -312,5 +165,4 @@ jobs:
312165
delete-branch: true
313166
labels: |
314167
automated
315-
extension-sync
316-
168+
extension-sync

0 commit comments

Comments
 (0)