Skip to content
Closed
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
291 changes: 291 additions & 0 deletions .github/workflows/sync-submodules.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,291 @@
name: Sync Submodule Changes

on:
pull_request:
types: [opened, synchronize, reopened]
workflow_dispatch:
inputs:
pr_number:
description: 'PR number to sync submodules for'
required: true
type: number

permissions:
contents: write
pull-requests: write

jobs:
sync-submodules:
runs-on: ubuntu-latest
steps:
- name: Checkout PR branch
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.ref || github.ref }}
fetch-depth: 0
submodules: recursive
token: ${{ secrets.GITHUB_TOKEN }}

- name: Configure Git
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"

- name: Check and create PR for ararat-ui-web submodule changes
id: push-ararat-ui-web
run: |
cd deps/ararat-ui-web

# Get current branch
CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
echo "Current branch in submodule: $CURRENT_BRANCH"

# Check if there are unpushed commits
if ! UNPUSHED=$(git log origin/$CURRENT_BRANCH..$CURRENT_BRANCH --oneline 2>&1); then
echo "Warning: Could not check for unpushed commits: $UNPUSHED"
UNPUSHED=""
fi

if [ -n "$UNPUSHED" ]; then
echo "Found unpushed commits in ararat-ui-web submodule:"
echo "$UNPUSHED"

# Create a new branch for the PR
PR_BRANCH="sync-from-main-pr-${{ github.event.pull_request.number || github.run_number }}"
echo "Creating branch: $PR_BRANCH"

git checkout -b $PR_BRANCH

# Try to push with the GitHub token
git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/hyecompany/ararat-ui-web.git

if git push origin $PR_BRANCH; then
echo "✅ Successfully pushed ararat-ui-web submodule changes to branch $PR_BRANCH"
echo "pushed=true" >> $GITHUB_OUTPUT
echo "branch=$PR_BRANCH" >> $GITHUB_OUTPUT
echo "base_branch=$CURRENT_BRANCH" >> $GITHUB_OUTPUT
echo "has_changes=true" >> $GITHUB_OUTPUT
else
echo "❌ Failed to push ararat-ui-web submodule changes"
echo "This may require manual intervention or additional permissions"
echo "pushed=false" >> $GITHUB_OUTPUT
echo "has_changes=false" >> $GITHUB_OUTPUT
echo "error=true" >> $GITHUB_OUTPUT
# Don't exit 1 - let the workflow continue to report the error
fi
else
echo "No unpushed commits in ararat-ui-web submodule"
echo "pushed=false" >> $GITHUB_OUTPUT
echo "has_changes=false" >> $GITHUB_OUTPUT
fi

- name: Check and create PR for ui-web submodule changes
id: push-ui-web
run: |
cd deps/ui-web

# Get current branch
CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
echo "Current branch in submodule: $CURRENT_BRANCH"

# Check if there are unpushed commits
if ! UNPUSHED=$(git log origin/$CURRENT_BRANCH..$CURRENT_BRANCH --oneline 2>&1); then
echo "Warning: Could not check for unpushed commits: $UNPUSHED"
UNPUSHED=""
fi

if [ -n "$UNPUSHED" ]; then
echo "Found unpushed commits in ui-web submodule:"
echo "$UNPUSHED"

# Create a new branch for the PR
PR_BRANCH="sync-from-main-pr-${{ github.event.pull_request.number || github.run_number }}"
echo "Creating branch: $PR_BRANCH"

git checkout -b $PR_BRANCH

# Try to push with the GitHub token
git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/hyecompany/ui-web.git

if git push origin $PR_BRANCH; then
echo "✅ Successfully pushed ui-web submodule changes to branch $PR_BRANCH"
echo "pushed=true" >> $GITHUB_OUTPUT
echo "branch=$PR_BRANCH" >> $GITHUB_OUTPUT
echo "base_branch=$CURRENT_BRANCH" >> $GITHUB_OUTPUT
echo "has_changes=true" >> $GITHUB_OUTPUT
else
echo "❌ Failed to push ui-web submodule changes"
echo "This may require manual intervention or additional permissions"
echo "pushed=false" >> $GITHUB_OUTPUT
echo "has_changes=false" >> $GITHUB_OUTPUT
echo "error=true" >> $GITHUB_OUTPUT
# Don't exit 1 - let the workflow continue to report the error
fi
else
echo "No unpushed commits in ui-web submodule"
echo "pushed=false" >> $GITHUB_OUTPUT
echo "has_changes=false" >> $GITHUB_OUTPUT
fi

- name: Create PR for ararat-ui-web submodule
if: steps.push-ararat-ui-web.outputs.has_changes == 'true'
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const branch = '${{ steps.push-ararat-ui-web.outputs.branch }}';
const baseBranch = '${{ steps.push-ararat-ui-web.outputs.base_branch }}';
const mainPrNumber = '${{ github.event.pull_request.number }}';

try {
const { data: pr } = await github.rest.pulls.create({
owner: 'hyecompany',
repo: 'ararat-ui-web',
title: `Sync changes from ararat-web PR #${mainPrNumber}`,
head: branch,
base: baseBranch,
body: `This PR contains changes synced from the main ararat-web repository.

**Source PR**: hyecompany/ararat-web#${mainPrNumber}

## Changes
These changes were made in the main repository's PR and need to be merged into the ararat-ui-web submodule.

This PR was automatically created by the sync-submodules workflow.`
});

console.log(\`Created PR #\${pr.number} in ararat-ui-web\`);
core.setOutput('pr_number', pr.number);
core.setOutput('pr_url', pr.html_url);
} catch (error) {
console.error('Failed to create PR:', error.message);
// Don't fail the workflow if PR creation fails (might already exist)
}

- name: Create PR for ui-web submodule
if: steps.push-ui-web.outputs.has_changes == 'true'
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const branch = '${{ steps.push-ui-web.outputs.branch }}';
const baseBranch = '${{ steps.push-ui-web.outputs.base_branch }}';
const mainPrNumber = '${{ github.event.pull_request.number }}';

try {
const { data: pr } = await github.rest.pulls.create({
owner: 'hyecompany',
repo: 'ui-web',
title: `Sync changes from ararat-web PR #${mainPrNumber}`,
head: branch,
base: baseBranch,
body: `This PR contains changes synced from the main ararat-web repository.

**Source PR**: hyecompany/ararat-web#${mainPrNumber}

## Changes
These changes were made in the main repository's PR and need to be merged into the ui-web submodule.

This PR was automatically created by the sync-submodules workflow.`
});

console.log(\`Created PR #\${pr.number} in ui-web\`);
core.setOutput('pr_number', pr.number);
core.setOutput('pr_url', pr.html_url);
} catch (error) {
console.error('Failed to create PR:', error.message);
// Don't fail the workflow if PR creation fails (might already exist)
}

- name: Update submodule references
if: steps.push-ararat-ui-web.outputs.pushed == 'true' || steps.push-ui-web.outputs.pushed == 'true'
run: |
# Update the submodule references in the main repo to point to the new PR branches
cd deps/ararat-ui-web
if [ "${{ steps.push-ararat-ui-web.outputs.pushed }}" == "true" ]; then
git checkout ${{ steps.push-ararat-ui-web.outputs.branch }}
fi
cd ../..

cd deps/ui-web
if [ "${{ steps.push-ui-web.outputs.pushed }}" == "true" ]; then
git checkout ${{ steps.push-ui-web.outputs.branch }}
fi
cd ../..

# Add the submodule changes
git add deps/ararat-ui-web deps/ui-web

if git diff --cached --quiet; then
echo "No submodule reference changes to commit"
else
git commit -m "Update submodule references to PR branches

This commit updates the submodule pointers to the PR branches:
- ararat-ui-web: ${{ steps.push-ararat-ui-web.outputs.branch }}
- ui-web: ${{ steps.push-ui-web.outputs.branch }}"

git push origin ${{ github.event.pull_request.head.ref || github.ref }}
fi

- name: Comment on PR
if: always() && github.event_name == 'pull_request'
id: comment
uses: actions/github-script@v7
with:
script: |
const araratHasChanges = '${{ steps.push-ararat-ui-web.outputs.has_changes }}' === 'true';
const araratError = '${{ steps.push-ararat-ui-web.outputs.error }}' === 'true';
const uiHasChanges = '${{ steps.push-ui-web.outputs.has_changes }}' === 'true';
const uiError = '${{ steps.push-ui-web.outputs.error }}' === 'true';

let message = '## 🔄 Submodule Sync Status\n\n';

if (araratHasChanges) {
if (araratError) {
message += '### ararat-ui-web\n';
message += '⚠️ Failed to push submodule changes\n';
message += 'The GitHub Actions workflow may not have sufficient permissions to push to the submodule repository.\n';
message += 'Please push the submodule changes manually or configure a PAT with appropriate permissions.\n\n';
} else {
message += '### ararat-ui-web\n';
message += '✅ Successfully created PR for submodule changes\n';
message += `- **Branch**: \`${{ steps.push-ararat-ui-web.outputs.branch }}\`\n`;
message += `- **Base**: \`${{ steps.push-ararat-ui-web.outputs.base_branch }}\`\n`;
message += `- **PR**: [View PR](https://github.com/hyecompany/ararat-ui-web/pulls)\n\n`;
}
}

if (uiHasChanges) {
if (uiError) {
message += '### ui-web\n';
message += '⚠️ Failed to push submodule changes\n';
message += 'The GitHub Actions workflow may not have sufficient permissions to push to the submodule repository.\n';
message += 'Please push the submodule changes manually or configure a PAT with appropriate permissions.\n\n';
} else {
message += '### ui-web\n';
message += '✅ Successfully created PR for submodule changes\n';
message += `- **Branch**: \`${{ steps.push-ui-web.outputs.branch }}\`\n`;
message += `- **Base**: \`${{ steps.push-ui-web.outputs.base_branch }}\`\n`;
message += `- **PR**: [View PR](https://github.com/hyecompany/ui-web/pulls)\n\n`;
}
}

if (!araratHasChanges && !uiHasChanges) {
message += 'ℹ️ No submodule changes needed to be synced.\n\n';
}

if (araratHasChanges || uiHasChanges) {
message += '---\n\n';
message += '**Next Steps:**\n';
message += '1. Review and merge the submodule PR(s) above\n';
message += '2. Once merged, update this PR to point to the merged commits\n';
message += '3. This PR can then be merged\n';
}

await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: message
});
39 changes: 39 additions & 0 deletions app/(main)/_lib/instance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,43 @@ export default class Instance implements IInstance {
}
return await response.text();
}

async openExecSocket(
command: string[],
options?: { width?: number; height?: number },
) {
const response = await fetch(
`/1.0/instances/${encodeURIComponent(this.name)}/exec`,
{
method: 'POST',
body: JSON.stringify({
command: command,
interactive: true,
'wait-for-websocket': true,
width: options?.width,
height: options?.height,
}),
},
);
if (!response.ok) {
let errorMessage = `Failed to open exec socket: ${response.status} ${response.statusText}`;
try {
const errorData = await response.json();
errorMessage += ` - ${JSON.stringify(errorData)}`;
} catch (e) {
// Ignore JSON parse errors, use default message
}
throw new Error(errorMessage);
}
const data = await response.json();
const protocol = window.location.protocol === 'https:' ? 'wss' : 'ws';
return {
data: new WebSocket(
`${protocol}://${window.location.host}${data.operation}/websocket?secret=${data.metadata.metadata.fds['0']}`,
),
control: new WebSocket(
`${protocol}://${window.location.host}${data.operation}/websocket?secret=${data.metadata.metadata.fds['control']}`,
),
};
}
}
Loading
Loading