Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
113 changes: 113 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ on:
description: 'Version to release (e.g., 0.1.0)'
required: true
type: string
extension_release_tag:
description: 'Optional extension release tag (e.g., v1.2.3). Defaults to latest if omitted.'
required: false
type: string

jobs:
build-and-publish:
Expand Down Expand Up @@ -50,6 +54,115 @@ jobs:
VERSION="${{ steps.version.outputs.version }}"
sed -i "s/^__version__ = \".*\"/__version__ = \"$VERSION\"/" predicate/__init__.py

- name: Sync extension files if missing
run: |
set -euo pipefail

REQUIRED_FILES=(
"predicate/extension/manifest.json"
"predicate/extension/content.js"
"predicate/extension/background.js"
"predicate/extension/injected_api.js"
"predicate/extension/pkg/sentience_core.js"
"predicate/extension/pkg/sentience_core_bg.wasm"
)

has_all_required_files() {
for file in "${REQUIRED_FILES[@]}"; do
if [ ! -f "$file" ]; then
return 1
fi
done
return 0
}

if has_all_required_files; then
echo "✅ Extension files already present in repository"
exit 0
fi

echo "⚠️ Extension files missing locally. Attempting auto-sync from extension release..."

REPO="${{ secrets.SENTIENCE_CHROME_REPO }}"
TOKEN="${{ secrets.SENTIENCE_CHROME_TOKEN }}"

if [ -z "$REPO" ] || [ -z "$TOKEN" ]; then
echo "❌ Cannot auto-sync extension files: SENTIENCE_CHROME_REPO or SENTIENCE_CHROME_TOKEN is not configured."
echo "Please run sync-extension workflow (or sync manually) before release."
exit 1
fi

TAG_INPUT="${{ github.event.inputs.extension_release_tag }}"
if [ -n "$TAG_INPUT" ]; then
TAG="$TAG_INPUT"
echo "Using extension release tag from input: $TAG"
else
echo "No extension_release_tag provided. Resolving latest release tag from $REPO..."
HTTP_CODE=$(curl -s -o latest_release.json -w "%{http_code}" \
-H "Authorization: token $TOKEN" \
"https://api.github.com/repos/$REPO/releases/latest")

if [ "$HTTP_CODE" != "200" ]; then
echo "❌ Failed to fetch latest extension release (HTTP $HTTP_CODE)"
cat latest_release.json
exit 1
fi

TAG=$(jq -r '.tag_name // empty' latest_release.json)
if [ -z "$TAG" ]; then
echo "❌ Could not determine latest extension release tag"
exit 1
fi
echo "Resolved latest extension tag: $TAG"
fi

mkdir -p extension-temp
cd extension-temp

HTTP_CODE=$(curl -s -w "%{http_code}" -o release.json \
-H "Authorization: token $TOKEN" \
"https://api.github.com/repos/$REPO/releases/tags/$TAG")

if [ "$HTTP_CODE" != "200" ]; then
echo "❌ Failed to fetch extension release info for tag $TAG (HTTP $HTTP_CODE)"
cat release.json
exit 1
fi

ASSET_URL=$(jq -r '.assets[]? | select(.name == "extension-files.tar.gz") | .url' release.json)
if [ -z "$ASSET_URL" ] || [ "$ASSET_URL" = "null" ]; then
echo "❌ extension-files.tar.gz not found on extension release $TAG"
echo "Available assets:"
jq -r '.assets[]?.name' release.json
exit 1
fi

HTTP_CODE=$(curl -L -s -w "%{http_code}" -o extension.tar.gz \
-H "Authorization: token $TOKEN" \
-H "Accept: application/octet-stream" \
"$ASSET_URL")

if [ "$HTTP_CODE" != "200" ] && [ "$HTTP_CODE" != "302" ]; then
echo "❌ Failed to download extension tarball (HTTP $HTTP_CODE)"
exit 1
fi

tar -xzf extension.tar.gz
cd ..

TARGET_DIR="predicate/extension"
rm -rf "$TARGET_DIR"
mkdir -p "$TARGET_DIR"
cp -r extension-temp/* "$TARGET_DIR/"
rm -rf extension-temp latest_release.json

if has_all_required_files; then
echo "✅ Extension files synced successfully from $REPO@$TAG"
else
echo "❌ Extension sync completed but required files are still missing"
exit 1
fi

- name: Verify extension files are present
run: |
echo "🔍 Verifying extension files are included..."
Expand Down
21 changes: 18 additions & 3 deletions .github/workflows/sync-extension.yml
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,24 @@ jobs:
# Copy files from temp directory
cp -r extension-temp/* "$TARGET_DIR/"

# Verify copy
if [ ! -f "$TARGET_DIR/manifest.json" ]; then
echo "❌ Failed to copy manifest.json to $TARGET_DIR"
# Verify required files were copied (including WASM pkg artifacts)
REQUIRED_FILES=(
"$TARGET_DIR/manifest.json"
"$TARGET_DIR/content.js"
"$TARGET_DIR/background.js"
"$TARGET_DIR/injected_api.js"
"$TARGET_DIR/pkg/sentience_core.js"
"$TARGET_DIR/pkg/sentience_core_bg.wasm"
)
MISSING_FILES=()
for file in "${REQUIRED_FILES[@]}"; do
if [ ! -f "$file" ]; then
MISSING_FILES+=("$file")
fi
done
if [ ${#MISSING_FILES[@]} -ne 0 ]; then
echo "❌ Extension sync incomplete. Missing required files:"
printf ' - %s\n' "${MISSING_FILES[@]}"
exit 1
fi

Expand Down
4 changes: 4 additions & 0 deletions predicate/extension/pkg/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
*
!.gitignore
!sentience_core.js
!sentience_core_bg.wasm
Loading
Loading