Skip to content

Commit 263b463

Browse files
authored
Merge pull request #213 from SentienceAPI/new_release
new release
2 parents 6b3af66 + 7f3021b commit 263b463

File tree

5 files changed

+506
-3
lines changed

5 files changed

+506
-3
lines changed

.github/workflows/release.yml

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ on:
99
description: 'Version to release (e.g., 0.1.0)'
1010
required: true
1111
type: string
12+
extension_release_tag:
13+
description: 'Optional extension release tag (e.g., v1.2.3). Defaults to latest if omitted.'
14+
required: false
15+
type: string
1216

1317
jobs:
1418
build-and-publish:
@@ -50,6 +54,115 @@ jobs:
5054
VERSION="${{ steps.version.outputs.version }}"
5155
sed -i "s/^__version__ = \".*\"/__version__ = \"$VERSION\"/" predicate/__init__.py
5256
57+
- name: Sync extension files if missing
58+
run: |
59+
set -euo pipefail
60+
61+
REQUIRED_FILES=(
62+
"predicate/extension/manifest.json"
63+
"predicate/extension/content.js"
64+
"predicate/extension/background.js"
65+
"predicate/extension/injected_api.js"
66+
"predicate/extension/pkg/sentience_core.js"
67+
"predicate/extension/pkg/sentience_core_bg.wasm"
68+
)
69+
70+
has_all_required_files() {
71+
for file in "${REQUIRED_FILES[@]}"; do
72+
if [ ! -f "$file" ]; then
73+
return 1
74+
fi
75+
done
76+
return 0
77+
}
78+
79+
if has_all_required_files; then
80+
echo "✅ Extension files already present in repository"
81+
exit 0
82+
fi
83+
84+
echo "⚠️ Extension files missing locally. Attempting auto-sync from extension release..."
85+
86+
REPO="${{ secrets.SENTIENCE_CHROME_REPO }}"
87+
TOKEN="${{ secrets.SENTIENCE_CHROME_TOKEN }}"
88+
89+
if [ -z "$REPO" ] || [ -z "$TOKEN" ]; then
90+
echo "❌ Cannot auto-sync extension files: SENTIENCE_CHROME_REPO or SENTIENCE_CHROME_TOKEN is not configured."
91+
echo "Please run sync-extension workflow (or sync manually) before release."
92+
exit 1
93+
fi
94+
95+
TAG_INPUT="${{ github.event.inputs.extension_release_tag }}"
96+
if [ -n "$TAG_INPUT" ]; then
97+
TAG="$TAG_INPUT"
98+
echo "Using extension release tag from input: $TAG"
99+
else
100+
echo "No extension_release_tag provided. Resolving latest release tag from $REPO..."
101+
HTTP_CODE=$(curl -s -o latest_release.json -w "%{http_code}" \
102+
-H "Authorization: token $TOKEN" \
103+
"https://api.github.com/repos/$REPO/releases/latest")
104+
105+
if [ "$HTTP_CODE" != "200" ]; then
106+
echo "❌ Failed to fetch latest extension release (HTTP $HTTP_CODE)"
107+
cat latest_release.json
108+
exit 1
109+
fi
110+
111+
TAG=$(jq -r '.tag_name // empty' latest_release.json)
112+
if [ -z "$TAG" ]; then
113+
echo "❌ Could not determine latest extension release tag"
114+
exit 1
115+
fi
116+
echo "Resolved latest extension tag: $TAG"
117+
fi
118+
119+
mkdir -p extension-temp
120+
cd extension-temp
121+
122+
HTTP_CODE=$(curl -s -w "%{http_code}" -o release.json \
123+
-H "Authorization: token $TOKEN" \
124+
"https://api.github.com/repos/$REPO/releases/tags/$TAG")
125+
126+
if [ "$HTTP_CODE" != "200" ]; then
127+
echo "❌ Failed to fetch extension release info for tag $TAG (HTTP $HTTP_CODE)"
128+
cat release.json
129+
exit 1
130+
fi
131+
132+
ASSET_URL=$(jq -r '.assets[]? | select(.name == "extension-files.tar.gz") | .url' release.json)
133+
if [ -z "$ASSET_URL" ] || [ "$ASSET_URL" = "null" ]; then
134+
echo "❌ extension-files.tar.gz not found on extension release $TAG"
135+
echo "Available assets:"
136+
jq -r '.assets[]?.name' release.json
137+
exit 1
138+
fi
139+
140+
HTTP_CODE=$(curl -L -s -w "%{http_code}" -o extension.tar.gz \
141+
-H "Authorization: token $TOKEN" \
142+
-H "Accept: application/octet-stream" \
143+
"$ASSET_URL")
144+
145+
if [ "$HTTP_CODE" != "200" ] && [ "$HTTP_CODE" != "302" ]; then
146+
echo "❌ Failed to download extension tarball (HTTP $HTTP_CODE)"
147+
exit 1
148+
fi
149+
150+
tar -xzf extension.tar.gz
151+
cd ..
152+
153+
TARGET_DIR="predicate/extension"
154+
rm -rf "$TARGET_DIR"
155+
mkdir -p "$TARGET_DIR"
156+
cp -r extension-temp/* "$TARGET_DIR/"
157+
rm -rf extension-temp latest_release.json
158+
159+
if has_all_required_files; then
160+
echo "✅ Extension files synced successfully from $REPO@$TAG"
161+
else
162+
echo "❌ Extension sync completed but required files are still missing"
163+
exit 1
164+
fi
165+
53166
- name: Verify extension files are present
54167
run: |
55168
echo "🔍 Verifying extension files are included..."

.github/workflows/sync-extension.yml

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,9 +156,24 @@ jobs:
156156
# Copy files from temp directory
157157
cp -r extension-temp/* "$TARGET_DIR/"
158158
159-
# Verify copy
160-
if [ ! -f "$TARGET_DIR/manifest.json" ]; then
161-
echo "❌ Failed to copy manifest.json to $TARGET_DIR"
159+
# Verify required files were copied (including WASM pkg artifacts)
160+
REQUIRED_FILES=(
161+
"$TARGET_DIR/manifest.json"
162+
"$TARGET_DIR/content.js"
163+
"$TARGET_DIR/background.js"
164+
"$TARGET_DIR/injected_api.js"
165+
"$TARGET_DIR/pkg/sentience_core.js"
166+
"$TARGET_DIR/pkg/sentience_core_bg.wasm"
167+
)
168+
MISSING_FILES=()
169+
for file in "${REQUIRED_FILES[@]}"; do
170+
if [ ! -f "$file" ]; then
171+
MISSING_FILES+=("$file")
172+
fi
173+
done
174+
if [ ${#MISSING_FILES[@]} -ne 0 ]; then
175+
echo "❌ Extension sync incomplete. Missing required files:"
176+
printf ' - %s\n' "${MISSING_FILES[@]}"
162177
exit 1
163178
fi
164179

predicate/extension/pkg/.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
*
2+
!.gitignore
3+
!sentience_core.js
4+
!sentience_core_bg.wasm

0 commit comments

Comments
 (0)