-
Notifications
You must be signed in to change notification settings - Fork 0
259 lines (226 loc) · 10.5 KB
/
sync-extension.yml
File metadata and controls
259 lines (226 loc) · 10.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
name: Sync Extension from sentience-chrome
on:
repository_dispatch:
types: [extension-updated]
workflow_dispatch:
inputs:
release_tag:
description: 'Release tag from sentience-chrome (e.g., v1.0.0)'
required: true
type: string
schedule:
# Check for new releases daily at 2 AM UTC
- cron: '0 2 * * *'
jobs:
sync-extension:
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- name: Checkout sdk-python
uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
fetch-depth: 0 # Fetch all history for proper branching
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Determine release tag
id: release
run: |
if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then
TAG="${{ github.event.inputs.release_tag }}"
elif [ "${{ github.event_name }}" == "repository_dispatch" ]; then
TAG="${{ github.event.client_payload.release_tag }}"
else
# Scheduled check - get latest release
TAG=$(curl -s https://api.github.com/repos/${{ secrets.SENTIENCE_CHROME_REPO }}/releases/latest | jq -r '.tag_name // empty')
fi
if [ -z "$TAG" ] || [ "$TAG" == "null" ]; then
echo "No release found, skipping"
echo "skip=true" >> $GITHUB_OUTPUT
exit 0
fi
echo "tag=$TAG" >> $GITHUB_OUTPUT
echo "Release tag: $TAG"
- name: Download extension files
if: steps.release.outputs.skip != 'true'
run: |
TAG="${{ steps.release.outputs.tag }}"
REPO="${{ secrets.SENTIENCE_CHROME_REPO }}"
# Download release assets
mkdir -p extension-temp
cd extension-temp
# Download individual files from release (reliable method - no zip)
echo "📁 Downloading individual files from release..."
echo "Available release assets:"
curl -s -H "Authorization: token ${{ secrets.SENTIENCE_CHROME_TOKEN }}" \
"https://api.github.com/repos/$REPO/releases/tags/$TAG" | \
jq -r '.assets[] | select(.name | endswith(".js") or endswith(".wasm") or endswith(".json") or endswith(".d.ts")) | .name' || true
curl -L -H "Authorization: token ${{ secrets.SENTIENCE_CHROME_TOKEN }}" \
"https://api.github.com/repos/$REPO/releases/tags/$TAG" | \
jq -r '.assets[] | select(.name | endswith(".js") or endswith(".wasm") or endswith(".json") or endswith(".d.ts")) | "\(.browser_download_url)|\(.name)"' | \
while IFS='|' read -r url name; do
if [ -n "$url" ] && [ "$url" != "null" ] && [ -n "$name" ]; then
# Handle asset names that might have paths like "pkg/sentience_core.js"
# GitHub releases might preserve directory structure in asset names
# If name starts with "pkg/", we want to preserve that structure
# If name is just a filename, put it at root
if [[ "$name" == pkg/* ]]; then
# Asset name is "pkg/sentience_core.js" - create pkg directory
mkdir -p pkg
filename=$(basename "$name")
echo " Downloading $name -> pkg/$filename"
curl -L -H "Authorization: token ${{ secrets.SENTIENCE_CHROME_TOKEN }}" "$url" -o "pkg/$filename"
else
# Asset name is just "manifest.json" - put at root
dir=$(dirname "$name")
if [ "$dir" != "." ]; then
mkdir -p "$dir"
fi
echo " Downloading $name"
curl -L -H "Authorization: token ${{ secrets.SENTIENCE_CHROME_TOKEN }}" "$url" -o "$name"
fi
fi
done
# Verify downloaded files
echo "📋 Downloaded files structure:"
find . -type f -name "*.js" -o -name "*.wasm" -o -name "*.json" | sort
echo ""
echo "Directory structure:"
ls -laR . | head -50
- name: Copy extension files
if: steps.release.outputs.skip != 'true'
run: |
# Create extension directory structure
mkdir -p sentience/extension/pkg
# Copy extension files (handle both root and extension-package/ subdirectory)
# Check root first, then extension-package/ subdirectory
if [ -f "extension-temp/manifest.json" ]; then
cp extension-temp/manifest.json sentience/extension/
elif [ -f "extension-temp/extension-package/manifest.json" ]; then
cp extension-temp/extension-package/manifest.json sentience/extension/
else
echo "⚠️ manifest.json not found"
fi
if [ -f "extension-temp/content.js" ]; then
cp extension-temp/content.js sentience/extension/
elif [ -f "extension-temp/extension-package/content.js" ]; then
cp extension-temp/extension-package/content.js sentience/extension/
else
echo "⚠️ content.js not found"
fi
if [ -f "extension-temp/background.js" ]; then
cp extension-temp/background.js sentience/extension/
elif [ -f "extension-temp/extension-package/background.js" ]; then
cp extension-temp/extension-package/background.js sentience/extension/
else
echo "⚠️ background.js not found"
fi
if [ -f "extension-temp/injected_api.js" ]; then
cp extension-temp/injected_api.js sentience/extension/
elif [ -f "extension-temp/extension-package/injected_api.js" ]; then
cp extension-temp/extension-package/injected_api.js sentience/extension/
else
echo "⚠️ injected_api.js not found"
fi
# Copy WASM files - try multiple locations and patterns
echo "🔍 Searching for pkg directory and WASM files..."
# Check all possible locations
if [ -d "extension-temp/pkg" ]; then
echo "✅ Found pkg directory at extension-temp/pkg"
cp -r extension-temp/pkg/* sentience/extension/pkg/ 2>/dev/null || true
elif [ -d "extension-temp/extension-package/pkg" ]; then
echo "✅ Found pkg directory at extension-temp/extension-package/pkg"
cp -r extension-temp/extension-package/pkg/* sentience/extension/pkg/ 2>/dev/null || true
else
echo "⚠️ pkg directory not found, searching for individual files..."
# Search for files in various locations
find extension-temp -name "sentience_core.js" -type f | while read file; do
echo " Found: $file"
cp "$file" sentience/extension/pkg/ 2>/dev/null || true
done
find extension-temp -name "sentience_core_bg.wasm" -type f | while read file; do
echo " Found: $file"
cp "$file" sentience/extension/pkg/ 2>/dev/null || true
done
find extension-temp -name "*.d.ts" -type f | while read file; do
echo " Found: $file"
cp "$file" sentience/extension/pkg/ 2>/dev/null || true
done
fi
# Verify copied files
echo "📋 Copied files:"
echo "Extension root:"
ls -la sentience/extension/ || echo "⚠️ Extension directory empty"
echo ""
echo "WASM files (pkg directory):"
if [ -d "sentience/extension/pkg" ]; then
ls -la sentience/extension/pkg/ || echo "⚠️ pkg directory empty"
else
echo "❌ ERROR: pkg directory not created!"
exit 1
fi
# Verify required files exist
if [ ! -f "sentience/extension/pkg/sentience_core.js" ]; then
echo "❌ ERROR: sentience_core.js not found!"
exit 1
fi
if [ ! -f "sentience/extension/pkg/sentience_core_bg.wasm" ]; then
echo "❌ ERROR: sentience_core_bg.wasm not found!"
exit 1
fi
echo "✅ All required WASM files verified"
- name: Check for changes
if: steps.release.outputs.skip != 'true'
id: changes
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
# Show what files exist before adding
echo "📋 Files in sentience/extension before git add:"
find sentience/extension -type f | sort || echo "No files found"
# Add all files including binary files
# Use -f to force add in case files are in .gitignore
git add -f sentience/extension/ || true
# Show what was staged
echo "📋 Staged files:"
git diff --staged --name-only || echo "No staged files"
# Check if there are actual changes
if git diff --staged --quiet; then
echo "changed=false" >> $GITHUB_OUTPUT
echo "No changes detected"
else
echo "changed=true" >> $GITHUB_OUTPUT
echo "Changes detected"
# Show file sizes to verify binary files are included
echo "📊 Staged file sizes:"
git diff --staged --name-only | while read file; do
if [ -f "$file" ]; then
size=$(ls -lh "$file" | awk '{print $5}')
echo " $file: $size"
fi
done
fi
- name: Create Pull Request
if: steps.release.outputs.skip != 'true' && steps.changes.outputs.changed == 'true'
uses: peter-evans/create-pull-request@v5
with:
# Use PR_TOKEN if available (for repos with org restrictions), otherwise use GITHUB_TOKEN
# To use PAT: create secret named PR_TOKEN with a Personal Access Token that has 'repo' scope
token: ${{ secrets.PR_TOKEN }}
commit-message: "chore: sync extension files from sentience-chrome ${{ steps.release.outputs.tag }}"
title: "Sync Extension: ${{ steps.release.outputs.tag }}"
body: |
This PR syncs extension files from sentience-chrome release ${{ steps.release.outputs.tag }}.
**Files updated:**
- Extension manifest and scripts
- WASM binary and bindings
**Source:** [sentience-chrome release ${{ steps.release.outputs.tag }}](https://github.com/${{ secrets.SENTIENCE_CHROME_REPO }}/releases/tag/${{ steps.release.outputs.tag }})
branch: sync-extension-${{ steps.release.outputs.tag }}
delete-branch: true
labels: |
automated
extension-sync