diff --git a/.github/workflows/preview-deploy.yml b/.github/workflows/preview-deploy.yml new file mode 100644 index 0000000000..5c7a33ac82 --- /dev/null +++ b/.github/workflows/preview-deploy.yml @@ -0,0 +1,724 @@ +name: Deploy Branch Preview + +on: + push: + branches: + - '**' # Trigger on all branches + +jobs: + deploy-preview: + runs-on: ubuntu-latest + environment: + name: preview + url: ${{ steps.deploy.outputs.deploy_url }} + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: '20' + + - name: Create preview directory + run: mkdir -p preview + + - name: Generate WebContainer snapshot + run: | + # Install snapshot tool in a temp directory to avoid creating + # node_modules (with symlinks) in the project root + SNAPSHOT_TOOL_DIR=$(mktemp -d) + cd "$SNAPSHOT_TOOL_DIR" && npm init -y --silent && npm install --silent @webcontainer/snapshot + cd "$GITHUB_WORKSPACE" + + node -e " + const { snapshot } = require('$SNAPSHOT_TOOL_DIR/node_modules/@webcontainer/snapshot'); + const fs = require('fs'); + snapshot('.').then(buf => { + fs.writeFileSync('preview/snapshot', buf); + console.log('✓ Snapshot generated (' + (buf.length / 1024 / 1024).toFixed(2) + ' MB)'); + }); + " + + - name: Generate preview HTML + run: | + cat > preview/index.html << 'EOF' + + +
+ + +