diff --git a/.github/workflows/build-and-deploy.yml b/.github/workflows/build-and-deploy.yml deleted file mode 100644 index 646900e..0000000 --- a/.github/workflows/build-and-deploy.yml +++ /dev/null @@ -1,48 +0,0 @@ -name: Build and Deploy - -on: - push: - branches: - - main - - dev - -permissions: - contents: write - -jobs: - build-and-deploy: - runs-on: ubuntu-latest - - steps: - - name: Checkout repository - uses: actions/checkout@v3 - - - name: Set up Node.js - uses: actions/setup-node@v3 - with: - node-version: 18.14.2 - - - name: Install Yarn - run: npm install -g yarn - - - name: Install dependencies - run: yarn install - - - name: Set up Clojure CLI tools - uses: DeLaGuardo/setup-clojure@12.5 - with: - cli: 1.11.1.1139 - - - name: Build the optimized release using shadow-cljs - run: npx shadow-cljs release app - - - name: Determine Deployment Branch - id: get-branch - run: echo "branch=$(if [ '${{ github.ref_name }}' == 'main' ]; then echo 'gh-pages'; else echo 'gh-pages-dev'; fi)" >> $GITHUB_ENV - - - name: Deploy to GitHub Pages - uses: peaceiris/actions-gh-pages@v3 - with: - github_token: ${{ secrets.GITHUB_TOKEN }} - publish_dir: ./public/app - publish_branch: ${{ env.branch }} diff --git a/build.sh b/build.sh new file mode 100644 index 0000000..c21dc15 --- /dev/null +++ b/build.sh @@ -0,0 +1,98 @@ +#!/bin/bash +set -e + +# Function to filter logs +filter_logs() { + grep -v "^Downloading: " | grep -v "^Downloaded: " +} + +# Start logging with filter +exec > >(filter_logs | tee build-log.txt) 2>&1 + +echo "=== Starting build script ===" + +# Install dependencies +echo "Installing yarn globally..." +npm i -g yarn + +curl -L -O https://github.com/clojure/brew-install/releases/latest/download/linux-install.sh +chmod +x linux-install.sh + +./linux-install.sh + +export PATH=/tmp/clojure/bin:$PATH + +echo "Installing project dependencies with yarn..." +yarn install + +# Build the app +npx shadow-cljs release app + +# Copy README.md into public/app directory +cp README.md public/app + +# Install Vercel Blob SDK +npm install @vercel/blob + + +# Save the Node.js script to a file +cat > upload-files.js << 'EOF' +const { readFileSync } = require('fs'); +const { join } = require('path'); +const { put } = require('@vercel/blob'); + +// Define the directory where our built files live +const distPath = join(__dirname, 'public', 'app'); + +// Files to be uploaded +const files = ['README.md', 'extension.js']; + +// Retrieve environment variables or defaults +const resolvedBranch = process.env.VERCEL_GIT_COMMIT_REF || process.env.BRANCH || 'main'; +const resolvedWorkspace = process.env.VERCEL_GIT_REPO_SLUG || process.env.WORKSPACE || 'myworkspace'; +const token = process.env.BLOB_READ_WRITE_TOKEN || 'your_blob_token_here'; + +(async () => { + for (const file of files) { + const filePath = join(distPath, file); + console.log(`DEBUG: Attempting to read file: ${filePath}`); + let content; + try { + content = readFileSync(filePath); + } catch (error) { + console.error(`ERROR: Failed to read file ${file}:`, error); + process.exit(1); + } + + const pathname = resolvedBranch === 'main' + ? `releases/${resolvedWorkspace}/${file}` + : `releases/${resolvedWorkspace}/${resolvedBranch}/${file}`; + + try { + const blob = await put(pathname, content, { + access: 'public', + addRandomSuffix: false, + token, + }); + } catch (error) { + console.error(`ERROR: Upload failed for ${file}:`, error); + process.exit(1); + } + } + console.log("=== Deploy completed successfully! ==="); + const url = resolvedBranch === 'main' + ? `https://discoursegraphs.com/releases/${resolvedWorkspace}` + : `https://discoursegraphs.com/releases/${resolvedWorkspace}/${resolvedBranch}`; + console.log(`✅ DEBUG: Endpoint URL: ${url}`); +})(); +EOF + +# Run the upload script +node upload-files.js + +echo "=== Build script finished ===" + +# Optional: Display important build artifacts +echo "=== Build Summary ===" +echo "Files in public/app directory:" +ls -la public/app \ No newline at end of file diff --git a/shadow-cljs.edn b/shadow-cljs.edn index 87c0016..211972e 100644 --- a/shadow-cljs.edn +++ b/shadow-cljs.edn @@ -5,8 +5,8 @@ :builds {:app {:target :browser - :output-dir "public/app/js" - :asset-path "/app/js" + :output-dir "public/app" + :asset-path "/" :http {:port 9630} :devtools {:http-root "public" :http-port 8080 @@ -15,4 +15,4 @@ :compiler-options {:output-feature-set :es-next-in :source-map true :source-map-include-sources-content true} - :modules {:main {:init-fn ui.core/init}}}}} \ No newline at end of file + :modules {:extension {:init-fn ui.core/init}}}}} \ No newline at end of file